Simulator

class Simulator(patient: Patient | None = None, random_generation_arg: dict | None = None, tci_propo: str | None = None, tci_remi: str | None = None, tci_nore: bool | None = None, tci_atra: bool | None = None, disturbance_profil: str | None = None, noise: bool = False, bis_delay_max: float = 120, save_signals: bool = True, arg_disturbance: dict | None = None, arg_tci_propo: dict | None = None, arg_tci_remi: dict | None = None, arg_tci_nore: dict | None = None, arg_tci_atra: dict | None = None)

Bases: object

Class to add environment and usefull functions for simulation.

Parameters:
patient: Patient, optional

The virtual patient object. If None a random patient is generaed with random_generation_arg parameters.

random_generation_arg: dict, optional

Argument to pass to generate_random_patient_method. The default is empty.

tci_propo: str, optional

Type of TCI for Propofol. Can be either ‘Plasma’, ‘Effect_site’ or ‘none’. Defaults to ‘none’.

tci_remi: str, optional

Type of TCI for Remifentanil. Can be either ‘Plasma’, ‘Effect_site’ or ‘none’. Defaults to ‘none’.

disturbance_profil: str, optional

Type of disturbance profile to apply. See disturbance module for more details. The default is None.

noise: bool, optional

If True, add noise to the outputs of the patient model. The default is False.

save_signalsbool, optional

Save all internal variables at each sampling time in a data frame. The default is True.

bis_delay_maxfloat, optional

Maximum value of the BIS delay caused by Signal Quality Index (SQI) expressed in (s) according to the relationship proposed in [Wahlquist2025]. The default is 120 (s).

arg_disturbance: dict, optional

Additional argument to pass to the function compute_disturbances. The default is empty.

arg_tci_propo: dict, optional

Additional argument to pass to tci class initialization for propofol. The default is empty.

arg_tci_remi: dict, optional

Additional argument to pass to tci class initialization for remifentanil. The default is empty.

arg_tci_nore: dict, optional

Additional argument to pass to tci class initialization for norepinephrine. The default is empty.

arg_tci_atra: dict, optional

Additional argument to pass to tci class initialization for atracurium. The default is empty.

References

[Wahlquist2025]

Y. Wahlquist, et al. “Kalman filter soft sensor to handle signal quality loss in closed-loop controlled anesthesia” Biomedical Signal Processing and Control 104 (2025): 107506. doi: https://doi.org/10.1016/j.bspc.2025.107506

add_noise()

Add noise on MAP, HR and BIS.

All noise are considered white noise filtered by a second order transfert function:

  • For MAP, the standard deviation of the white noise is 30 and the filter is a second-order low-pass noise filter with damping ratio ξ=2 and cutoff frequency ω=0.01.

  • For HR, the standard deviation of the white noise is 17 and the filter is a second-order low-pass noise filter with damping ratio ξ=10 and cutoff frequency ω=0.02. In addition, the output is ceiled to the nearest integer.

  • For BIS, the standard deviation of the white noise is 35 and the filter is a second-order low-pass noise filter with damping ratio ξ=1 and cutoff frequency ω=0.04.

See identification details on this Notebook

full_sim(inputs_propo: ndarray | None = None, inputs_remi: ndarray | None = None, inputs_nore: ndarray | None = None, inputs_atra: ndarray | None = None, x0_propo: array | None = None, x0_remi: array | None = None, x0_nore: array | None = None, x0_atra: array | None = None, interp=False) DataFrame

Perform a simulation over multiple step times using the inputs profiles provided.

Parameters:
inputs_propoOptional[np.ndarray], optional

Infusion rates or TCI targets for propofol over time. The default is null.

inputs_remiOptional[np.ndarray], optional

Infusion rates or TCI targets for remifentnanil over time. The default is null.

inputs_noreOptional[np.ndarray], optional

Infusion rates or TCI targets for norepinephrine over time. The default is null.

inputs_atraOptional[np.ndarray], optional

Infusion rates or TCI targets for remifentanil over time. The default is null.

