Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Python

Install with python -m pip install actinv, then install the data from your working folder with actinv data fetch. Python calls the same Rust solver as the CLI.

Construct a problem

from actinv import Material, Problem, Schedule, solve

problem = Problem.example()
problem["material"] = Material({"Fe": 100.0}, mass_g=10.0)
problem["schedule"] = Schedule().irradiate("5 min").cool("1 h")
problem.save("iron.json")

result = solve(problem)
print(result.heat())         # List of (seconds, W/g) pairs.
print(result.activity())     # List of (seconds, total Bq/g) pairs.
print(result.activity("Mn56"))
result.save("iron-result.json")

The example includes the iron spectrum and data references. Material keeps the declared composition basis; it does not silently convert weight percentages to fractions. Schedule methods return the same schedule for chaining. Use Spectrum when supplying your own group-integrated flux vector.

mass_g=10.0 does not change the unit returned by heat(): multiply W/g by ten to obtain this sample’s total watts.

Load an existing problem

from pathlib import Path
from actinv import Problem, solve

problem = Problem.from_file("iron.json")
result = solve(problem)
# You can also use: result = solve(Path("iron.json"))
print(result.steps[-1]["heat_W_per_g"]["total"])
print(result.ledger)

Problem.from_file resolves literal relative data references against the file’s directory. Supply base= when an older problem expects a different base folder. Plain dictionaries use the current working directory. Catalog references use ACTINV_DATA_DIR or ./actinv-data.

Result is a mapping: every result field remains accessible by key. Its helpers select existing data and preserve the reported units.

Use the JSON interface

import json
from pathlib import Path
import actinv

text = Path("problem.json").read_text(encoding="utf-8")
print(actinv.validate(text))
result = json.loads(actinv.run(text))
print(result["steps"][-1]["heat_W_per_g"]["total"])

run and its alias run_json accept JSON text and return JSON text. Literal paths in this interface use the current directory. solve returns a Result object instead.

Optional features

Set the corresponding problem blocks to request uncertainty, photon responses, radiological indices, damage, or self-shielding. Continuous feed and removal can be attached to schedule steps:

problem["schedule"] = (
    Schedule()
    .irradiate("5 min", feed={"Co60": 1e12}, removal={"Mn56": 1e-3})
    .cool("1 h")
)

Feed units are atoms s⁻¹ g⁻¹ and removal units are s⁻¹. Other helpers include reverse, decide, and optimize; 1.4.0 adds actinv.budget(budget, *, base_dir=None, verify=True). Their options after the first arguments are keyword-only, for example actinv.decide(decision, base_dir="case") and actinv.optimize(path, outdir="out", resume=True). A failed budget verification is returned in the document rather than raised as an exception. See the Python package reference, Advanced workflows.

Waste classification from Python

The waste commands and the facility twin are available as functions. Each runs the command line’s own code, so the result is the document the CLI would write.

PythonCLI
actinv.waste.classify(spec)actinv waste SPEC
actinv.waste.budget(spec)actinv waste budget SPEC
actinv.waste.bounds(spec)actinv waste bounds SPEC
actinv.waste.composition(spec)actinv waste composition SPEC
actinv.waste.composition_solve(spec)actinv waste composition solve SPEC
actinv.waste.intrusion_screen(spec)actinv waste intrusion-screen SPEC
actinv.waste.uncertainty(spec)actinv waste uncertainty SPEC
actinv.waste.budget_uncertainty(spec)actinv waste budget uncertainty SPEC
actinv.waste.package(spec)actinv waste package SPEC
actinv.twin(spec)actinv twin SPEC

spec is a path, or a dictionary together with base_dir, the folder its relative paths resolve against (default: the current directory). A path is used as it is, and relative paths inside the file resolve against the file’s folder. A dictionary is written to a temporary file in base_dir for the duration of the call and removed afterwards, also on error. Each call returns the result as a dictionary, or with text=True the exact JSON text the CLI writes to an output file. A refusal raises ValueError with the CLI’s message. Calls print nothing; actinv waste composition also prints an intermediate bounds report to standard output, which actinv.waste.composition leaves out (the result is the same). actinv.waste.budget is actinv waste budget (impurity limits for a requested class); the impurity budget actinv.budget is unchanged.

import json
from pathlib import Path
import actinv

result = actinv.waste.classify("component.json")
for row in actinv.waste.summary(result):
    print(row["component"], row["step"], row["class"], row["binding_table"], row["binding_nuclides"])

spec = json.loads(Path("case/bounds.json").read_text(encoding="utf-8"))
bounds = actinv.waste.bounds(spec, base_dir="case")

actinv.waste.summary(result) takes a classification result (also the classification member of an intrusion-screen result, or a twin’s waste_classification) and returns one flat dictionary per component and target step: class, status, coverage, the governing table, column and margin, and the binding nuclides. It reads the result and computes nothing new. The scope is that of Component waste classes: nominal screening, not disposal acceptance or intrusion dose.