icon_sc.core.io — monitors and output

Generic I/O: monitors (§7.4). Synchronous single-rank slice; async/zarr post-slice.

In-memory monitor and shared monitor helpers (§7.4, SPEC S03).

MemoryMonitor snapshots states for tests and interactive work (the RCE-style acceptance loop verifies trajectories against closed forms through it). Snapshots are deep copies of the selected DataArrays: T0 loops with out= mutate buffers in place, so a monitor holding references would watch its history being rewritten.

class icon_sc.core.io.monitor.MemoryMonitor(*, variables=None, name=None)

Store deep-copied state snapshots in memory (frozen interface, SPEC S03).

Parameters:
  • variables (Iterable[str] | None)

  • name (str | None)

property snapshots: tuple[dict[str, Any], ...]

The stored snapshots, oldest first.

store(state)

Store the given state (side effect defined by the concrete monitor).

Parameters:

state (Mapping[str, Any])

Return type:

None

icon_sc.core.io.monitor.snapshot_state(state, *, variables=None)

A deep-copied snapshot of state (optionally restricted to variables).

The time entry is always kept; DataArray values are deep-copied, anything else (time) is carried as-is.

Parameters:
Return type:

dict[str, Any]

Synchronous single-rank NetCDF monitor (§7.4, SPEC S03).

xarray-based, one file, record appended on every store — semantics from upstream sympl’s NetCDFMonitor (see REFERENCES.lock), reimplemented over xarray. The T0 implementation keeps all stored records in memory and rewrites the whole file per store (synchronous, deliberately dumb — enough for the SCM example); async writers and zarr are post-slice.

class icon_sc.core.io.netcdf.NetCDFMonitor(filename, *, variables=None, name=None)

Write stored states to one NetCDF file, appending a time record per store.

variables restricts the stored set (default: every DataArray in the state). The provenance stamp (§5.3) is written into the global attributes as JSON under icon_sc_provenance.

Parameters:
  • filename (str | Path)

  • variables (Iterable[str] | None)

  • name (str | None)

property path: Path

The output file.

store(state)

Append the state as one time record and (re)write the file.

Parameters:

state (Mapping[str, Any])

Return type:

None