Skip to content

Commit 32f3559

Browse files
committed
Implement list_fill_paths for IMAS-Core (HDF5 backend)
1 parent 6fca4fd commit 32f3559

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

imas/backends/imas_core/al_context.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ def list_all_occurrences(self, ids_name: str) -> List[int]:
174174
return list(occurrences)
175175
return []
176176

177+
def list_filled_paths(self, path: str) -> List[str]:
178+
"""List all filled paths in an IDS.
179+
180+
Args:
181+
path: IDS and occurrence as a string: <IDS>[/<occurrence>]
182+
"""
183+
status, result = ll_interface.list_filled_paths(self.ctx, path)
184+
if status != 0:
185+
raise LowlevelError(f"list filled paths for {path!r}", status)
186+
return result
187+
177188
def close(self):
178189
"""Close this ALContext."""
179190
ll_interface.end_action(self.ctx)

imas/backends/imas_core/db_entry_al.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,17 @@ def list_all_occurrences(self, ids_name: str) -> List[int]:
365365
return occurrence_list
366366

367367
def list_filled_paths(self, ids_name: str, occurrence: int) -> List[str]:
368-
raise NotImplementedError()
368+
if self._db_ctx is None:
369+
raise RuntimeError("Database entry is not open.")
370+
ll_path = ids_name
371+
if occurrence != 0:
372+
ll_path += f"/{occurrence}"
373+
paths = self._db_ctx.list_filled_paths(ll_path)
374+
if not paths:
375+
raise DataEntryException(
376+
f"IDS {ids_name!r}, occurrence {occurrence} is empty."
377+
)
378+
return paths
369379

370380
def _check_uda_warnings(self, lazy: bool) -> None:
371381
"""Various checks / warnings for the UDA backend."""

imas/backends/imas_core/imas_interface.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ def begin_timerange_action(
166166
):
167167
raise self._minimal_version("5.4")
168168

169+
# New method in AL 5.7
170+
171+
def list_filled_paths(self, ctx, path):
172+
raise self._minimal_version("5.7")
173+
169174

170175
# Dummy documentation for interface:
171176
for funcname in dir(LowlevelInterface):

imas/test/test_list_filled_paths.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
22

33
import imas
4-
from imas.backends.imas_core.imas_interface import ll_interface
4+
from imas_core import _al_lowlevel
55
from imas.exception import DataEntryException
66
from imas.ids_defs import IDS_TIME_MODE_HOMOGENEOUS, IDS_TIME_MODE_INDEPENDENT
77

88

9-
if not hasattr(ll_interface, "list_all_occurrences"):
10-
marker = pytest.mark.xfail(reason="list_all_occurrences not available in imas_core")
9+
if not hasattr(_al_lowlevel, "al_list_filled_paths"):
10+
marker = pytest.mark.xfail(reason="list_filled_paths not available in imas_core")
1111
else:
1212
marker = []
1313

@@ -61,6 +61,9 @@ def test_list_filled_paths(testuri):
6161
# Other occurrence should still raise an error:
6262
with pytest.raises(DataEntryException):
6363
dbentry.list_filled_paths("core_profiles", 1)
64+
# Until we write data to the occurrence:
65+
dbentry.put(cp, 3)
66+
assert set(filled_paths) == set(dbentry.list_filled_paths("core_profiles", 3))
6467

6568

6669
def test_list_filled_paths_autoconvert(testuri):

0 commit comments

Comments
 (0)