Skip to content

Commit

Permalink
Fix kwarg setup: _checkargs must modify kwargs inplace to fulfil assu…
Browse files Browse the repository at this point in the history
…mptions in micromagneticmodel
  • Loading branch information
lang-m committed Jun 8, 2024
1 parent 5b538d9 commit 555a49a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
10 changes: 4 additions & 6 deletions oommfc/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 6 additions & 8 deletions oommfc/drivers/hysteresisdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -101,8 +101,6 @@ def _checkargs(self, kwargs):
)
return ValueError(msg)

return kwargs

@staticmethod
def _checkvalues(Hmin, Hmax, n):
for item in [Hmin, Hmax]:
Expand Down
2 changes: 1 addition & 1 deletion oommfc/drivers/mindriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
1 change: 0 additions & 1 deletion oommfc/drivers/timedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 555a49a

Please sign in to comment.