reactor_class¶
fusdb.reactor_class
Reactor class for loading and solving fusion reactor design specifications.
This module provides the Reactor class which loads reactor specifications from YAML files, manages variables, filters applicable relations, and orchestrates the solving process.
Reactor
dataclass
¶
Container for fusion reactor specifications, variables, and solving logic.
A Reactor represents a fusion reactor design with its parameters (geometry, plasma properties, etc.) and the physics relations that govern it. The class can load a configuration (currently from YAML), filter applicable relations based on tags, and solve for unknown variables.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path | None
|
Path to the source reactor file. |
id |
str | None
|
Unique reactor identifier (e.g., "ARC_2015", "DEMO_2022"). |
name |
str | None
|
Reactor name. |
organization |
str | None
|
Organization (industrial or academic) developing the reactor. |
country |
str | None
|
Country where reactor is being developed/built. |
year |
int | None
|
Design year. |
doi |
str | None
|
DOI reference to published design. |
notes |
str | None
|
Additional notes. |
tags |
list[str]
|
Classification tags (e.g., "tokamak", "hmode",...). Used for relations filtering. |
solving_order |
list[str]
|
Ordered domains/relations to solve (e.g., ["geometry", "fusion_power"]). |
solver_mode |
str
|
How to handle computed vs input values: - "overwrite": Replace input values with computed (default) - "check": Only check consistency, don't modify |
verbose |
bool
|
Enable detailed solver logging. |
relations |
list[Relation]
|
Filtered list of applicable relations for this reactor. |
variables_dict |
dict[str, Variable]
|
Dictionary of Variable objects keyed by name. |
from_yaml
classmethod
¶
from_yaml(path_like: str | Path) -> 'Reactor'
Create a Reactor object from a YAML file.
Parses the YAML file containing reactor metadata, tags, variables, and solver settings. Automatically filters relations based on tags and creates a fully initialized Reactor object ready for solving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_like
|
str | Path
|
Path to reactor.yaml file or directory containing it. |
required |
Returns:
| Type | Description |
|---|---|
'Reactor'
|
Reactor object with variables and relations loaded. |
Example
reactor = Reactor.from_yaml('reactors/ARC_2015/reactor.yaml') reactor.solve()
solve ¶
solve(mode: str | None = None, *, verbose: bool | None = None, enforce_constraint_tags: Iterable[str] | None = None, enforce_constraint_names: Iterable[str] | None = None) -> None
Solve for unknown reactor variables using physics relations.
Executes the iterative solver to compute unknown variables from known ones. If solving_order is specified, solves each domain in sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str | None
|
Override solver mode ("overwrite" or "check"). If None, uses self.solver_mode. |
None
|
verbose
|
bool | None
|
Override verbosity setting. If None, uses self.verbose. |
None
|
enforce_constraint_tags
|
Iterable[str] | None
|
Relation tags whose soft constraints should be enforced. |
None
|
enforce_constraint_names
|
Iterable[str] | None
|
Relation names/outputs or variable names whose soft constraints should be enforced. |
None
|
Example: >>> reactor = Reactor.from_yaml('reactors/ARC_2015/reactor.yaml') >>> reactor.solve(verbose=True) # Show detailed solving progress
diagnose ¶
diagnose() -> dict[str, object]
Run comprehensive diagnostics on reactor consistency.
Checks all applicable relations to see which are violated and identifies likely culprit variables causing inconsistencies. Useful for debugging reactor specifications.
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Dictionary containing: |
dict[str, object]
|
|
dict[str, object]
|
|
dict[str, object]
|
|
Example
reactor = Reactor.from_yaml('reactors/ARC_2015/reactor.yaml') diag = reactor.diagnose() print(f"Violated: {len(diag['violated_relations'])} relations")
popcon ¶
popcon(scan_axes: dict[str, Sequence[float]], *, outputs: Iterable[str] | None = None, constraints: Iterable[str] | None = None, constraint_tags: Iterable[str] | None = ('constraint',), exclude_constraints: Iterable[str] | None = None, where: dict[str, tuple[float | None, float | None]] | None = None, chunk_size: int | None = None) -> dict[str, object]
Evaluate a POPCON-style scan over one or more axes.
This method always uses the dense matrix path of RelationSystem.evaluate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_axes
|
dict[str, Sequence[float]]
|
Mapping of variable name -> 1D sequence of scan values. |
required |
outputs
|
Iterable[str] | None
|
Optional output variable names to return. |
None
|
constraints
|
Iterable[str] | None
|
Explicit constraint relation names/outputs. |
None
|
constraint_tags
|
Iterable[str] | None
|
Relation tags used to auto-select constraints. |
('constraint',)
|
exclude_constraints
|
Iterable[str] | None
|
Relation names/outputs to exclude. |
None
|
where
|
dict[str, tuple[float | None, float | None]] | None
|
Optional thresholds {name: (min, max)}. |
None
|
chunk_size
|
int | None
|
Optional row-chunk size passed to |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Dict with axes, outputs, margins, allowed mask, and diagnostics. |
plot_popcon ¶
plot_popcon(result: dict[str, object], *, x: str, y: str, fill: str, contours: list[str] | None = None, contour_levels: dict[str, list[float]] | None = None, contour_counts: dict[str, int] | None = None, constraint_contours: bool = True, slice: dict[str, int | float] | None = None, reduce: dict[str, str] | None = None, best: dict[str, str] | None = None, ax=None)
Plot POPCON results with masked fill and contour overlays.
__repr__ ¶
__repr__() -> str
Return a string representation of the reactor for display.
Shows the reactor name, ID, and key metadata in a readable format.
plot_cross_sections ¶
plot_cross_sections(*, ax=None, label: str | None = None)
Plot plasma cross-section using 95% flux surface geometry.