kups.core.storage
¶
HDF5-backed storage for simulation trajectories.
Provides async-writing :class:HDF5StorageWriter (Logger protocol) and
:class:HDF5StorageReader for reading back logged data. Logging frequency
is controlled via :class:LoggingFrequency implementations (:class:Once,
:class:EveryNStep).
BackgroundWriter
dataclass
¶
Background thread worker that asynchronously writes pre-extracted data to HDF5.
Source code in src/kups/core/storage.py
flush()
¶
start()
¶
Main loop for the background writer thread.
Source code in src/kups/core/storage.py
stop()
¶
EveryNStep
dataclass
¶
Bases: LoggingFrequency
Logs data every N steps, creating datasets with a time dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The interval between logging steps (e.g., n=10 logs at steps 0, 10, 20, ...). |
required |
Source code in src/kups/core/storage.py
GroupReader
dataclass
¶
Reader for a single HDF5 logging group, providing array-like access.
Source code in src/kups/core/storage.py
GroupWriters
dataclass
¶
Bases: WriterGroupConfig[State, Storage]
Internal class combining a WriterGroupConfig with its initialized HDF5 writer.
Source code in src/kups/core/storage.py
HDF5StorageReader
dataclass
¶
Reader for HDF5 files created by HDF5StorageWriter.
Usage
Source code in src/kups/core/storage.py
focus_group(view_or_name)
¶
Returns a reader for a specific logging group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_or_name
|
View[Config, WriterGroupConfig[Any, Storage]] | str
|
Either a string group name or a View lens. |
required |
Source code in src/kups/core/storage.py
HDF5StorageWriter
dataclass
¶
Logs simulation state to HDF5 files. Implements the Logger protocol.
Usage as context manager (preferred):
writer = HDF5StorageWriter(out_path, config, initial_state, total_steps=1000)
with writer:
for step in range(1000):
state = simulate_step(state)
writer.log(state, step)
The writer opens the file and starts a background I/O thread on __enter__,
and flushes, records actual_steps, and closes the file on __exit__.
Source code in src/kups/core/storage.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
log(state, step)
¶
Queue state for async background writing.
Hdf5ObjWriter
dataclass
¶
Low-level writer for a single HDF5 group that stores a pytree of JAX arrays.
Source code in src/kups/core/storage.py
LoggingFrequency
¶
Bases: Protocol
Protocol for defining when and how data should be logged during simulation.
Implementations control logging frequency, determine HDF5 dataset dimensions, and map simulation steps to dataset indices.
Source code in src/kups/core/storage.py
Once
¶
Bases: LoggingFrequency
Logs data only at step 0, creating scalar datasets without time dimension.
Source code in src/kups/core/storage.py
WriterGroupConfig
dataclass
¶
Configuration for a single logging group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
View[State, Storage]
|
A lens that extracts Storage data from the full State. |
required |
logging_frequency
|
LoggingFrequency
|
Controls when this data should be logged. |
required |