Skip to content

Commit

Permalink
Use BP5, add CI test
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Nov 15, 2024
1 parent e324f55 commit 09ed574
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/advanced/ex10_convert_numpy_openpmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
descriptor_save_path="./",
target_save_path="./",
additional_info_save_path="./",
naming_scheme="converted_from_numpy_*.bp4",
naming_scheme="converted_from_numpy_*.bp5",
descriptor_calculation_kwargs={"working_directory": "./"},
)

Expand All @@ -40,11 +40,11 @@
for snapshot in range(2):
data_converter.add_snapshot(
descriptor_input_type="openpmd",
descriptor_input_path="converted_from_numpy_{}.in.bp4".format(
descriptor_input_path="converted_from_numpy_{}.in.bp5".format(
snapshot
),
target_input_type="openpmd",
target_input_path="converted_from_numpy_{}.out.bp4".format(snapshot),
target_input_path="converted_from_numpy_{}.out.bp5".format(snapshot),
additional_info_input_type=None,
additional_info_input_path=None,
target_units=None,
Expand Down
71 changes: 71 additions & 0 deletions test/complete_interfaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,77 @@ def test_openpmd_io(self):
rtol=accuracy_fine,
)

@pytest.mark.skipif(
importlib.util.find_spec("openpmd_api") is None,
reason="No OpenPMD found on this machine, skipping " "test.",
)
def test_convert_numpy_openpmd(self):
parameters = mala.Parameters()
parameters.descriptors.descriptors_contain_xyz = False

data_converter = mala.DataConverter(parameters)
for snapshot in range(2):
data_converter.add_snapshot(
descriptor_input_type="numpy",
descriptor_input_path=os.path.join(
data_path, "Be_snapshot{}.in.npy".format(snapshot)
),
target_input_type="numpy",
target_input_path=os.path.join(
data_path, "Be_snapshot{}.out.npy".format(snapshot)
),
additional_info_input_type=None,
additional_info_input_path=None,
target_units=None,
)

data_converter.convert_snapshots(
descriptor_save_path="./",
target_save_path="./",
additional_info_save_path="./",
naming_scheme="converted_from_numpy_*.bp5",
descriptor_calculation_kwargs={"working_directory": "./"},
)

# Convert those files back to Numpy to verify the data stays the same.

data_converter = mala.DataConverter(parameters)

for snapshot in range(2):
data_converter.add_snapshot(
descriptor_input_type="openpmd",
descriptor_input_path="converted_from_numpy_{}.in.bp5".format(
snapshot
),
target_input_type="openpmd",
target_input_path="converted_from_numpy_{}.out.bp5".format(snapshot),
additional_info_input_type=None,
additional_info_input_path=None,
target_units=None,
)

data_converter.convert_snapshots(
descriptor_save_path="./",
target_save_path="./",
additional_info_save_path="./",
naming_scheme="verify_against_original_numpy_data_*.npy",
descriptor_calculation_kwargs={"working_directory": "./"},
)

for snapshot in range(2):
for i_o in ["in", "out"]:
original = os.path.join(
data_path, "Be_snapshot{}.{}.npy".format(snapshot, i_o)
)
roundtrip = "verify_against_original_numpy_data_{}.{}.npy".format(
snapshot, i_o
)
import numpy as np

original_a = np.load(original)
roundtrip_a = np.load(roundtrip)
np.testing.assert_allclose(original_a, roundtrip_a)

@pytest.mark.skipif(
importlib.util.find_spec("total_energy") is None
or importlib.util.find_spec("lammps") is None,
Expand Down

0 comments on commit 09ed574

Please sign in to comment.