Delay Differential Equations (DDE)

ODE solver extension for models with delayed state feedback.

Class

class openpkpd.pk.ode.dde.DDESubroutine(n_compartments=10, rtol=1e-06, atol=1e-08, method='RK45')[source]

Bases: PKSubroutine

Generic DDE solver for PK/PD models with constant or parameter-dependent delays.

The delay value (τ) is read from pk_params as "TAU" or "DELAY". If neither is present, the solver degenerates to a plain ODE (τ = 0).

The history function is injected into pk_params under the key "_AHISTORY" before each call to des_callable, allowing the user’s $DES code to look up past compartment states.

Parameters

n_compartmentsint

Number of ODE compartments (default 10).

rtol, atolfloat

Tolerances for the underlying solve_ivp (RK45).

methodstr

scipy integration method (default "RK45").

advan: int = 16

ADVAN number (e.g., 1 for ADVAN1)

output_compartment: int = 1

Default output compartment (1-based)

__init__(n_compartments=10, rtol=1e-06, atol=1e-08, method='RK45')[source]
Parameters:
Return type:

None

n_compartments: int = 10

Number of compartments in this model

solve(pk_params, dose_events, obs_times, pk_callable=None, des_callable=None)[source]

Integrate the DDE system for a single subject.

The des_callable is called as:

dadt = des_callable(t, a_list, pk_params_with_history, [], [])

where pk_params_with_history is pk_params augmented with the key "_AHISTORY".

Return type:

PKSolution

Parameters:

Parameters

pk_params :

PK parameter dict (e.g., {"CL": 3.0, "V": 10.0, "TAU": 2.0}).

dose_events :

Dose events for this subject (bolus or infusion).

obs_times :

Observation times (unsorted is OK).

pk_callable :

Unused; included for interface compatibility.

des_callable :

REQUIRED compiled $DES callable with signature (t, A_list, pk_params, theta, eta) -> dAdt_list.

Returns

PKSolution

Raises

PKError

If des_callable is None or ODE integration fails.

Parameters:

Overview

DDESubroutine extends ADVAN6 to support delayed compartment values in the $DES right-hand side. The solver integrates piecewise using scipy’s solve_ivp with history interpolation.

from openpkpd.pk.ode.dde import DDESubroutine

dde = DDESubroutine(n_compartments=2, delay_params=["TAU"])

The $DES block may reference ALAG(n) or explicit delay parameters. See examples/16_dde_model.py for a full example.