API
- class pydiffsol.InitialConditionSolverOptions
Bases:
object- armijo_constant
- max_linear_solver_setups
- max_linesearch_iterations
- max_newton_iterations
- step_reduction_factor
- use_linesearch
- class pydiffsol.MatrixType
Bases:
objectEnumerates the possible matrix types for diffsol
- Attr nalgebra_dense:
dense matrix using nalgebra crate (https://nalgebra.rs/)
- Attr faer_dense:
dense matrix using faer crate (https://faer.veganb.tw/)
- Attr faer_sparse:
sparse matrix using faer crate (https://faer.veganb.tw/)
- classmethod all()
Get all available matrix types :return: list of MatrixType
- classmethod from_str(name)
Create MatrixType from string name :param name: string representation of matrix type :return: valid MatrixType or exception if name is invalid
- faer_dense = MatrixType.faer_dense
- faer_sparse = MatrixType.faer_sparse
- nalgebra_dense = MatrixType.nalgebra_dense
- class pydiffsol.Ode(code, matrix_type=Ellipsis, scalar_type=Ellipsis, method=Ellipsis, linear_solver=Ellipsis)
Bases:
object- has_stop()
Check if the diffsl code has a stop event defined.
- rhs(params, t, y)
evaluate the right-hand side function at time t and state y.
- rhs_jac_mul(params, t, y, v)
evaluate the right-hand side Jacobian-vector product Jv` at time t and state y.
- solve(params, final_time, solution=None)
Using the provided state, solve the problem up to time final_time.
The number of params must match the expected params in the diffsl code.
- Parameters:
params (numpy.ndarray) – 1D array of solver parameters
final_time (float) – end time of solver
solution (Solution, optional) – optional existing solution object to continue from; if provided, it is consumed and the appended result is returned as a new Solution
- Returns:
Solution object with fields ys and ts
- Return type:
Example
>>> print(ode.solve(np.array([]), 0.5))
- solve_dense(params, t_eval, solution=None)
Using the provided state, solve the problem up to time t_eval[t_eval.len()-1]. Returns a Solution object with values at timepoints given by t_eval.
The number of params must match the expected params in the diffsl code.
- Parameters:
params (numpy.ndarray) – 1D array of solver parameters
t_eval – 1D array of solver times
solution (Solution, optional) – optional existing solution object to continue from; if provided, it is consumed and the appended result is returned as a new Solution
- Returns:
Solution object with fields ys and ts
- Return type:
- solve_fwd_sens(params, t_eval, solution=None)
Using the provided state, solve the problem up to time t_eval[t_eval.len()-1]. Returns a Solution object with values at t_eval and sensitivity arrays at the same timepoints. The number of params must match the expected params in the diffsl code.
- Parameters:
params (numpy.ndarray) – 1D array of solver parameters
t_eval – 1D array of solver times
solution (Solution, optional) – optional existing solution object to continue from; if provided, it is consumed and the appended result is returned as a new Solution
- Returns:
Solution object with fields ys, ts, and sens
- Return type:
- solve_sum_squares_adj(params, data, t_eval)
Using the provided state, solve the adjoint problem for the sum of squares objective given data at timepoints t_eval. Returns the objective value and a list of 1D arrays of adjoint sensitivities for each parameter.
- y0(params)
Get the initial condition vector y0 as a 1D numpy array.
- atol
Absolute tolerance for the solver, default 1e-6. Governs the error as the solution goes to zero.
- code
Get the DiffSl compiled to generate this ODE
- ic_options
- linear_solver
Linear solver type used in the ODE solver. Set to default to use the solver’s default choice, which is typically an LU solver.
- matrix_type
Matrix type used in the ODE solver. This is fixed after construction.
- method
Ode solver method, default Bdf (backward differentiation formula).
- nout
Get the number of outputs in the ODE system, if there is no out tensor, this is the number of states.
- nparams
Get the number of parameters expected by the diffsl code.
- nstates
Get the number of states in the ODE system.
- options
- rtol
Relative tolerance for the solver, default 1e-6. Governs the error relative to the solution size.
- class pydiffsol.OdeSolverOptions
Bases:
object- max_error_test_failures
- max_nonlinear_solver_iterations
- min_timestep
- threshold_to_update_jacobian
- threshold_to_update_rhs_jacobian
- update_jacobian_after_steps
- update_rhs_jacobian_after_steps
- class pydiffsol.ScalarType
Bases:
object- classmethod all()
Get all available data types :return: list of ScalarType
- classmethod from_str(name)
Create ScalarType from string name :param name: string representation of data type :return: valid ScalarType or exception if name is invalid
- f32 = ScalarType.f32
- f64 = ScalarType.f64
- class pydiffsol.SolverMethod
Bases:
objectEnumerates the possible ODE solver methods for diffsol. See the solver descriptions in the diffsol documentation (https://github.com/martinjrobins/diffsol) for more details.
- Attr bdf:
Backward Differentiation Formula (BDF) method for stiff ODEs and singular mass matrices
- Attr esdirk34:
Explicit Singly Diagonally Implicit Runge-Kutta (ESDIRK) method for moderately stiff ODEs and singular mass matrices.
- Attr tr_bdf2:
Trapezoidal Backward Differentiation Formula of order 2 (TR-BDF2) method for moderately stiff ODEs and singular mass matrices.
- Attr tsit45:
Tsitouras 4/5th order Explicit Runge-Kutta (TSIT45) method for non-stiff ODEs. This is an explicit method, it cannot handle singular mass matrices and does not require a linear solver.
- classmethod all()
- classmethod from_str(value)
- bdf = SolverMethod.bdf
- esdirk34 = SolverMethod.esdirk34
- tr_bdf2 = SolverMethod.tr_bdf2
- tsit45 = SolverMethod.tsit45
- class pydiffsol.SolverType
Bases:
objectEnumerates the possible linear solver types for diffsol
- Attr default:
use the solver’s default linear solver choice, typically LU
- Attr lu:
use LU decomposition linear solver (dense or sparse as appropriate)
- Attr klu:
use KLU sparse linear solver
- classmethod all()
- classmethod from_str(value)
- default = SolverType.default
- klu = SolverType.klu
- lu = SolverType.lu
- pydiffsol.is_klu_available()
Inidicate whether Klu functions are available. This depends on whether the library was built with suitesparse support.
- pydiffsol.version()
Get version of this pydiffsol module