result
¶
Structured simulation result with metadata and serialize/reload.
SimulationResult
dataclass
¶
Outputs from a simulator simulate() / run() call.
Attributes:
-
times(NDArray[float64]) –Simulation time grid.
-
observables(list[NDArray[float64]]) –One expectation trajectory per measured observable / group.
-
states(list[ndarray] | None) –Optional state trajectory (
Nonewhen the backend does not store states). -
seed(int | None) –Random seed used for the run, if any.
-
algorithm(str) –Backend identifier (typically the simulator
id). -
runtime(float | None) –Wall-clock seconds for the
simulate()call, if recorded. -
metadata(dict[str, Any]) –Reproducibility and parameter metadata (version, params, …).
-
counts(list[dict[str, int]] | None) –One shot-count dict per entry of
times(Nonewhen the backend does not sample). Bitiof a key is system qubiti.
Source code in shadowsim/simulators/result.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
save
¶
Write this result to a directory as numeric arrays plus meta.json.
Layout::
path/
times.npy
observables.npz
states.npz # only when ``states`` is not None
counts.json # only when ``counts`` is not None
meta.json
Traces and states keep their shapes, including jagged traces. Archives
contain only numeric arrays, so load can read them with
allow_pickle=False.
Source code in shadowsim/simulators/result.py
load
classmethod
¶
load(path: str | Path) -> SimulationResult
Reload a result previously written by save.
Array files are read with allow_pickle=False. A numeric
observables.npy from an older save still loads. Object-dtype arrays
and other pickle payloads are rejected and not executed. states.npy
from an older save is refused, because that file was an object array.
Source code in shadowsim/simulators/result.py
package_version
¶
Return the installed shadowsim version, or "unknown" if unavailable.
save_resource_metrics
¶
save_resource_metrics(
simulator: object,
wall_time: float | None,
*,
path: Path | None = None,
output_dir: str | Path = "results",
) -> Path
Write one simulator's runtime and shot budget as JSON.
When path is set, that file is written and output_dir is ignored.
Otherwise a timestamped resource_metrics_*.json file is written under
output_dir (default results/), which is created if it does not exist.
The payload is {"resources": [record]}. Shot fields are None when
neither the circuit backend nor the simulator stores an integer shots
count. Otherwise num_jobs is len(tlist) and total_shots is
shots_per_job * num_jobs. depth, width, gate_count,
t_count, and toffoli_count are integers when the backend can
measure metrics_circuit. Each is "N/A" when it cannot.