# Persistent Parameter Scan Persistent Parameter Scan repeats the radius scan from [Parameter Scan](parameter_scan.md) and stores the results in a {class}`Resultbag `. On a later run, JCMsuite reuses {term}`resultbag entries ` that match the {term}`project`, {term}`project keys`, {term}`JCMT pattern`, and source-file state. The same workflow supports multi-dimensional parameter scans. Each complete set of project keys is one Resultbag entry. ## Define The Scan The script uses `numpy.linspace(...)` to create 41 equally spaced radii from $0.3\,\mathrm{\mu m}$ through $0.5\,\mathrm{\mu m}$. The script then creates one set of project keys for each radius and opens `results.jcmrb` in the current working directory: ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/run.py :language: python :lines: 6-11 ``` ## Run The Scan ```{warning} Open Resultbag files only from trusted sources. Loading stored results uses Python pickle and can execute code from the Resultbag file. ``` ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/run.py :language: python ``` Pass the {class}`Resultbag ` to {func}`solve ` with `resultbag=`. On the first run, the call solves and stores all radius values. On a later run, the call solves and stores only project keys without matching resultbag entries. Matching entries are loaded from the resultbag. Set `recompute=True` to run a project solve again instead of reusing a matching resultbag entry. The {func}`solve ` call returns a {class}`BatchSolveResult `. The script selects the first postprocess, exports the data to xarray, and plots the real scattering cross section. ## Load Stored Results `run_load_results.py` opens the existing resultbag without running a project solve. The script reads the stored project keys and reconstructs the radii from the `radius` value in each set of project keys: ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/run_load_results.py :language: python :lines: 5-13 ``` {meth}`resultbag.get_results(keys=keys) ` loads the resultbag entries in the order of the stored project keys. The script selects the first postprocess, exports the data to xarray, and plots the real scattering cross section: ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/run_load_results.py :language: python ``` The script requires JCMsuite, an available license, and `matplotlib`. ## Project Files
run.py ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/run.py :language: python ```
run_load_results.py ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/run_load_results.py :language: python ```
layout.jcmt ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/layout.jcmt :language: jcm ```
materials.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/materials.jcm :language: jcm ```
mie2D.jcmp ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/mie2D.jcmp :language: jcm ```
sources.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/persistent_parameter_scan/sources.jcm :language: jcm ```
## Next Step Continue to [Resultbag](../resultbag/index.md) to query and manage stored results.