Skip to content

Commit

Permalink
Merge pull request #154 from ubermag/drive-kwargs-handling
Browse files Browse the repository at this point in the history
More flexible keyword argument handling to also allow modifying kwargs
  • Loading branch information
lang-m authored May 9, 2024
2 parents 665d99f + 81389e1 commit 57830b3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-13, windows-latest]
python-version: ["3.8", "3.10"]
defaults:
run:
Expand All @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
auto-update-conda: true
Expand Down
13 changes: 9 additions & 4 deletions oommfc/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ def __init__(self, **kwargs):
self.autoselect_evolver = True

@abc.abstractmethod
def _checkargs(self, **kwargs):
"""Abstract method for checking arguments."""
def _checkargs(self, kwargs) -> dict:
"""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.
"""

def drive_kwargs_setup(self, drive_kwargs):
"""Additional keyword arguments allowed for drive.
Expand Down Expand Up @@ -56,7 +61,7 @@ def drive_kwargs_setup(self, drive_kwargs):
save additional data. Defaults to ``None``.
"""
self._checkargs(**drive_kwargs)
drive_kwargs = self._checkargs(drive_kwargs)
drive_kwargs.setdefault("fixed_subregions", None)
drive_kwargs.setdefault("output_step", False)
drive_kwargs.setdefault("n_threads", None)
Expand Down Expand Up @@ -98,7 +103,7 @@ def schedule_kwargs_setup(self, schedule_kwargs):
save additional data. Defaults to ``None``.
"""
self._checkargs(**schedule_kwargs)
schedule_kwargs = self._checkargs(schedule_kwargs)
schedule_kwargs.setdefault("fixed_subregions", None)
schedule_kwargs.setdefault("output_step", False)
schedule_kwargs.setdefault("compute", None)
Expand Down
3 changes: 2 additions & 1 deletion oommfc/drivers/hysteresisdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class HysteresisDriver(Driver):
"report_wall_time",
]

def _checkargs(self, **kwargs):
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)):
Expand All @@ -73,6 +73,7 @@ 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"""
Expand Down
4 changes: 2 additions & 2 deletions oommfc/drivers/mindriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class MinDriver(Driver):
"report_wall_time",
]

def _checkargs(self, **kwargs):
pass # no kwargs should be checked
def _checkargs(self, kwargs):
return kwargs # no kwargs should be checked

def _check_system(self, system):
"""Checks the system has energy in it"""
Expand Down
3 changes: 2 additions & 1 deletion oommfc/drivers/timedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TimeDriver(Driver):
"report_wall_time",
]

def _checkargs(self, **kwargs):
def _checkargs(self, kwargs):
t, n = kwargs["t"], kwargs["n"]
if t <= 0:
msg = f"Cannot drive with {t=}."
Expand All @@ -66,6 +66,7 @@ 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 57830b3

Please sign in to comment.