Explore different ways to run an OpenMC model, continue simulations, and retrieve tally results.
Ways to run and post-process
├── 0. Run from the command line
├── 1. Load and plot
├── 2. Restart / continue
├── 3. Run again with `apply_tally_results=True`
├── 4. Retrieve tallies without opening a `StatePoint`
└── 5. Post-process0. Run from the command line¶
The simulation can be run directly from the directory containing
model.xml, without rebuilding the model in Python:
OPENMC_CROSS_SECTIONS="/full/path/to/endf-b8.1/cross_sections.xml" openmcfrom pathlib import Path
import openmc
from openmc_workbench_config import DATA_ROOT
xs_xml = DATA_ROOT / 'endf-b8.1' / 'cross_sections.xml'
openmc.config['cross_sections'] = xs_xml1. Load and plot¶
# Load the model saved by 4_0_breeder_tritium_neutron_maps.ipynb, without
# rebuilding its materials, geometry, source, settings, or tallies.
openmc_model = openmc.Model.from_model_xml('output_0/model.xml')
R = 610
ax = openmc_model.plot(
basis='xy',
origin=(R / 2, R / 2, 0),
width=(R, R),
outline=True,
pixels=(600, 600),
)
2. Restart / continue¶
OpenMC’s restart capability is similar to MCNP’s CONTINUE. It resumes from a
saved statepoint and retains the accumulated tally statistics.
The run in 4_0_breeder_tritium_neutron_maps.ipynb uses a 1% relative-error
trigger for Li-7 (n,Xt) production. Here, we tighten the threshold by a
factor of 2 (to 0.5%) and restart from its statepoint.
# Tighten each relative-error trigger by a factor of 2.
for tally in openmc_model.tallies:
for trigger in tally.triggers:
if trigger.trigger_type == 'rel_err':
trigger.threshold /= 2
convergence_tally = next(
t for t in openmc_model.tallies
if t.name == 'Li7_(n,Xt)_convergence'
)dir_cont = Path('output_1')
dir_cont.mkdir(parents=True, exist_ok=True)
statepoint_files = list(Path('output_0').glob('statepoint.*.h5'))
assert statepoint_files, 'Run 4_0_breeder_tritium_neutron_maps.ipynb first to save a statepoint.'
sp_previous = max(statepoint_files, key=lambda p: p.stat().st_mtime)
with openmc.StatePoint(sp_previous, autolink=False) as sp:
completed_batches = sp.current_batch
assert any(
t.name == 'Li7_(n,Xt)_convergence'
for t in sp.tallies.values()
), 'Rerun 4_0_breeder_tritium_neutron_maps.ipynb with the Li-7 convergence tally first.'
# Keep the seed and the tightened trigger. Require at least 10 more
# batches, and increase the trigger maximum by 100.
settings = openmc_model.settings
settings.batches = completed_batches + 10
settings.trigger_max_batches += 100
settings.trigger_batch_interval = 10
openmc_model.run(
cwd=dir_cont,
restart_file=Path('..') / sp_previous,
) %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%%%%%%%%%
################## %%%%%%%%%%%%%%%%%%%%%%%
################### %%%%%%%%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%%%%%%
##################### %%%%%%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%
################# %%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%
############ %%%%%%%%%%%%%%%
######## %%%%%%%%%%%%%%
%%%%%%%%%%%
| The OpenMC Monte Carlo Code
Copyright | 2011-2026 MIT, UChicago Argonne LLC, and contributors
License | https://docs.openmc.org/en/latest/license.html
Version | 0.16.0
Commit Hash | 617d35a5063c57796b43428bc401e627d2011046
Date/Time | 2026-11-06 19:49:38
OpenMP Threads | 16
Reading model XML file 'model.xml' ...
Reading cross sections XML file...
Reading Pb204 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb204.h5
Reading Pb206 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb206.h5
Reading Pb207 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb207.h5
Reading Pb208 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb208.h5
Reading Li6 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Li6.h5
Reading Li7 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Li7.h5
Reading Cr50 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr50.h5
Reading Cr52 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr52.h5
Reading Cr53 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr53.h5
Reading Cr54 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr54.h5
Reading W180 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W180.h5
Reading W182 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W182.h5
Reading W183 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W183.h5
Reading W184 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W184.h5
Reading W186 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W186.h5
Reading Mn55 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Mn55.h5
Reading V50 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/V50.h5
Reading V51 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/V51.h5
Reading Ta180_m1 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ta180_m1.h5
Reading Ta181 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ta181.h5
Reading C12 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/C12.h5
Reading C13 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/C13.h5
Reading Ti46 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti46.h5
Reading Ti47 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti47.h5
Reading Ti48 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti48.h5
Reading Ti49 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti49.h5
Reading Ti50 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti50.h5
Reading N14 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/N14.h5
Reading N15 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/N15.h5
Reading Fe54 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe54.h5
Reading Fe56 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe56.h5
Reading Fe57 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe57.h5
Reading Fe58 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe58.h5
Minimum neutron data temperature: 294 K
Maximum neutron data temperature: 294 K
Preparing distributed cell instances...
Writing summary.h5 file...
Maximum neutron transport energy: 20000000 eV for Pb207
Loading state point ../output_0/statepoint.010.h5...
Resuming simulation...
===============> FIXED SOURCE TRANSPORT SIMULATION <===============
Simulating batch 11
Simulating batch 12
Simulating batch 13
Simulating batch 14
Simulating batch 15
Simulating batch 16
Simulating batch 17
Simulating batch 18
Simulating batch 19
Simulating batch 20
Triggers unsatisfied, max unc./thresh. is 1.3462663204335088 for (n,Xt) in
tally 2
Creating state point statepoint.020.h5...
Simulating batch 21
Simulating batch 22
Simulating batch 23
Simulating batch 24
Simulating batch 25
Simulating batch 26
Simulating batch 27
Simulating batch 28
Simulating batch 29
Simulating batch 30
Triggers unsatisfied, max unc./thresh. is 1.0100134329820314 for (n,Xt) in
tally 2
Simulating batch 31
Simulating batch 32
Simulating batch 33
Simulating batch 34
Simulating batch 35
Simulating batch 36
Simulating batch 37
Simulating batch 38
Simulating batch 39
Simulating batch 40
Triggers satisfied for batch 40
Creating state point statepoint.040.h5...
=======================> TIMING STATISTICS <=======================
Total time for initialization = 1.7341e+00 seconds
Reading cross sections = 1.7289e+00 seconds
Total time in simulation = 1.1998e+01 seconds
Time in transport only = 1.1989e+01 seconds
Time in active batches = 1.1998e+01 seconds
Time accumulating tallies = 5.3616e-03 seconds
Time writing statepoints = 3.6722e-03 seconds
Total time for finalization = 1.4806e-03 seconds
Total time elapsed = 1.3737e+01 seconds
Calculation Rate (active) = 8334.47 particles/second
============================> RESULTS <============================
Leakage Fraction = 0.05256 +/- 0.00041
PosixPath('/Users/marychin/Downloads/output_1/statepoint.040.h5')3. Run again with apply_tally_results=True¶
Use a different seed for an independent run. The tightened trigger
and increased minimum batch count from section 2 remain in effect.
OpenMC saves the tallies in the statepoint as usual and, with
apply_tally_results=True, also loads the results into the model’s
tally objects.
output_dir = Path('output_2')
output_dir.mkdir(exist_ok=True)
openmc_model.settings.seed = (openmc_model.settings.seed or 1) + 1
openmc_model.run(apply_tally_results=True, cwd=output_dir) %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%%%%%%%%%
################## %%%%%%%%%%%%%%%%%%%%%%%
################### %%%%%%%%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%%%%%%
##################### %%%%%%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%
################# %%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%
############ %%%%%%%%%%%%%%%
######## %%%%%%%%%%%%%%
%%%%%%%%%%%
| The OpenMC Monte Carlo Code
Copyright | 2011-2026 MIT, UChicago Argonne LLC, and contributors
License | https://docs.openmc.org/en/latest/license.html
Version | 0.16.0
Commit Hash | 617d35a5063c57796b43428bc401e627d2011046
Date/Time | 2026-11-06 19:49:52
OpenMP Threads | 16
Reading model XML file 'model.xml' ...
Reading cross sections XML file...
Reading Pb204 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb204.h5
Reading Pb206 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb206.h5
Reading Pb207 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb207.h5
Reading Pb208 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Pb208.h5
Reading Li6 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Li6.h5
Reading Li7 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Li7.h5
Reading Cr50 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr50.h5
Reading Cr52 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr52.h5
Reading Cr53 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr53.h5
Reading Cr54 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Cr54.h5
Reading W180 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W180.h5
Reading W182 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W182.h5
Reading W183 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W183.h5
Reading W184 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W184.h5
Reading W186 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/W186.h5
Reading Mn55 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Mn55.h5
Reading V50 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/V50.h5
Reading V51 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/V51.h5
Reading Ta180_m1 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ta180_m1.h5
Reading Ta181 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ta181.h5
Reading C12 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/C12.h5
Reading C13 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/C13.h5
Reading Ti46 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti46.h5
Reading Ti47 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti47.h5
Reading Ti48 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti48.h5
Reading Ti49 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti49.h5
Reading Ti50 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Ti50.h5
Reading N14 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/N14.h5
Reading N15 from /Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/N15.h5
Reading Fe54 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe54.h5
Reading Fe56 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe56.h5
Reading Fe57 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe57.h5
Reading Fe58 from
/Users/marychin/gitlabcode/power/data/endf-b8.1/neutron/Fe58.h5
Minimum neutron data temperature: 294 K
Maximum neutron data temperature: 294 K
Preparing distributed cell instances...
Writing summary.h5 file...
Maximum neutron transport energy: 20000000 eV for Pb207
===============> FIXED SOURCE TRANSPORT SIMULATION <===============
Simulating batch 1
Simulating batch 2
Simulating batch 3
Simulating batch 4
Simulating batch 5
Simulating batch 6
Simulating batch 7
Simulating batch 8
Simulating batch 9
Simulating batch 10
Simulating batch 11
Simulating batch 12
Simulating batch 13
Simulating batch 14
Simulating batch 15
Simulating batch 16
Simulating batch 17
Simulating batch 18
Simulating batch 19
Simulating batch 20
Triggers satisfied for batch 20
Creating state point statepoint.020.h5...
=======================> TIMING STATISTICS <=======================
Total time for initialization = 1.8584e+00 seconds
Reading cross sections = 1.8535e+00 seconds
Total time in simulation = 8.5954e+00 seconds
Time in transport only = 8.5895e+00 seconds
Time in active batches = 8.5954e+00 seconds
Time accumulating tallies = 3.5843e-03 seconds
Time writing statepoints = 2.1738e-03 seconds
Total time for finalization = 1.3318e-03 seconds
Total time elapsed = 1.0458e+01 seconds
Calculation Rate (active) = 23268.2 particles/second
============================> RESULTS <============================
Leakage Fraction = 0.05368 +/- 0.00059
PosixPath('/Users/marychin/Downloads/output_2/statepoint.020.h5')4. Retrieve tallies without opening a StatePoint¶
Create a dictionary of every tally in the model, indexed by name.
The results are already attached after apply_tally_results=True.
tallies = {t.name: t for t in openmc_model.tallies}
list(tallies)['(n,Xt)', 'Li7_(n,Xt)_convergence', 'fluence_r_E', 'fluence_n_Xt_r']5. Post-process¶
We can now proceed to the tally analysis in section 8 of
4_0_breeder_tritium_neutron_maps.ipynb, without opening the statepoint
explicitly. Only the first two cells are repeated here.
li7_rel_err = tallies['Li7_(n,Xt)_convergence'].get_values(
value='rel_err'
).item()
trigger_value = convergence_tally.triggers[0].threshold
print(f'Li-7 (n,Xt) relative error: {li7_rel_err:.3%}')
print(f'Convergence threshold: {trigger_value:.3%}')
Li-7 (n,Xt) relative error: 0.470%
Convergence threshold: 0.500%
tallies['(n,Xt)']Tally
ID = 1
Name = (n,Xt)
Filters = CellFilter
Nuclides = Pb204 Pb206 Pb207 Pb208 Li6 Li7 total
Scores = ['(n,Xt)']
Estimator = None
Multiply dens. = Truedf_n_Xt = tallies['(n,Xt)'].get_pandas_dataframe()
df_n_Xt['rel_err'] = df_n_Xt['std. dev.'] / df_n_Xt['mean'].abs()
df_n_Xt.sort_values('mean', ascending=False)