Restartable Parameter SweepsΒΆ
ParameterSweep expands a parameter grid, passes each point to a callback, saves returned Result objects, and writes manifest.json, summary.csv, and summary.h5 when an output directory is supplied.
from pathlib import Path
import numpy as np
import openquantumsim as oqs
For a lightweight tutorial, the callback below returns an analytic Result instead of launching a backend simulation. The same pattern works for mesolve or mcsolve.
def run_point(point: oqs.SweepPoint) -> oqs.Result:
gamma = float(point.params["gamma"])
times = np.linspace(0.0, 4.0, 41)
population = np.exp(-gamma * times).astype(np.complex128)
return oqs.Result(
times=times,
expect=[population],
solver_stats={"retcode": "Success", "gamma": gamma},
)
sweep = oqs.ParameterSweep(
base_system={"model": "analytic_decay"},
params={"gamma": [0.1, 0.2, 0.4]},
)
run = sweep.run(run_point, output_dir=Path("runs/tutorial_sweep"))
run.summary
Rerunning the same cell skips completed points unless force=True or restart=True is passed.