Skip to content

Commit

Permalink
add serialized simulation to diagnostics files
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Feb 2, 2024
1 parent 618c8f6 commit 4bb039e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
8 changes: 7 additions & 1 deletion pyphare/pyphare/pharein/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,14 @@ def as_paths(rb):
addInitFunction(maginit_path + "y_component", fn_wrapper(modelDict["by"]))
addInitFunction(maginit_path + "z_component", fn_wrapper(modelDict["bz"]))

serialized_sim = serialize_sim(simulation)

#### adding diagnostics

diag_path = "simulation/diagnostics/"
for diag in list(simulation.diagnostics.values()):
diag.attributes["serialized_simulation"] = serialized_sim

type_path = diag_path + diag.type + "/"
name_path = type_path + diag.name
add_string(name_path + "/" + "type", diag.type)
Expand All @@ -265,6 +270,7 @@ def as_paths(rb):
pp.add_array_as_vector(
name_path + "/" + "compute_timestamps", diag.compute_timestamps
)

add_size_t(name_path + "/" + "n_attributes", len(diag.attributes))
for attr_idx, attr_key in enumerate(diag.attributes):
add_string(name_path + "/" + f"attribute_{attr_idx}_key", attr_key)
Expand Down Expand Up @@ -343,7 +349,7 @@ def as_paths(rb):
restarts_path + "write_timestamps", restart_options["timestamps"]
)

add_string(restarts_path + "serialized_simulation", serialize_sim(simulation))
add_string(restarts_path + "serialized_simulation", serialized_sim)
#### restarts added

#### adding electrons
Expand Down
8 changes: 2 additions & 6 deletions pyphare/pyphare/pharein/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from ..core import phare_utilities
from . import global_vars

Expand Down Expand Up @@ -45,8 +47,6 @@ def wrapper(diagnostics_object, name, **kwargs):
return wrapper


import numpy as np

# ------------------------------------------------------------------------------
def validate_timestamps(clazz, key, **kwargs):
sim = global_vars.sim
Expand Down Expand Up @@ -173,7 +173,6 @@ def __init__(self, **kwargs):
)

def _setSubTypeAttributes(self, **kwargs):

if kwargs["quantity"] not in ElectromagDiagnostics.em_quantities:
error_msg = "Error: '{}' not a valid electromag diagnostics : " + ", ".join(
ElectromagDiagnostics.em_quantities
Expand Down Expand Up @@ -201,7 +200,6 @@ def population_in_model(population):


class FluidDiagnostics_(Diagnostics):

fluid_quantities = [
"density",
"mass_density",
Expand Down Expand Up @@ -327,7 +325,6 @@ def _setSubTypeAttributes(self, **kwargs):
self.quantity = "/ions/pop/" + self.population_name + "/" + self.quantity

def space_box(self, **kwargs):

if "extent" not in kwargs and self.quantity == "space_box":
raise ValueError(
"Error: missing 'extent' parameter required by 'space_box' the ParticleDiagnostics type"
Expand All @@ -352,7 +349,6 @@ def to_dict(self):


class MetaDiagnostics(Diagnostics):

meta_quantities = ["tags"]
type = "info"

Expand Down
1 change: 0 additions & 1 deletion pyphare/pyphare/pharesee/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def _divB2D(Bx, By, xBx, yBy):


def _compute_divB(patchdatas, **kwargs):

reference_pd = patchdatas["Bx"] # take Bx as a reference, but could be any other
ndim = reference_pd.box.ndim

Expand Down
9 changes: 8 additions & 1 deletion tests/simulator/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _test_dump_diags(self, dim, **simInput):
simInput["refinement_boxes"] = {"L0": {"B0": b0}}

py_attrs = [f"{dep}_version" for dep in ["samrai", "highfive", "pybind"]]
py_attrs += ["git_hash"]
py_attrs += ["git_hash", "serialized_simulation"]

for interp in range(1, 4):
print("test_dump_diags dim/interp:{}/{}".format(dim, interp))
Expand Down Expand Up @@ -203,6 +203,13 @@ def _test_dump_diags(self, dim, **simInput):
for py_attr in py_attrs:
self.assertIn(py_attr, h5_py_attrs)

assert (
ph.simulation.deserialize(
h5_file["py_attrs"].attrs["serialized_simulation"]
).electrons.closure.Te
== 0.12
)

hier = hierarchy_from(h5_filename=h5_filepath)
if h5_filepath.endswith("domain.h5"):
particle_files += 1
Expand Down

0 comments on commit 4bb039e

Please sign in to comment.