Python API¶
These entries are generated from public Python objects and their docstrings. The hand-written reference explains configuration choices and runtime behavior.
For constructor calls and working extension examples, see the plugin guide.
Package exports¶
Public package exports for polarism.
BoundaryCondition
¶
Config
dataclass
¶
Store the full simulation configuration.
AbstractSolver
¶
Bases: ABC
Define the interface for solver backends.
step(potential, pump, reservoir, boundary_condition, state)
abstractmethod
¶
Advance the fields from state.t to state.t + dt.
pump(t) returns the pump array at time t. Evaluate it at the
integration stage times; the caller updates state.t after the step.
advance(potential, pump, reservoir, boundary_condition, state, start_step, n_steps)
¶
Advance several steps, preserving controller stage times.
RK4CudaSolver
¶
Bases: AbstractSolver
Generic fused RK4 CUDA solver with overridable kernel and launch hooks.
LaserFactory
¶
Build laser objects from config data.
create_laser(laser_config, X, Y, precision='double')
staticmethod
¶
Create one or more lasers from the config.
RealTimeVisualization
¶
Plot fields and scalars during a run.
update(t, fields=None, scalars=None, scalar_groups=None)
¶
Update the plots with new fields and scalars.
ResultNode
¶
Describe one computed result.
compute_field_device(**context)
¶
Compute the field on the active backend without evaluating the scalar reduction.
compute_device(**context)
¶
Compute the field and reduced value on the active backend.
compute_cpu(**context)
¶
Compute the field and reduced value on the CPU.
compute_field_cpu(**context)
¶
Compute the field value on the CPU.
compute_reduced_cpu(**context)
¶
Compute the reduced value on the CPU.
ResultProvider
¶
Bases: ABC
Define the interface for result providers.
make_result_nodes()
abstractmethod
¶
Build the result nodes exposed by this object.
SimulationGrid2D
¶
Bases: Protocol
Protocol for 2D simulation grids.
SimulationState
¶
Store the wavefunction and current time.
At most one of _psi and psi_k is authoritative between step
boundaries. Both may coexist after materialization and until the next
mutation. A leading batch axis is supported when batch_size is given.
Results2D
dataclass
¶
Describe one 2D field view.
ResultScalar
dataclass
¶
Describe one scalar result.
ResultScalarGroup
dataclass
¶
Describe a grouped scalar result.
ResultsManager
¶
Send result nodes to each registered visitor.
Visitors that declare data_location = "device" receive backend-native
arrays without a CPU conversion. Each node is computed at most once per
:meth:step call regardless of how many visitors request it.
When a node is only requested by device visitors, the scalar reduction
(reduce_dim_fn) is skipped so GPU stream synchronisation is avoided.
Nodes also needed by CPU visitors always compute both field and reduction.
Visitor exceptions are isolated: a visitor that raises is disabled for the
rest of the run so that it cannot abort the simulation loop. Visitors that
expose an abort(exc) method have it called before being disabled.
StorageVisitor
¶
Bases: ResultVisitor
Write result nodes to storage backends.
VisualizationVisitor
¶
Bases: ResultVisitor
Send result nodes to the live visualizer.
ResultVisitor
¶
load_plugins(root=None)
¶
Import every module under <root>/polarism_plugins and return their names.
Plugin modules register their components with the usual registry
decorators (register_laser, register_potential, ...) on import.
root defaults to the current working directory.
Configuration dataclasses¶
Simulation config dataclasses.
GridParameters
dataclass
¶
Store grid size and box-length settings.
PhysicsConstants
dataclass
¶
Store the physics constants for the model.
BoundaryConditionParameters
dataclass
¶
Store boundary absorption settings.
PotentialParameters
dataclass
¶
Store potential settings.
LaserParameters
dataclass
¶
Store laser settings.
ReservoirParameters
dataclass
¶
Store reservoir settings.
SolverParameters
dataclass
¶
Store solver settings.
ResultParameters
dataclass
¶
Store result-output settings.
ComputeEngineParameters
dataclass
¶
Store backend settings.
Config
dataclass
¶
Store the full simulation configuration.
Controller and solver extension¶
Set up and run a full simulation.
run()
¶
Run the simulation loop.
Bases: ABC
Define the interface for solver backends.
step(potential, pump, reservoir, boundary_condition, state)
abstractmethod
¶
Advance the fields from state.t to state.t + dt.
pump(t) returns the pump array at time t. Evaluate it at the
integration stage times; the caller updates state.t after the step.
advance(potential, pump, reservoir, boundary_condition, state, start_step, n_steps)
¶
Advance several steps, preserving controller stage times.
Model component extension¶
The laser, reservoir, solver, grid, and absorption guides explain these bases and registration decorators in context.
Bases: ABC
Define the interface for reservoir models.
step(dt, psi_mid, pump)
abstractmethod
¶
Advance the reservoir by one time step.
get_reservoir_density()
abstractmethod
¶
Return the total reservoir density.
make_result_nodes()
abstractmethod
¶
Build the result nodes exposed by this object.
get_state()
abstractmethod
¶
Return the current state.
set_state(state)
abstractmethod
¶
Set the current state.
get_derivatives(psi, pump, state, rho=None)
abstractmethod
¶
Return the reservoir time derivatives.
get_active_density(state)
¶
Return the active reservoir density.
get_inactive_density(state)
¶
Return the inactive reservoir density, or zero if the model has none.
Batched state and reservoir API¶
SimulationState(grid, eps=1e-3, precision="double", *, mode="legacy_positive_uniform", k_cutoff_um=None, seed=None, batch_size=None) creates identical seeded initial fields along the batch axis. create_reservoir(reservoir_config, physics, grid, precision="double", *, batch_size=None) creates matching zero density fields. Built-in reservoirs support reset(batch_size=None) to clear and resize their density fields. See Batched simulations for a working pattern.