Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion imaspy/backends/imas_core/db_entry_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ def get_children(
getattr(structure, name)._IDSPrimitive__value = data


def _get_child(child: IDSBase, ctx: LazyALContext):
def _get_child(child: IDSBase, ctx: Optional[LazyALContext]):
"""Get a single child when required (lazy loading)."""
# NOTE: changes in this method must be propagated to _get_children and vice versa
# Performance: this method is specialized for the lazy get

# ctx can be None when the parent structure does not exist in the on-disk DD version
if ctx is None:
return # There is no data to be loaded

time_mode = ctx.time_mode
if time_mode == IDS_TIME_MODE_INDEPENDENT and child.metadata.type.is_dynamic:
return # skip dynamic (time-dependent) nodes
Expand Down
16 changes: 16 additions & 0 deletions imaspy/test/test_lazy_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ def test_lazy_load_with_new_aos(requires_imas):
dbentry.close()


def test_lazy_load_with_new_structure(requires_imas):
dbentry = DBEntry(MEMORY_BACKEND, "ITER", 1, 1, dd_version="3.30.0")
dbentry.create()

eq = dbentry.factory.equilibrium()
eq.ids_properties.homogeneous_time = IDS_TIME_MODE_HOMOGENEOUS
eq.time = [0.0]
eq.time_slice.resize(1)
dbentry.put(eq)

entry2 = DBEntry(MEMORY_BACKEND, "ITER", 1, 1, data_version="3", dd_version="4.0.0")
entry2.open()
lazy_eq = entry2.get("equilibrium", lazy=True)
assert not lazy_eq.time_slice[0].boundary.dr_dz_zero_point.r.has_value


def test_lazy_load_multiple_ids(backend, worker_id, tmp_path):
if backend == ASCII_BACKEND:
pytest.skip("Lazy loading is not supported by the ASCII backend.")
Expand Down