BaseODE
- class cubie.odesystems.BaseODE(precision: type[float16] | type[float32] | type[float64] | dtype[float16] | dtype[float32] | dtype[float64] = <class 'numpy.float32'>, initial_values: Dict[str, float] | None=None, parameters: Dict[str, float] | None=None, constants: Dict[str, float] | None=None, observables: Dict[str, float] | None=None, default_initial_values: Dict[str, float] | None=None, default_parameters: Dict[str, float] | None=None, default_constants: Dict[str, float] | None=None, default_observable_names: Dict[str, float] | None=None, num_drivers: int = 1, name: str | None = None)[source]
Bases:
CUDAFactoryAbstract base for CUDA-backed ordinary differential equation systems.
Subclasses override
build()to compile a CUDA device function that advances the system state and, optionally, provide analytic helpers viaget_solver_helper(). The base class handles value management, precision selection, and caching throughCUDAFactory.Notes
Only functions cached during
build()(typicallydxdt) are available on this base class. Solver helper functions such as the linear operator or preconditioner are generated only by subclasses likeSymbolicODE.- __init__(precision: type[float16] | type[float32] | type[float64] | dtype[float16] | dtype[float32] | dtype[float64] = <class 'numpy.float32'>, initial_values: Dict[str, float] | None=None, parameters: Dict[str, float] | None=None, constants: Dict[str, float] | None=None, observables: Dict[str, float] | None=None, default_initial_values: Dict[str, float] | None=None, default_parameters: Dict[str, float] | None=None, default_constants: Dict[str, float] | None=None, default_observable_names: Dict[str, float] | None=None, num_drivers: int = 1, name: str | None = None) None[source]
Initialize the ODE system.
- Parameters:
initial_values – Initial values for state variables.
parameters – Parameter values for the system.
constants – Constants that are not expected to change between simulations.
observables – Observable values to track.
default_initial_values – Default initial values if
initial_valuesomits entries.default_parameters – Default parameter values if
parametersomits entries.default_constants – Default constant values if
constantsomits entries.default_observable_names – Default observable names if
observablesomits entries.precision – Precision factory used for calculations. Defaults to
numpy.float64.num_drivers – Number of driver or forcing functions. Defaults to
1.name – Printable identifier for the system. Defaults to
None.
Notes
‘Precision’ is the root for all other precisions in the package. If left unset, it will make everything float32.
- abstractmethod build() ODECache[source]
Compile the
dxdtsystem as a CUDA device function.- Returns:
Cache containing the built
dxdtfunction. Subclasses may add further solver helpers to this cache as needed.- Return type:
Notes
Bring constants into local (outer) scope before defining
dxdtbecause CUDA device functions cannot referenceself.
- property config_hash
Override the config hash fetcher to add and hash the current constant values. When labels change, we need to re-codegen, but when values change, we need to rebuild.
- property constants
Constant values configured for the system.
- correct_answer_python(states: ndarray[Any, dtype[floating[Any]]], parameters: ndarray[Any, dtype[floating[Any]]], drivers: ndarray[Any, dtype[floating[Any]]]) Tuple[ndarray[Any, dtype[floating[Any]]], ndarray[Any, dtype[floating[Any]]]][source]
Python reference
dxdtfor testing.- Parameters:
states – Current state values.
parameters – Parameter values.
drivers – Driver or forcing values.
- Returns:
Tuple containing the state derivatives and observable outputs.
- Return type:
- property evaluate_f
Compiled CUDA device function for evaluating f(t, y).
- property evaluate_observables: Callable
Return the compiled observables device function.
- Returns:
CUDA device function that computes observables without updating the derivative buffer.
- Return type:
Callable
- get_solver_helper(func_name: str, beta: float = 1.0, gamma: float = 1.0, mass: Any = 1.0, preconditioner_order: int = 0) Callable[source]
Retrieve a cached solver helper function.
- Parameters:
func_name – Identifier for the helper function.
beta – Shift parameter for the linear operator. Defaults to
1.0.gamma – Weight of the Jacobian term in the linear operator. Defaults to
1.0.preconditioner_order – Polynomial order of the preconditioner. Defaults to
0. Unused when generating the linear operator.mass – Mass matrix used by the linear operator. Defaults to identity.
- Returns:
Cached device function corresponding to
func_name.- Return type:
Callable
Notes
Returns
NotImplementedErrorif theODESystemlacks generated code for the requested helper.
- property observables
Observable definitions configured for the system.
- property parameters
Parameter values configured for the system.
- set_constants(updates_dict: Dict[str, float] | None = None, silent: bool = False, **kwargs: float) Set[str][source]
Update constant values in the system.
- Parameters:
updates_dict – Mapping from constant names to their new values.
silent – Set to
Trueto suppress warnings about missing keys.**kwargs – Additional constant updates provided as keyword arguments. These override entries in
updates_dict.
- Returns:
Labels that were recognized and updated.
- Return type:
- property sizes
System component sizes cached for solvers.
- property states
Initial state values configured for the system.
- update(updates_dict: Dict[str, float] | None, silent: bool = False, **kwargs: float) Set[str][source]
Update compile settings through the
CUDAFactoryinterface.Pass updates through the compile-settings interface, which invalidates caches when an update succeeds.
- Parameters:
updates_dict – Dictionary of updates to apply.
silent – Set to
Trueto suppress warnings about missing keys.**kwargs – Additional updates specified as keyword arguments.
- Returns:
Labels that were recognized and updated.
- Return type:
Notes
Pass
silent=Truewhen performing bulk updates that may include values for other components to suppress warnings about missing keys.