Skip to content

Commit

Permalink
Merge pull request #82 from ubermag/extend-info-file
Browse files Browse the repository at this point in the history
Add adapter to info.json
  • Loading branch information
swapneelap authored Nov 29, 2023
2 parents dfd1e71 + 32a938b commit 12cb9a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions micromagneticmodel/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ def _write_info_json(self, system, **kwargs):
info["date"] = datetime.datetime.now().strftime("%Y-%m-%d")
info["time"] = datetime.datetime.now().strftime("%H:%M:%S")
info["driver"] = self.__class__.__name__
# "adapter" is the ubermag package (e.g. oommfc) that communicates with the
# calculator (e.g. OOMMF)
info["adapter"] = self.__module__.split(".")[0]
for k, v in kwargs.items():
info[k] = v
with open("info.json", "wt", encoding="utf-8") as jsonfile:
Expand Down
15 changes: 15 additions & 0 deletions micromagneticmodel/tests/test_driver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import datetime
import json

import discretisedfield as df
import pytest

Expand Down Expand Up @@ -66,6 +69,18 @@ def test_external_driver(tmp_path):
assert system.m.allclose(-mm.examples.macrospin().m)
assert (tmp_path / system.name / "drive-0" / "info.json").exists()

with open(tmp_path / system.name / "drive-0" / "info.json") as f:
info = json.load(f)

assert info["adapter"] == "micromagneticmodel"
assert info["driver"] == "MyExternalDriver"
assert info["drive_number"] == 0

info_time = datetime.datetime.fromisoformat(f"{info['date']}T{info['time']}")
now = datetime.datetime.now()
# assumption: this test runs in under one minute
assert (now - info_time).total_seconds() < 60

with pytest.raises(FileExistsError):
driver.drive(system, dirname=str(tmp_path), append=False)

Expand Down

0 comments on commit 12cb9a6

Please sign in to comment.