CyRK.nb¶
Submodules¶
CyRK.nb.dop_coefficients module¶
CyRK.nb.nb_storage module¶
- class CyRK.nb.nb_storage.WrapNBRKResult(success, message, size, num_dy, num_y, error_code, y, t)¶
Bases:
tuple- error_code¶
Alias for field number 5
- message¶
Alias for field number 1
- num_dy¶
Alias for field number 3
- num_y¶
Alias for field number 4
- size¶
Alias for field number 2
- success¶
Alias for field number 0
- t¶
Alias for field number 7
- y¶
Alias for field number 6
CyRK.nb.nbrk module¶
- CyRK.nb.nbrk.nbsolve_ivp(diffeq: callable, t_span: Tuple[float, float], y0: ndarray, args: tuple = (), rtol: float = 0.001, atol: float = 1e-06, rtols: ndarray = array([], dtype=float64), atols: ndarray = array([], dtype=float64), max_step: float = inf, first_step: float = None, rk_method: int = 1, t_eval: ndarray = array([], dtype=float64), capture_extra: bool = False, interpolate_extra: bool = False, max_num_steps: int = 0, warnings: bool = True)[source]¶
A Numba-safe Runge-Kutta Integrator based on Scipy’s solve_ivp RK integrator [1], [2].
- Parameters:
diffeq (callable) – An njit-compiled function that defines the derivatives of the problem.
t_span (Tuple[float, float]) – A tuple of the beginning and end of the integration domain’s dependent variables.
y0 (np.ndarray) – 1D array of the initial values of the problem at t_span[0]
args (tuple = tuple()) – Any additional arguments that are passed to dffeq.
rtol (float = 1.e-3) – Integration relative tolerance used to determine optimal step size.
atol (float = 1.e-6) – Integration absolute tolerance used to determine optimal step size.
rtols (np.ndarray = EMPTY_ARR) – Array of relative tolerances (size of y0).
atols (np.ndarray = EMPTY_ARR) – Array of absolute tolerances (size of y0).
max_step (float = np.inf) – Maximum allowed step size.
first_step (float = None) – Initial step size. If None, then the function will attempt to determine an appropriate initial step.
rk_method (int = 1) –
- The type of RK method used for integration
0 = RK23 1 = RK45 2 = DOP853
t_eval (np.ndarray = None) –
- If provided, then the function will interpolate the integration results to provide them at the
requested t-steps.
capture_extra (bool = False) – If True, then extra output will be captured from the differential equation. See CyRK’s Documentation/Extra Output.md for more information
interpolate_extra (bool = False) –
- If True, then extra output will be interpolated (along with y) at t_eval. Otherwise, y will be interpolated
and then differential equation will be called to find the output at each t in t_eval.
max_num_steps (int = 0) – Maximum number of steps integrator is allowed to take. If set to 0 (the default) then an infinite number of steps are allowed.
warnings (bool = True) – If True, then warnings will be raised which can slow down integration.
References
- Returns:
time_domain (np.ndarray) – The final time domain. This is equal to t_eval if it was provided.
y_results (np.ndarray) –
- The solution of the differential equation provided for each time_result.
- If capture_extra was set to True then this will output both y and any extra parameters calculated by the
differential equation. The format of this output will look like:
y_results[0:y_size, :] = ... # Actual y-results calculated by the diffeq solver y_results[y_size:extra_size, :] = ... # Extra outputs captured alongside y during integration
success (bool) – Final integration success flag.
message (str) – Any integration messages, useful if success=False.
CyRK.nb.numba_c_api module¶
- CyRK.nb.numba_c_api.get_args_ptr_func_ptr()¶
- CyRK.nb.numba_c_api.get_args_size_func_ptr()¶
- CyRK.nb.numba_c_api.get_call_call_func_ptr()¶
- CyRK.nb.numba_c_api.get_call_call_vectorize_func_ptr()¶
- CyRK.nb.numba_c_api.get_capture_dense_func_ptr()¶
- CyRK.nb.numba_c_api.get_capture_extra_func_ptr()¶
- CyRK.nb.numba_c_api.get_direction_func_ptr()¶
- CyRK.nb.numba_c_api.get_dy_now_ptr_func_ptr()¶
- CyRK.nb.numba_c_api.get_free_func_ptr()¶
- CyRK.nb.numba_c_api.get_message_buffer_func_ptr()¶
- CyRK.nb.numba_c_api.get_method_func_ptr()¶
- CyRK.nb.numba_c_api.get_num_dy_func_ptr()¶
- CyRK.nb.numba_c_api.get_num_interpolates_func_ptr()¶
- CyRK.nb.numba_c_api.get_num_y_func_ptr()¶
- CyRK.nb.numba_c_api.get_size_func_ptr()¶
- CyRK.nb.numba_c_api.get_solve_func_ptr()¶
- CyRK.nb.numba_c_api.get_status_func_ptr()¶
- CyRK.nb.numba_c_api.get_status_message_buffer_func_ptr()¶
- CyRK.nb.numba_c_api.get_steps_taken_func_ptr()¶
- CyRK.nb.numba_c_api.get_success_func_ptr()¶
- CyRK.nb.numba_c_api.get_t_func_ptr()¶
- CyRK.nb.numba_c_api.get_t_now_func_ptr()¶
- CyRK.nb.numba_c_api.get_y_func_ptr()¶
- CyRK.nb.numba_c_api.get_y_now_ptr_func_ptr()¶
CyRK.nb.numba_solver module¶
- class CyRK.nb.numba_solver.NbCySolverResult(*args, **kwargs)[source]¶
Bases:
NbCySolverResultNumba-compatible wrapper for the C++ CySolverResult class.
- Parameters:
ptr (int) – Memory address of the underlying C++ CySolverResult instance.
- class_type = jitclass.NbCySolverResult#7e2e466c5b80<_ptr:int64>¶
- CyRK.nb.numba_solver.get_method_str(method_int: int)[source]¶
Map integration method integers to strings.
- Parameters:
method_int (int) – Integer identifier for the ODE method.
- Returns:
String name of the integration method.
- Return type:
str
- CyRK.nb.numba_solver.get_status_message_str(status_code: int)[source]¶
Numba-safe string extractor for C++ Error Code map.
- Parameters:
status_code (int) – The error code to look up.
- Returns:
The descriptive error message from the C++ backend.
- Return type:
str
- CyRK.nb.numba_solver.nb_diffeq_addr(diffeq_func)[source]¶
Compile a Python function to a C-callback and return its memory address.
- Parameters:
diffeq_func (callable) – The differential equation function to compile.
- Returns:
Memory address of the compiled C-callback.
- Return type:
int
- CyRK.nb.numba_solver.nbsolve2_ivp(diffeq_address: int64, t_span: Tuple[float, float], y0: ndarray, method: str = 'RK45', t_eval: ndarray | None = None, dense_output: bool = False, args: ndarray | None = None, rtol: float = 0.001, atol: float = 1e-06, rtols: ndarray | None = None, atols: ndarray | None = None, num_extra: int = 0, expected_size: int = 0, max_step: float = 18446744073709551615, first_step: float = 0.0, max_num_steps: int = 0, max_ram_MB: int = 2000, force_retain_solver: bool = True)[source]¶
Numba-compiled entry point for the C++ CyRK ODE solver.
- Parameters:
diffeq_address (int) – Memory address of the compiled differential equation C-callback.
t_span (tuple of float) – Interval of integration (t0, tf).
y0 (numpy.ndarray) – Initial state vector.
method (str, optional) – Integration method (‘RK45’, ‘RK23’, ‘DOP853’). Default is ‘RK45’.
t_eval (numpy.ndarray, optional) – Times at which to store the computed solution.
dense_output (bool, optional) – Whether to compute a continuous-time polynomial interpolation. Default is False.
args (numpy.ndarray, optional) – Additional arguments passed to the differential equation.
rtol (float, optional) – Relative and absolute tolerances.
atol (float, optional) – Relative and absolute tolerances.
rtols (numpy.ndarray, optional) – Vector-valued relative and absolute tolerances.
atols (numpy.ndarray, optional) – Vector-valued relative and absolute tolerances.
num_extra (int, optional) – Number of extra output variables computed by the diffeq.
expected_size (int, optional) – Estimated number of steps to pre-allocate memory.
max_step (float, optional) – Maximum allowed step size.
first_step (float, optional) – Initial step size guess.
max_num_steps (int, optional) – Maximum number of steps allowed before termination.
max_ram_MB (int, optional) – Maximum memory allowed for solution storage in Megabytes.
force_retain_solver (bool, optional) – Whether to keep the solver instance alive after integration.
- Returns:
A jitclass object containing the integration results and solution views.
- Return type:
- CyRK.nb.numba_solver.njit_test_nbsolve_ivp(diffeq_address: int64, t_span: Tuple[float, float], y0: ndarray, method: str = 'RK45', t_eval: ndarray | None = None, dense_output: bool = False, args: ndarray | None = None, rtol: float = 0.001, atol: float = 1e-06, rtols: ndarray | None = None, atols: ndarray | None = None, num_extra: int = 0, expected_size: int = 0, max_step: float = 18446744073709551615, first_step: float = 0.0, max_num_steps: int = 0, max_ram_MB: int = 2000, force_retain_solver: bool = True)[source]¶
Numba-compiled test wrapper to verify njit-to-njit call performance.
- Parameters:
nbsolve2_ivp] ([Parameters mirror)
- Returns:
Frees the result object internally after execution.
- Return type:
None
- CyRK.nb.numba_solver.test_nbsolve_ivp(diffeq: callable, t_span: Tuple[float, float], y0: ndarray, method: str = 'RK45', t_eval: ndarray = None, dense_output: bool = False, args: ndarray = None, rtol: float = 0.001, atol: float = 1e-06, rtols: ndarray = None, atols: ndarray = None, num_extra: int = 0, expected_size: int = 0, max_step: float = 18446744073709551615, first_step: float = 0.0, max_num_steps: int = 0, max_ram_MB: int = 2000, force_retain_solver: bool = True)[source]¶
Pure-Python test wrapper for the Numba solver.
- Parameters:
callable] ([Parameters mirror nbsolve2_ivp except diffeq is a)
- Returns:
Frees the result object internally after execution.
- Return type:
None