Skip to content

Commit

Permalink
Read descriptors from openPMD
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 30, 2024
1 parent 9f538c7 commit 4285ebf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
24 changes: 24 additions & 0 deletions examples/advanced/ex09_convert_numpy_openpmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mala

parameters = mala.Parameters()
data_converter = mala.DataConverter(parameters)

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

# data_handler.descriptor_calculator.write_to_openpmd_file("descriptor_*.bp")
data_converter.convert_snapshots(
descriptor_save_path="./",
target_save_path="./",
additional_info_save_path="./",
naming_scheme="Be_snapshot*.bp",
descriptor_calculation_kwargs={"working_directory": "./"},
)
2 changes: 1 addition & 1 deletion examples/basic/ex03_preprocess_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""
Shows how this framework can be used to preprocess
data. Preprocessing here means converting raw DFT calculation output into
data. Preprocessing here means converting raw DFT calculation output into
numpy arrays of the correct size. For the input data, this means descriptor
calculation.
Expand Down
13 changes: 11 additions & 2 deletions mala/common/physical_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ def write_to_openpmd_iteration(
atoms_openpmd["position"][str(atom)].unit_SI = 1.0e-10
atoms_openpmd["positionOffset"][str(atom)].unit_SI = 1.0e-10

if any(i == 0 for i in self.grid_dimensions) and not isinstance(
array, self.SkipArrayWriting
):
self.grid_dimensions = array.shape[0:-1]

dataset = (
array.dataset
if isinstance(array, self.SkipArrayWriting)
Expand All @@ -564,8 +569,12 @@ def write_to_openpmd_iteration(
# Global feature sizes:
feature_global_from = 0
feature_global_to = self.feature_size
if feature_global_to == 0 and isinstance(array, self.SkipArrayWriting):
feature_global_to = array.feature_size
if feature_global_to == 0:
feature_global_to = (
array.feature_size
if isinstance(array, self.SkipArrayWriting)
else array.shape[-1]
)

# First loop: Only metadata, write metadata equivalently across ranks
for current_feature in range(feature_global_from, feature_global_to):
Expand Down
17 changes: 15 additions & 2 deletions mala/datahandling/data_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from mala.targets.target import Target
from mala.version import __version__ as mala_version

descriptor_input_types = ["espresso-out"]
target_input_types = [".cube", ".xsf"]
descriptor_input_types = ["espresso-out", "openpmd"]
target_input_types = [".cube", ".xsf", "openpmd"]
additional_info_input_types = ["espresso-out"]


Expand Down Expand Up @@ -546,6 +546,16 @@ def __convert_single_snapshot(
snapshot["input"], **descriptor_calculation_kwargs
)
)
print(tmp_input)
print(tmp_input.shape)
print(local_size)

elif description["input"] == "openpmd":
tmp_input = self.descriptor_calculator.read_from_openpmd_file(
snapshot["input"]
)
print(tmp_input)
print(tmp_input.shape)

elif description["input"] is None:
# In this case, only the output is processed.
Expand Down Expand Up @@ -617,6 +627,9 @@ def __convert_single_snapshot(
snapshot["output"], **target_calculator_kwargs
)

elif description["output"] == "openpmd":
raise RuntimeError("unimplemented!")

elif description["output"] is None:
# In this case, only the input is processed.
pass
Expand Down

0 comments on commit 4285ebf

Please sign in to comment.