Skip to content

Commit

Permalink
Deleted extract_all_simulation_subsections (using extract_section fro…
Browse files Browse the repository at this point in the history
…m nomad.utils directly)
  • Loading branch information
JosePizarro3 committed Oct 10, 2024
1 parent ad055ee commit 20e0277
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 118 deletions.
1 change: 0 additions & 1 deletion src/nomad_simulations/schema_packages/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .utils import (
RussellSaundersState,
extract_all_simulation_subsections,
get_composition,
get_sibling_section,
get_variables,
Expand Down
37 changes: 0 additions & 37 deletions src/nomad_simulations/schema_packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,40 +159,3 @@ def get_composition(children_names: 'list[str]') -> str:
children_count_tup = np.unique(children_names, return_counts=True)
formula = ''.join([f'{name}({count})' for name, count in zip(*children_count_tup)])
return formula if formula else None


def extract_all_simulation_subsections(
archive: 'EntryArchive',
i_system: int = 0,
i_method: int = -1,
i_output: int = -1,
) -> 'tuple[ModelSystem, ModelMethod, Outputs]':
"""
Extracts the simulation sub-sections for `ModelSystem`, `ModelMethod`, and `Outputs` from the archive. The specific
element of the section returned is specified by the indices `i_system`, `i_method`, and `i_output`.
This utility function is useful when extracting the initial `ModelSystem` structure, the `ModelMethod` used in
the simulation, and the last `Outputs` section generated by the simulation.
Args:
archive (EntryArchive): The archive to extract the simulation sub-sections from.
i_system (int, optional): The index of the `ModelSystem` to extract. Defaults to 0.
i_method (int, optional): The index of the `ModelMethod` to extract. Defaults to -1.
i_output (int, optional): The index of the `Outputs` to extract. Defaults to -1.
Returns:
tuple[ModelSystem, ModelMethod, Outputs]: The extracted `ModelSystem`, `ModelMethod`, and `Outputs` sections.
"""
if (
not archive.m_xpath('data.model_system')
or not archive.m_xpath('data.model_method')
or not archive.m_xpath('data.outputs')
):
return None, None, None
try:
system = archive.data.model_system[i_system]
method = archive.data.model_method[i_method]
output = archive.data.outputs[i_output]
return system, method, output
except IndexError:
return None, None, None
80 changes: 0 additions & 80 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
)
from nomad_simulations.schema_packages.outputs import Outputs
from nomad_simulations.schema_packages.utils import (
extract_all_simulation_subsections,
get_sibling_section,
get_variables,
is_not_representative,
Expand Down Expand Up @@ -89,82 +88,3 @@ def test_get_variables(variables: list, result: list, result_length: int):
assert len(energies) == result_length
for i, energy in enumerate(energies): # asserting energies == result does not work
assert energy.n_points == result[i].n_points


@pytest.mark.parametrize(
'archive, subsection_indices, result',
[
# no data section
(
EntryArchive(),
[0, -1, -1],
[None, None, None],
),
# no subsections
(
EntryArchive(data=Simulation()),
[0, -1, -1],
[None, None, None],
),
# no model_method and outputs
(
EntryArchive(data=Simulation(model_system=[ModelSystem()])),
[0, -1, -1],
[None, None, None],
),
# no outputs
(
EntryArchive(
data=Simulation(
model_system=[ModelSystem()], model_method=[ModelMethod()]
)
),
[0, -1, -1],
[None, None, None],
),
# all subsections
(
EntryArchive(
data=Simulation(
model_system=[ModelSystem()],
model_method=[ModelMethod()],
outputs=[Outputs()],
)
),
[0, -1, -1],
[ModelSystem(), ModelMethod(), Outputs()],
),
# wrong index for model_system
(
EntryArchive(
data=Simulation(
model_system=[ModelSystem()],
model_method=[ModelMethod()],
outputs=[Outputs()],
)
),
[2, -1, -1],
[None, None, None],
),
],
)
def test_extract_all_simulation_subsections(
archive: EntryArchive, subsection_indices: list, result: list
):
"""
Test the `extract_all_simulation_subsections` utility function.
"""
system, method, output = extract_all_simulation_subsections(
archive=archive,
i_system=subsection_indices[0],
i_method=subsection_indices[1],
i_output=subsection_indices[2],
)
if result[0] is not None:
assert (
isinstance(system, ModelSystem)
and isinstance(method, ModelMethod)
and isinstance(output, Outputs)
)
else:
assert system == result[0] and method == result[1] and output == result[2]

0 comments on commit 20e0277

Please sign in to comment.