x0_propoOptional[np.array], optional

Initial state of the propofol PK model. The default is zeros.

x0_remiOptional[np.array], optional

Initial state of the remifentanil PK model. The default is zeros.

x0_noreOptional[np.array], optional

Initial state of the norepinephrine PK model. The default is zeros.

x0_atraOptional[np.array], optional

Initial state of the atracurium PK model. The default is zeros.

interpbool, optional

Whether to use zero-order-hold (False, the default) or linear (True) interpolation for the input array.

Returns:
pd.DataFrame

Dataframe including all the signals during the simulation.

generate_random_patient(distribution: str | None = 'uniform', patient_arg: dict | None = None)

Generate a random patient with characteristics following either a uniform distribution or a distribution fitted on VitalDB data.

init_dataframe()

Initilize the dataframe variable with the following columns:

  • ‘Time’: Simulation time (s)

  • ‘BIS’: Bispectral Index

  • ‘SQI’: Signal Quality Index

  • ‘LOC’: Loss of consciousness

  • ‘TOL’: Tolerance level

  • ‘TOF’: Train-of-four (%)

  • ‘TPR’: Total eripheral resistance (mmHg min/ mL)

  • ‘SV’: Stroke volume (ml)

  • ‘HR’: Heart rate (beat/min)

  • ‘MAP’: Mean Arterial Pressure (mmHg)

  • ‘CO’: Cardiac Output (L/min)

  • ‘u_propo’: Propofol infusion rate (mg/s)

  • ‘u_remi’: Remifentanil infusion rate (µg/s)

  • ‘u_nore’: Norepinephrine infusion rate (µg/s)

  • ‘u_atra’: Atracurium infusion rate (µg/s)

  • ‘x_propo_1’ to ‘x_propo_4’: States of the propofol PK model

  • ‘x_remi_1’ to ‘x_remi_4’: States of the remifentanil PK model

  • ‘x_nore’: State of the norepinephrine PK model

  • ‘x_atra_1’ to ‘x_atra_4’: States of the atracurium PK model

  • ‘blood_volume’: Blood volume (L)

if applicable TCI targets are also added:

  • ‘target_propo’: Target concentration for Propofol (µg/ml)

  • ‘target_remi’: Target concentration for Remifentanil (ng/ml)

one_step(input_propo: float = 0, input_remi: float = 0, input_nore: float = 0, input_atra: float = 0, blood_rate: float = 0, sqi: float = 100) tuple[float, float, float, float]

Simulate one step of the patient model with given inputs.

If tci pumps are used, the inputs are the target concentrations. Otherwise, they are the infusion rates.

Parameters:
input_propofloat, optional

Infusion rate (mg/s) or target concentration (µg/ml) for Propofol. The default is 0.

input_remifloat, optional

Infusion rate (µg/s) or target concentration (ng/ml) for Remifentanil. The default is 0.

input_norefloat, optional

Infusion rate (µg/s) or target concentration (ng/ml) for Norepinephrine. The default is 0.

input_atracuriumfloat, optional

Infusion rate (mg/s) or target concentration (µg/ml) for Atracurium. The default is 0.

blood_ratefloat, optional

Fluid rates from blood volume (mL/min), negative is bleeding while positive is a transfusion.

sqi: float, optional

Signal Quality Index of the BIS signal. It affects the BIS delay (expressed in seconds) according to the relationship proposed in [Wahlquist2025]: \(bis\_delay = bis\_delay\_max * (1 - \frac{sqi}{100})\). The default is 100.

Returns:
tuple[float, float, float, float]

BIS, MAP, HR, TOF values after one step of simulation.

References

[Wahlquist2025]

Y. Wahlquist, et al. “Kalman filter soft sensor to handle signal quality loss in closed-loop controlled anesthesia” Biomedical Signal Processing and Control 104 (2025): 107506. doi: https://doi.org/10.1016/j.bspc.2025.107506

save_data(inputs: list = None)

Save all current internal variables as a new line in self.dataframe.