Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adapter to info.json #82

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading