Skip to content

Commit

Permalink
Update tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
frostedoyster committed Jan 26, 2024
1 parent a7811bc commit f8b2325
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
20 changes: 18 additions & 2 deletions docs/src/getting-started/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,31 @@ the current directory and type
Evaluation
##########

The sub-command to evaluate a already trained model is
The sub-command to evaluate an already trained model is

.. code-block:: bash
metatensor-models eval
.. literalinclude:: ../../../examples/usage.sh
:language: bash
:lines: 9-
:lines: 9-25


Exporting
#########

Exporting a model is very useful if you want to use it in other frameworks,
especially in molecular dynamics simulations.
The sub-command to export an already trained model is

.. code-block:: bash
metatensor-models export
.. literalinclude:: ../../../examples/usage.sh
:language: bash
:lines: 25-

In the next tutorials we show how adjust the dataset section of ``options.yaml`` file
to use it for your own datasets.
6 changes: 6 additions & 0 deletions examples/usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ head -n 20 output.xyz
# All command line flags of the eval sub-command can be listed via

metatensor-models eval --help

# For example, the following command

metatensor-models export model.pt

# creates an `exported-model.pt` file that contains the exported model.
5 changes: 4 additions & 1 deletion src/metatensor/models/cli/export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ def export_model(model: str, output: Optional[str]) -> None:

# Export the model
wrapper = MetatensorAtomisticModel(loaded_model.eval(), loaded_model.capabilities)
wrapper.export("exported-model.pt")
if output is None:
wrapper.export("exported-model.pt")
else:
wrapper.export(output)
32 changes: 32 additions & 0 deletions tests/cli/test_export_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import shutil
import subprocess
from pathlib import Path

import pytest


# Execute the setup script which will make sum_over_samples saveable.
current_dir = os.path.dirname(__file__)
setup_path = os.path.join(current_dir, "..", "..", "scripts", "setup.py")
exec(open(setup_path).read())


RESOURCES_PATH = Path(__file__).parent.resolve() / ".." / "resources"


@pytest.mark.parametrize("output", [None, "exported.pt"])
def test_export(monkeypatch, tmp_path, output):
"""Test that the export cli runs without an error raise."""
monkeypatch.chdir(tmp_path)
shutil.copy(RESOURCES_PATH / "bpnn-model.pt", "bpnn-model.pt")

command = ["metatensor-models", "export", "bpnn-model.pt"]

if output is not None:
command += ["-o", output]
else:
output = "exported-model.pt"

subprocess.check_call(command)
assert Path(output).is_file()
Binary file modified tests/resources/bpnn-model.pt
Binary file not shown.
Binary file removed tests/resources/model.pt
Binary file not shown.

0 comments on commit f8b2325

Please sign in to comment.