jaxdem.utils.load_legacy#

Adapter for loading HDF5 data saved with the pre-merge-2-27-26 branch.

The old format differs from the current one in several ways:

State field renames:

angVel -> ang_vel, clump_ID -> clump_id, deformable_ID -> bond_id, unique_ID -> unique_id.

System changes:

New fields bonded_force_model and interact_same_bond_id did not exist.

DeformableParticle changes:

Class moved from jaxdem.forces.deformable_particle:DeformableParticleContainer to jaxdem.bonded_forces.deformable_particle:DeformableParticleModel. Fields renamed: elements_ID -> elements_id, initial_bending -> initial_bendings. Fields removed: edges_ID, element_adjacency_ID, weighted_ref_vectors, directed_edges_source, directed_edges_target, lame_lambda, lame_mu. New field: w_b (bending normalization, computed from reference geometry).

Functions

load_legacy_dp(path[, ref_pos, dim])

Load an old DeformableParticleContainer h5 file and return a new DeformableParticleModel.

load_legacy_simulation(state_path, system_path)

Load state, system, and (optionally) a deformable-particle container from old-format h5 files and wire them into a ready-to-use (State, System) pair.

load_legacy_state(path)

Load a State saved with the old field naming convention (angVel, clump_ID, deformable_ID, unique_ID).

load_legacy_system(path[, state_shape])

Load a System saved with the old schema (no bonded_force_model or interact_same_bond_id fields).

jaxdem.utils.load_legacy.load_legacy_dp(path: str, ref_pos: jax.Array | None = None, dim: int = 3) DeformableParticleModel[source]#

Load an old DeformableParticleContainer h5 file and return a new DeformableParticleModel.

Parameters:
  • path (str) – Path to the .h5 file containing the saved DP container.

  • ref_pos (jax.Array, optional) – Reference vertex positions, shape (N, dim). Required for 3D to compute the new w_b bending normalization. You can obtain this from the legacy state: ref_pos = state.pos.

  • dim (int) – Spatial dimension (2 or 3). Needed to choose the correct w_b computation.

Returns:

A new model instance with fields mapped from the old container.

Return type:

DeformableParticleModel

jaxdem.utils.load_legacy.load_legacy_simulation(state_path: str, system_path: str, dp_path: str | None = None) tuple[State, System][source]#

Load state, system, and (optionally) a deformable-particle container from old-format h5 files and wire them into a ready-to-use (State, System) pair.

When dp_path is given, the DP model is attached to the system via system.bonded_force_model and its force/energy functions are registered in the force manager.

Parameters:
  • state_path (str) – Path to the legacy State h5 file.

  • system_path (str) – Path to the legacy System h5 file.

  • dp_path (str, optional) – Path to the legacy DeformableParticleContainer h5 file.

Returns:

  • state (State) – The loaded state with current field names.

  • system (System) – The loaded system, with bonded forces wired up if dp_path was given.

Example

from jaxdem.utils.load_legacy import load_legacy_simulation

state, system = load_legacy_simulation(
    "old_data/state.h5",
    "old_data/system.h5",
    dp_path="old_data/dp.h5",
)
jaxdem.utils.load_legacy.load_legacy_state(path: str) State[source]#

Load a State saved with the old field naming convention (angVel, clump_ID, deformable_ID, unique_ID).

Parameters:

path (str) – Path to the .h5 file containing the saved State.

Returns:

A new State constructed with the current field names.

Return type:

State

jaxdem.utils.load_legacy.load_legacy_system(path: str, state_shape: tuple[int, ...] | None = None) System[source]#

Load a System saved with the old schema (no bonded_force_model or interact_same_bond_id fields).

The current System.create factory is used to produce a valid skeleton; scalar fields (dt, time, step_count, key) and nested component dataclasses that still exist (collider, domain, force_model, mat_table, force_manager, integrators) are overwritten from the file where the schemas still match.

Parameters:
  • path (str) – Path to the .h5 file containing the saved System.

  • state_shape (tuple of int, optional) – Shape hint (N, dim) passed to System.create to build default components. If None, inferred from the stored force_manager/external_force or force_manager/external_force_com dataset.

Returns:

A new System instance populated with as much data from the file as possible. bonded_force_model defaults to None and interact_same_bond_id defaults to False.

Return type:

System