From bfd39fe2ce256c9de7e0891ab9dfe2548d84ac5c Mon Sep 17 00:00:00 2001 From: Pascal Muster Date: Wed, 19 Jul 2023 16:26:42 +0200 Subject: [PATCH 01/14] Added new option "Hsteps" to HysteresisDriver Allows configuration of tunable (non-symmetric) hysteresis loops. --- oommfc/drivers/hysteresisdriver.py | 29 +++++++++++++++++++++++++---- oommfc/scripts/driver.py | 10 +++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index 089c90b..a206bef 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -59,13 +59,34 @@ class HysteresisDriver(Driver): ] def _checkargs(self, **kwargs): - Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"] - for i in [Hmin, Hmax]: + # check the default arguments for a symmetric hysteresis loop + if ( + any(item in kwargs for item in ["Hmin", "Hmax", "n"]) + and "Hsteps" in kwargs + ): + msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." + raise ValueError(msg) + + if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): + self._checkvalues(kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]) + elif "Hsteps" in kwargs: + for Hstart, Hend, n in kwargs["Hsteps"]: + self._checkvalues(Hstart, Hend, n) + else: + msg = ( + "Some of the required arguments are missing. " + "(Hmin, Hmax, n) or Hsteps must be defined." + ) + raise ValueError(msg) + + @staticmethod + def _checkvalues(Hstart, Hend, n): + for i in [Hstart, Hend]: if not isinstance(i, (list, tuple, np.ndarray)): - msg = "Hmin and Hmax must have array_like values." + msg = "Hstart (Hmin) and Hend (Hmax) must have array_like values." raise ValueError(msg) if len(i) != 3: - msg = "Hmin and Hmax must have length 3." + msg = "Hstart (Hmin) and Hend (Hmax) must have length 3." raise ValueError(msg) if not isinstance(n, int): msg = f"Cannot drive with {type(n)=}." diff --git a/oommfc/scripts/driver.py b/oommfc/scripts/driver.py index 5e751d4..99bdcb4 100644 --- a/oommfc/scripts/driver.py +++ b/oommfc/scripts/driver.py @@ -29,12 +29,16 @@ def driver_script( mif += oc.scripts.evolver_script(driver.evolver) # Oxs_UZeeman - Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"] mif += "# OxS_UZeeman\n" mif += "Specify Oxs_UZeeman:hysteresis {\n" mif += " Hrange {\n" - mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmin, *Hmax, n - 1) - mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmax, *Hmin, n - 1) + if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): + Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"] + mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmin, *Hmax, n - 1) + mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmax, *Hmin, n - 1) + elif "Hsteps" in kwargs: + for Hstart, Hend, n in kwargs["Hsteps"]: + mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hstart, *Hend, n - 1) mif += " }\n" mif += "}\n\n" From 142d1c163aaa565b0e33ce644e8018284f6ad448 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:34:29 +0000 Subject: [PATCH 02/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- oommfc/drivers/hysteresisdriver.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index a206bef..f43bee3 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -60,10 +60,7 @@ class HysteresisDriver(Driver): def _checkargs(self, **kwargs): # check the default arguments for a symmetric hysteresis loop - if ( - any(item in kwargs for item in ["Hmin", "Hmax", "n"]) - and "Hsteps" in kwargs - ): + if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs: msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." raise ValueError(msg) From b62fa9fc2acab598b9d218179a61517edc896ea0 Mon Sep 17 00:00:00 2001 From: Pascal Muster Date: Tue, 24 Oct 2023 12:35:59 +0200 Subject: [PATCH 03/14] Including suggested changes --- oommfc/drivers/hysteresisdriver.py | 30 +++++++++++++++++++++++++++--- oommfc/scripts/driver.py | 9 ++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index f43bee3..cbd02cf 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -35,6 +35,18 @@ class HysteresisDriver(Driver): >>> hd._allowed_attributes [...] + 4. How to define multiple steps with this driver. + >>> import oommfc as oc + ... + >>> system = oc.System(name="my_system") + ... + >>> sd = oc.HysteresisDriver() + >>> sd.drive(system, Hsteps=[ + >>> [(0, 0, 0), (0, 0, 1), 10], + >>> [(0, 0, 1), (0, 0, -1), 10], + >>> [(0, 0, -1), (0, 0, 0), 10], + >>> ]) + """ _allowed_attributes = [ @@ -58,23 +70,35 @@ class HysteresisDriver(Driver): "report_wall_time", ] - def _checkargs(self, **kwargs): + def _checkargs(self, kwargs): # check the default arguments for a symmetric hysteresis loop if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs: msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." raise ValueError(msg) if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): + # case of a symmetric hysteresis simulation self._checkvalues(kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]) + kwargs["Hsteps"] = [ + [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], + [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]] + ] elif "Hsteps" in kwargs: + # case of multiple hysteresis sweep steps + if not isinstance(kwargs["Hsteps"], (list, tuple)): + raise TypeError("Hsteps has to be iterable.") + if any(len(element) != 3 for element in kwargs["Hsteps"]): + raise ValueError( + "Hsteps has to include three elements " + "(Hstart, Hend, n) in each step." + ) for Hstart, Hend, n in kwargs["Hsteps"]: self._checkvalues(Hstart, Hend, n) else: - msg = ( + raise ValueError( "Some of the required arguments are missing. " "(Hmin, Hmax, n) or Hsteps must be defined." ) - raise ValueError(msg) @staticmethod def _checkvalues(Hstart, Hend, n): diff --git a/oommfc/scripts/driver.py b/oommfc/scripts/driver.py index 99bdcb4..53a7b98 100644 --- a/oommfc/scripts/driver.py +++ b/oommfc/scripts/driver.py @@ -32,13 +32,8 @@ def driver_script( mif += "# OxS_UZeeman\n" mif += "Specify Oxs_UZeeman:hysteresis {\n" mif += " Hrange {\n" - if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): - Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"] - mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmin, *Hmax, n - 1) - mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmax, *Hmin, n - 1) - elif "Hsteps" in kwargs: - for Hstart, Hend, n in kwargs["Hsteps"]: - mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hstart, *Hend, n - 1) + for Hstart, Hend, n in kwargs["Hsteps"]: + mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hstart, *Hend, n - 1) mif += " }\n" mif += "}\n\n" From 7a2b6060ca3f62c12e6bff12c0a8631bff811c1c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 10:36:30 +0000 Subject: [PATCH 04/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- oommfc/drivers/hysteresisdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index cbd02cf..9920e7a 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -81,7 +81,7 @@ def _checkargs(self, kwargs): self._checkvalues(kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]) kwargs["Hsteps"] = [ [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], - [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]] + [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]], ] elif "Hsteps" in kwargs: # case of multiple hysteresis sweep steps From 236c41d4fb1be7e629cf05d1a9a2b93ace02fbd9 Mon Sep 17 00:00:00 2001 From: Pascal Muster Date: Wed, 25 Oct 2023 18:01:56 +0200 Subject: [PATCH 05/14] Exchange "iterable" by "list or tuple" Iterable is too generic. Co-authored-by: Martin Lang <67915889+lang-m@users.noreply.github.com> --- oommfc/drivers/hysteresisdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index 9920e7a..cac69f9 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -86,7 +86,7 @@ def _checkargs(self, kwargs): elif "Hsteps" in kwargs: # case of multiple hysteresis sweep steps if not isinstance(kwargs["Hsteps"], (list, tuple)): - raise TypeError("Hsteps has to be iterable.") + raise TypeError("Hsteps has to be a list or tuple.") if any(len(element) != 3 for element in kwargs["Hsteps"]): raise ValueError( "Hsteps has to include three elements " From be573b326ff1c4afdbf48832fa87791421f58784 Mon Sep 17 00:00:00 2001 From: Pascal Muster Date: Wed, 25 Oct 2023 18:33:12 +0200 Subject: [PATCH 06/14] Combine checks into one if-elif-else block --- oommfc/drivers/hysteresisdriver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index cac69f9..ee905c3 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -71,12 +71,11 @@ class HysteresisDriver(Driver): ] def _checkargs(self, kwargs): - # check the default arguments for a symmetric hysteresis loop if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs: + # unwanted case of beeing (Hmin, Hmax, n) and Hsteps both defined msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." raise ValueError(msg) - - if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): + elif all(item in kwargs for item in ["Hmin", "Hmax", "n"]): # case of a symmetric hysteresis simulation self._checkvalues(kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]) kwargs["Hsteps"] = [ From c089c7847c16bcd6df8d6f5a097ac40f1631c69e Mon Sep 17 00:00:00 2001 From: Pascal Muster Date: Wed, 25 Oct 2023 18:44:17 +0200 Subject: [PATCH 07/14] Reverting kwargs to **kwargs in _checkargs --- oommfc/drivers/hysteresisdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index ee905c3..5b2e508 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -70,7 +70,7 @@ class HysteresisDriver(Driver): "report_wall_time", ] - def _checkargs(self, kwargs): + def _checkargs(self, **kwargs): if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs: # unwanted case of beeing (Hmin, Hmax, n) and Hsteps both defined msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." From e8fd61c5c46d653c26b9cee55e882c9d079af350 Mon Sep 17 00:00:00 2001 From: Pascal Muster Date: Thu, 30 May 2024 17:26:09 +0200 Subject: [PATCH 08/14] Use kwargs instead of **kwargs in _checkargs --- oommfc/drivers/driver.py | 1 + oommfc/drivers/hysteresisdriver.py | 41 +++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/oommfc/drivers/driver.py b/oommfc/drivers/driver.py index a77f534..47bdb9d 100644 --- a/oommfc/drivers/driver.py +++ b/oommfc/drivers/driver.py @@ -66,6 +66,7 @@ def drive_kwargs_setup(self, drive_kwargs): drive_kwargs.setdefault("output_step", False) drive_kwargs.setdefault("n_threads", None) drive_kwargs.setdefault("compute", None) + return drive_kwargs def schedule_kwargs_setup(self, schedule_kwargs): """Additional keyword arguments allowed for schedule. diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index 5500486..8f683c9 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -71,13 +71,41 @@ class HysteresisDriver(Driver): ] def _checkargs(self, kwargs): - Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"] - for i in [Hmin, Hmax]: - if not isinstance(i, (list, tuple, np.ndarray)): - msg = "Hstart (Hmin) and Hend (Hmax) must have array_like values." + + if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs: + # both Hsteps and (Hmin, Hmax, n) are defined, which is not allowed + msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." + raise ValueError(msg) + + if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): + # case of a symmetric hysteresis simulation + # construct symmetric Hsteps from (Hmin, Hmax, n) + kwargs = {"Hsteps": [ + [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], + [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]] + ]} + + if "Hsteps" in kwargs: + # case of a stepped hysteresis simulation + for step in kwargs["Hsteps"]: + if len(step) != 3: + msg = "Each list item in Hsteps must have 3 entries: Hstart, Hend, n." + raise ValueError(msg) + self._checkvalues(step[0], step[1], step[2]) + else: + msg = "Cannot drive without a full definition of (Hmin, Hmax, n) xor Hsteps." + return ValueError(msg) + + return kwargs + + @staticmethod + def _checkvalues(Hmin, Hmax, n): + for item in [Hmin, Hmax]: + if not isinstance(item, (list, tuple, np.ndarray)): + msg = "Hmin and Hmax must have array_like values." raise ValueError(msg) - if len(i) != 3: - msg = "Hstart (Hmin) and Hend (Hmax) must have length 3." + if len(item) != 3: + msg = "Hmin and Hmax must have length 3." raise ValueError(msg) if not isinstance(n, int): msg = f"Cannot drive with {type(n)=}." @@ -85,7 +113,6 @@ def _checkargs(self, kwargs): if n - 1 <= 0: # OOMMF counts steps, not points (n -> n-1) msg = f"Cannot drive with {n=}." raise ValueError(msg) - return kwargs def _check_system(self, system): """Checks the system has energy in it""" From 5b538d9a16dc0e87f452f2a0b1fbe716a5069325 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 15:27:38 +0000 Subject: [PATCH 09/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- oommfc/drivers/hysteresisdriver.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index 8f683c9..75143ce 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -71,33 +71,38 @@ class HysteresisDriver(Driver): ] def _checkargs(self, kwargs): - if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs: # both Hsteps and (Hmin, Hmax, n) are defined, which is not allowed msg = "Cannot define both (Hmin, Hmax, n) and Hsteps." raise ValueError(msg) - + if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): # case of a symmetric hysteresis simulation # construct symmetric Hsteps from (Hmin, Hmax, n) - kwargs = {"Hsteps": [ - [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], - [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]] - ]} - + kwargs = { + "Hsteps": [ + [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], + [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]], + ] + } + if "Hsteps" in kwargs: # case of a stepped hysteresis simulation for step in kwargs["Hsteps"]: if len(step) != 3: - msg = "Each list item in Hsteps must have 3 entries: Hstart, Hend, n." + msg = ( + "Each list item in Hsteps must have 3 entries: Hstart, Hend, n." + ) raise ValueError(msg) self._checkvalues(step[0], step[1], step[2]) else: - msg = "Cannot drive without a full definition of (Hmin, Hmax, n) xor Hsteps." + msg = ( + "Cannot drive without a full definition of (Hmin, Hmax, n) xor Hsteps." + ) return ValueError(msg) - + return kwargs - + @staticmethod def _checkvalues(Hmin, Hmax, n): for item in [Hmin, Hmax]: From 555a49a36b0a948f581fdfeef76cfec4f121320c Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Sat, 8 Jun 2024 17:11:00 +0200 Subject: [PATCH 10/14] Fix kwarg setup: _checkargs must modify kwargs inplace to fulfil assumptions in micromagneticmodel --- oommfc/drivers/driver.py | 10 ++++------ oommfc/drivers/hysteresisdriver.py | 14 ++++++-------- oommfc/drivers/mindriver.py | 2 +- oommfc/drivers/timedriver.py | 1 - 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/oommfc/drivers/driver.py b/oommfc/drivers/driver.py index 47bdb9d..3403c37 100644 --- a/oommfc/drivers/driver.py +++ b/oommfc/drivers/driver.py @@ -21,12 +21,11 @@ def __init__(self, **kwargs): self.autoselect_evolver = True @abc.abstractmethod - def _checkargs(self, kwargs) -> dict: + def _checkargs(self, kwargs): """Check drive keyword arguments. - This method can also update keyword arguments where required. It must return - a dict of all keyword arguments (initial or modified) that shall be used for the - simulation. + This method can also update keyword arguments where required. Changes must + happen in-place, i.e. `kwargs` must be modified directly. """ def drive_kwargs_setup(self, drive_kwargs): @@ -61,12 +60,11 @@ def drive_kwargs_setup(self, drive_kwargs): save additional data. Defaults to ``None``. """ - drive_kwargs = self._checkargs(drive_kwargs) + self._checkargs(drive_kwargs) drive_kwargs.setdefault("fixed_subregions", None) drive_kwargs.setdefault("output_step", False) drive_kwargs.setdefault("n_threads", None) drive_kwargs.setdefault("compute", None) - return drive_kwargs def schedule_kwargs_setup(self, schedule_kwargs): """Additional keyword arguments allowed for schedule. diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index 75143ce..f4630fe 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -79,12 +79,12 @@ def _checkargs(self, kwargs): if all(item in kwargs for item in ["Hmin", "Hmax", "n"]): # case of a symmetric hysteresis simulation # construct symmetric Hsteps from (Hmin, Hmax, n) - kwargs = { - "Hsteps": [ - [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], - [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]], - ] - } + kwargs["Hsteps"] = [ + [kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]], + [kwargs["Hmax"], kwargs["Hmin"], kwargs["n"]], + ] + for key in ["Hmin", "Hmax", "n"]: + kwargs.pop(key) if "Hsteps" in kwargs: # case of a stepped hysteresis simulation @@ -101,8 +101,6 @@ def _checkargs(self, kwargs): ) return ValueError(msg) - return kwargs - @staticmethod def _checkvalues(Hmin, Hmax, n): for item in [Hmin, Hmax]: diff --git a/oommfc/drivers/mindriver.py b/oommfc/drivers/mindriver.py index a04b9aa..f93fbb7 100644 --- a/oommfc/drivers/mindriver.py +++ b/oommfc/drivers/mindriver.py @@ -57,7 +57,7 @@ class MinDriver(Driver): ] def _checkargs(self, kwargs): - return kwargs # no kwargs should be checked + pass # no kwargs should be checked def _check_system(self, system): """Checks the system has energy in it""" diff --git a/oommfc/drivers/timedriver.py b/oommfc/drivers/timedriver.py index 3df8070..9f6fff3 100644 --- a/oommfc/drivers/timedriver.py +++ b/oommfc/drivers/timedriver.py @@ -66,7 +66,6 @@ def _checkargs(self, kwargs): if n <= 0: msg = f"Cannot drive with {n=}." raise ValueError(msg) - return kwargs def _check_system(self, system): """Checks the system has dynamics in it""" From 2acb02960266c71e38b7313cfc08936ae53129ca Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Sat, 8 Jun 2024 17:32:13 +0200 Subject: [PATCH 11/14] Fix schedule_kwargs_setup: _checkargs modifies kwargs in-place --- oommfc/drivers/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oommfc/drivers/driver.py b/oommfc/drivers/driver.py index 3403c37..a16284a 100644 --- a/oommfc/drivers/driver.py +++ b/oommfc/drivers/driver.py @@ -102,7 +102,7 @@ def schedule_kwargs_setup(self, schedule_kwargs): save additional data. Defaults to ``None``. """ - schedule_kwargs = self._checkargs(schedule_kwargs) + self._checkargs(schedule_kwargs) schedule_kwargs.setdefault("fixed_subregions", None) schedule_kwargs.setdefault("output_step", False) schedule_kwargs.setdefault("compute", None) From f2be061b0152d9f485fd04e1087835192bd1dda5 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Sat, 8 Jun 2024 17:32:32 +0200 Subject: [PATCH 12/14] Import fixtures required for hysteresis tests --- oommfc/tests/test_micromagnetictests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/oommfc/tests/test_micromagnetictests.py b/oommfc/tests/test_micromagnetictests.py index 41a9914..bd69ddb 100644 --- a/oommfc/tests/test_micromagnetictests.py +++ b/oommfc/tests/test_micromagnetictests.py @@ -1 +1,2 @@ from micromagnetictests.calculatortests import * # noqa: F401,F403 +from micromagnetictests.calculatortests.hysteresisdriver import Ms, system # noqa: F401 From 66fd90a844bc152df42f3b0ffed8f8b158a7a258 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Sat, 8 Jun 2024 21:37:17 +0200 Subject: [PATCH 13/14] Fixture imports fixed in micromagnetictests --- oommfc/tests/test_micromagnetictests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/oommfc/tests/test_micromagnetictests.py b/oommfc/tests/test_micromagnetictests.py index bd69ddb..41a9914 100644 --- a/oommfc/tests/test_micromagnetictests.py +++ b/oommfc/tests/test_micromagnetictests.py @@ -1,2 +1 @@ from micromagnetictests.calculatortests import * # noqa: F401,F403 -from micromagnetictests.calculatortests.hysteresisdriver import Ms, system # noqa: F401 From ef493d775365da6830a97934b39b1687c8ae0e66 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Sat, 8 Jun 2024 21:38:07 +0200 Subject: [PATCH 14/14] Fix doctest for stepped hysteresis driver --- oommfc/drivers/hysteresisdriver.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/oommfc/drivers/hysteresisdriver.py b/oommfc/drivers/hysteresisdriver.py index f4630fe..163b012 100644 --- a/oommfc/drivers/hysteresisdriver.py +++ b/oommfc/drivers/hysteresisdriver.py @@ -36,16 +36,17 @@ class HysteresisDriver(Driver): [...] 4. How to define multiple steps with this driver. + >>> import micromagneticmodel as mm >>> import oommfc as oc - ... - >>> system = oc.System(name="my_system") - ... + >>> system = mm.examples.macrospin() >>> sd = oc.HysteresisDriver() + >>> H = 1 / mm.consts.mu0 >>> sd.drive(system, Hsteps=[ - >>> [(0, 0, 0), (0, 0, 1), 10], - >>> [(0, 0, 1), (0, 0, -1), 10], - >>> [(0, 0, -1), (0, 0, 0), 10], - >>> ]) + ... [(0, 0, 0), (0, 0, H), 10], + ... [(0, 0, H), (0, 0, -H), 10], + ... [(0, 0, -H), (0, 0, 0), 10], + ... ]) + Running OOMMF ... """