cubie.systemmodels.systems.GenericODE
- class cubie.systemmodels.systems.GenericODE(initial_values=None, parameters=None, constants=None, observables=None, default_initial_values=None, default_parameters=None, default_constants=None, default_observable_names=None, precision=<class 'numpy.float64'>, num_drivers=1, **kwargs)[source]
Bases:
CUDAFactory
Template class for a system of ODEs.
This class is designed to be subclassed for specific systems so that the shared machinery used to interface with CUDA can be reused. When subclassing, you should overload the build() and correct_answer_python() methods to provide the specific ODE system you want to simulate.
- Parameters:
initial_values (dict, optional) – Initial values for state variables.
parameters (dict, optional) – Parameter values for the system.
constants (dict, optional) – Constants that are not expected to change between simulations.
observables (dict, optional) – Observable values to track.
default_initial_values (dict, optional) – Default initial values if not provided in initial_values.
default_parameters (dict, optional) – Default parameter values if not provided in parameters.
default_constants (dict, optional) – Default constant values if not provided in constants.
default_observable_names (dict, optional) – Default observable names if not provided in observables.
precision (numpy.dtype, optional) – Precision to use for calculations, by default np.float64.
num_drivers (int, optional) – Number of driver/forcing functions, by default 1.
**kwargs (dict) – Additional arguments.
Notes
If you do implement a correct_answer_python() method, then you can subclass the SystemTester class in tests/systemmodels/SystemTester.py and overload system_class with your ODE class name. The generate_system_tests function can then generate a set of floating-point and missing-input tests to see if your system behaves as expected.
Most systems will contain a default set of initial values, parameters, constants, and observables. This parent class does not contain them, but instead can be instantiated with a set of values of any size, for testing purposes. The default values provide a way to both set a default state and to provide the set of modifiable entries. This means that a user can’t add in a state or parameter when solving the system that ends up having no effect on the system.
- __init__(initial_values=None, parameters=None, constants=None, observables=None, default_initial_values=None, default_parameters=None, default_constants=None, default_observable_names=None, precision=<class 'numpy.float64'>, num_drivers=1, **kwargs)[source]
Initialize the ODE system.
- Parameters:
initial_values (dict, optional) – Initial values for state variables.
parameters (dict, optional) – Parameter values for the system.
constants (dict, optional) – Constants that are not expected to change between simulations.
observables (dict, optional) – Observable values to track.
default_initial_values (dict, optional) – Default initial values if not provided in initial_values.
default_parameters (dict, optional) – Default parameter values if not provided in parameters.
default_constants (dict, optional) – Default constant values if not provided in constants.
default_observable_names (dict, optional) – Default observable names if not provided in observables.
precision (numpy.dtype, optional) – Precision to use for calculations, by default np.float64.
num_drivers (int, optional) – Number of driver/forcing functions, by default 1.
**kwargs (dict) – Additional arguments.
Methods
__init__
([initial_values, parameters, ...])Initialize the ODE system.
build
()Compile the dxdt system as a CUDA device function.
correct_answer_python
(states, parameters, ...)Python version of the dxdt function for testing.
get_cached_output
(output_name)Return a named cached output.
set_constants
([updates_dict, silent])Update the constants of the system.
setup_compile_settings
(compile_settings)Attach a container of compile-critical settings to the object.
update
(updates_dict[, silent])Update compile settings through the CUDAFactory interface.
update_compile_settings
([updates_dict, silent])Update compile settings with new values.
Attributes
cache_valid
True
if cached outputs are up to date.compile_settings
Return the current compile settings object.
contants
Get the constants of the system.
device_function
Return the compiled CUDA device function.
dxdt_function
Get the compiled device function.
initial_values
Get the initial values of the system.
num_constants
Get the number of constants.
num_drivers
Get the number of driver variables.
num_observables
Get the number of observable variables.
num_parameters
Get the number of parameters.
num_states
Get the number of state variables.
observables
Get the observables of the system.
parameters
Get the parameters of the system.
precision
Get the precision of the system.
sizes
Get system sizes.
- __init__(initial_values=None, parameters=None, constants=None, observables=None, default_initial_values=None, default_parameters=None, default_constants=None, default_observable_names=None, precision=<class 'numpy.float64'>, num_drivers=1, **kwargs)[source]
Initialize the ODE system.
- Parameters:
initial_values (dict, optional) – Initial values for state variables.
parameters (dict, optional) – Parameter values for the system.
constants (dict, optional) – Constants that are not expected to change between simulations.
observables (dict, optional) – Observable values to track.
default_initial_values (dict, optional) – Default initial values if not provided in initial_values.
default_parameters (dict, optional) – Default parameter values if not provided in parameters.
default_constants (dict, optional) – Default constant values if not provided in constants.
default_observable_names (dict, optional) – Default observable names if not provided in observables.
precision (numpy.dtype, optional) – Precision to use for calculations, by default np.float64.
num_drivers (int, optional) – Number of driver/forcing functions, by default 1.
**kwargs (dict) – Additional arguments.
- build()[source]
Compile the dxdt system as a CUDA device function.
- Returns:
Compiled CUDA device function for the ODE system.
- Return type:
function
Notes
Assign dxdt contents into local scope by assigning before you define the dxdt function, as the CUDA device function can’t handle a reference to self.
- property contants
Get the constants of the system.
- Returns:
The constants of the system.
- Return type:
- correct_answer_python(states, parameters, drivers)[source]
Python version of the dxdt function for testing.
This function is used in testing. Overload this with a simpler, Python version of the dxdt function. This will be run in a python test to compare the output of your CUDA function with this known, correct answer.
- Parameters:
states (numpy.ndarray) – Current state values.
parameters (numpy.ndarray) – Parameter values.
drivers (numpy.ndarray) – Driver/forcing values.
- Returns:
A tuple containing (dxdt, observables) arrays.
- Return type:
- property dxdt_function
Get the compiled device function.
- Returns:
The compiled CUDA device function.
- Return type:
function
- property initial_values
Get the initial values of the system.
- Returns:
The initial values of the system.
- Return type:
- property num_drivers
Get the number of driver variables.
- Returns:
Number of driver variables.
- Return type:
- property num_observables
Get the number of observable variables.
- Returns:
Number of observable variables.
- Return type:
- property num_parameters
Get the number of parameters.
- Returns:
Number of parameters.
- Return type:
- property num_states
Get the number of state variables.
- Returns:
Number of state variables.
- Return type:
- property observables
Get the observables of the system.
- Returns:
The observables of the system.
- Return type:
- property parameters
Get the parameters of the system.
- Returns:
The parameters of the system.
- Return type:
- property precision
Get the precision of the system.
- Returns:
The precision of the system (numba type, float32 or float64).
- Return type:
- set_constants(updates_dict=None, silent=False, **kwargs)[source]
Update the constants of the system. Does not relabel parameters to constants, just updates values already compiled as constants and forces a rebuild with new compile-time constants.
- Parameters:
updates_dict (dict) – A dictionary of constant names and their
values. (new)
- property sizes
Get system sizes.
- Returns:
Dictionary of sizes (number of states, parameters, observables, constants, drivers) for the system.
- Return type:
- update(updates_dict, silent=False, **kwargs)[source]
Update compile settings through the CUDAFactory interface.
Pass updates to compile settings through the CUDAFactory interface, which will invalidate cache if an update is successful.
- Parameters:
Notes
Pass silent=True if doing a bulk update with other component’s params to suppress warnings about keys not found.