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: object

Enumerates 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

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)

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. If specified, the config can be used to override the solver method (Bdf by default) and SolverType (Lu by default) along with other solver params like rtol.

Parameters:
  • params (numpy.ndarray) – 1D array of solver parameters

  • final_time (float) – end time of solver

Returns:

(ys, ts) tuple where ys is a 2D array of values at times ts chosen by the solver

Return type:

Tuple[numpy.ndarray, numpy.ndarray]

Example

>>> print(ode.solve(np.array([]), 0.5))
solve_dense(params, t_eval)

Using the provided state, solve the problem up to time t_eval[t_eval.len()-1]. Returns 2D array of solution values at timepoints given by t_eval.

The number of params must match the expected params in the diffsl code. The config may be optionally specified to override solver settings.

Parameters:
  • params (numpy.ndarray) – 1D array of solver parameters

  • t_eval – 1D array of solver times

Returns:

2D array of values at times t_eval

Return type:

numpy.ndarray

solve_fwd_sens(params, t_eval)

Using the provided state, solve the problem up to time t_eval[t_eval.len()-1]. Returns 2D array of solution values at timepoints given by t_eval. Also returns a list of 2D arrays of sensitivities at the same timepoints as the solution. The number of params must match the expected params in the diffsl code. The config may be optionally specified to override solver settings. :param params: 1D array of solver parameters :type params: numpy.ndarray :param t_eval: 1D array of solver times :type params: numpy.ndarray :return: 2D array of values at times t_eval and a list of 2D arrays of sensitivities at the same timepoints :rtype: (numpy.ndarray, List[numpy.ndarray])

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).

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: object

Enumerates 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: object

Enumerates 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