Skip to content

Commit

Permalink
Allow optimizer to be configured for MACE/GAP (#615)
Browse files Browse the repository at this point in the history
* fea: add MACE RelaxMaker and StaticMaker

* fea: add mace to reqs

* doc: add placeholders for the task_doc_kwargs and optimizer_kwargs

* fix: pin test to use float64 as model trained as double

* fix: set dtypes for tests

* fea: allow optimizer to be configured for MACE/GAP

* fix: optimizer_kwargs -> self.optimizer_kwargs

* fix: bad merge
  • Loading branch information
CompRhys authored Nov 17, 2023
1 parent 0738890 commit d693643
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/atomate2/forcefields/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ def _relax(self, structure: Structure) -> dict:
calculator = MACECalculator(
model_paths=self.potential_param_file_name, **self.potential_kwargs
)
relaxer = Relaxer(calculator, relax_cell=self.relax_cell)
relaxer = Relaxer(
calculator, **self.optimizer_kwargs, relax_cell=self.relax_cell
)
return relaxer.relax(structure, steps=self.steps, **self.relax_kwargs)


Expand Down Expand Up @@ -424,7 +426,9 @@ def _relax(self, structure: Structure) -> dict:
param_filename=str(self.potential_param_file_name),
**self.potential_kwargs,
)
relaxer = Relaxer(calculator, relax_cell=self.relax_cell)
relaxer = Relaxer(
calculator, **self.optimizer_kwargs, relax_cell=self.relax_cell
)
return relaxer.relax(structure, steps=self.steps, **self.relax_kwargs)


Expand Down
5 changes: 3 additions & 2 deletions tests/forcefields/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_mace_relax_maker(si_structure, test_dir, revert_torch_default_dtype):
# 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",
optimizer_kwargs={"optimizer": "BFGSLineSearch"},
potential_kwargs={"default_dtype": "float64", "device": "cpu"},
steps=25,
).make(si_structure)
Expand All @@ -131,8 +132,8 @@ def test_mace_relax_maker(si_structure, test_dir, revert_torch_default_dtype):
# validating the outputs of the job
output1 = responses[job.uuid][1].output
assert isinstance(output1, ForceFieldTaskDocument)
assert output1.output.energy == approx(-0.051099, rel=1e-4)
assert output1.output.n_steps == 10
assert output1.output.energy == approx(-0.051912, rel=1e-4)
assert output1.output.n_steps == 4


def test_gap_static_maker(si_structure, test_dir):
Expand Down

0 comments on commit d693643

Please sign in to comment.