Skip to content

Commit

Permalink
parametrize model_path in test_mace_static_maker and test_mace_relax_…
Browse files Browse the repository at this point in the history
…maker
  • Loading branch information
janosh committed Nov 16, 2023
1 parent c74e0f1 commit 29c8062
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tests/forcefields/test_jobs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import pytest
from jobflow import run_locally
from pytest import approx, importorskip
Expand Down Expand Up @@ -92,15 +94,26 @@ def test_m3gnet_relax_maker(si_structure):
assert output1.output.n_steps == 14


def test_mace_static_maker(si_structure, test_dir, revert_torch_default_dtype):
mace_paths = pytest.mark.parametrize(
"model_path",
[
# None, # TODO uncomment once https://github.com/ACEsuit/mace/pull/230 is merged
# to test loading MACE checkpoint on the fly from figshare
f"{Path(__file__).parent.parent}/test_data/forcefields/mace/MACE.model",
],
)


@mace_paths
def test_mace_static_maker(
si_structure, test_dir, revert_torch_default_dtype, model_path
):
task_doc_kwargs = {"ionic_step_data": ("structure", "energy")}

# generate job
# NOTE the test model is not trained on Si, so the energy is not accurate
job = MACEStaticMaker(
potential_param_file_name=test_dir / "forcefields" / "mace" / "MACE.model",
potential_kwargs={"default_dtype": "float64", "device": "cpu"},
task_document_kwargs=task_doc_kwargs,
model_path=model_path, task_document_kwargs=task_doc_kwargs
).make(si_structure)

# run the flow or job and ensure that it finished running successfully
Expand All @@ -113,17 +126,16 @@ def test_mace_static_maker(si_structure, test_dir, revert_torch_default_dtype):
assert output1.output.n_steps == 1


def test_mace_relax_maker(si_structure, test_dir, revert_torch_default_dtype):
@mace_paths
def test_mace_relax_maker(
si_structure, test_dir, revert_torch_default_dtype, model_path
):
# translate one atom to ensure a small number of relaxation steps are taken
si_structure.translate_sites(0, [0, 0, 0.1])

# generate job
# NOTE the test model is not trained on Si, so the energy is not accurate
job = MACERelaxMaker(
potential_param_file_name=test_dir / "forcefields" / "mace" / "MACE.model",
potential_kwargs={"default_dtype": "float64", "device": "cpu"},
steps=25,
).make(si_structure)
job = MACERelaxMaker(model_path=model_path, steps=25).make(si_structure)

# run the flow or job and ensure that it finished running successfully
responses = run_locally(job, ensure_success=True)
Expand Down

0 comments on commit 29c8062

Please sign in to comment.