Todo

Improve autoapi module

circadapt

@package CircAdapt.

CircAdapt is a modelling framework of the cardiovascular system. The framework is written in C++ and this package is a wrapper to use CircAdapt in python. The default CircAdapt is empty. The other class descriptions automatically build the corresponding model.

Package Contents

Classes

CircAdapt

Wrapper to communicate with c++ code.

Walmsley2015

Walmsley2015.

VanOsta2022

VanOsta2022 by Nick van Osta.

Attributes

DEFAULT_PATH_TO_CIRCADAPT

Default path to CircAdapt.dll.

Subpackages

Submodules

Objects

circadapt.DEFAULT_PATH_TO_CIRCADAPT = 'CircAdapt.dll'

Default path to CircAdapt.dll.

Do not change this unless you develop the c++ code. By default, it points to the compiled dll file in the package.

class circadapt.CircAdapt(model: str = 'Custom', solver: str = None, path_to_circadapt: str = None, model_state: dict = None)

Wrapper to communicate with c++ code.

Parameters

model: str

Name of the model to be build

solver: str (optional)

Name of solver to be build. If not given, the default models solver is used.

path_to_circadapt: str (optional)

Path to CircAdapt library. If not given, the default_path_to_circadapt is used.

model_state: (multi)

Model state to be loaded. (default) -> load model reference from package False -> do nothing str -> load filename dict -> load given model state

load_reference()

Load reference of current model from the package.

run(n_beats: int = 1, run_stable: bool = False, export: bool = True) None

Run the model by solving the ODEs for n_beats.

The currently loaded model, model state, and parameterization will be used to run n_beats. Optional, more beats are performed until the model is hemodynamically stable (run_stable=True). By default, all data will be exported (export=True). By disabling this (export=False), the model runs faster by only solving the state variables in case a backward ODE solver is used.

Parameters
n_beats: int, optional (default: True)

Number of beats

run_stable: bool, optional (default: False)

Run beats until simulation is hemodynamically stable

export: bool, optional (default: False)

Future

is_stable() bool

Check if simulation is hemodynamically stable.

get(par: str, dtype: any = None) any

Get parameter from the model.

Parameters
par: str

Parameter name to get. This string value contains the parameter that will be obtained and the component from which it will be obtained. Components, its subcomponents, and the parameter name at the and are separated with a dot.

dtype: string or type, optional (default = None)

The type of parameter that will be obtained. If not specified, it will be detairmined automatically. If computational cost is important, it is better to specify the dtype.

Returns
Get value: type depending on dtype.

Returns the value stored in the c++ object

set(par: str, val: any, dtype=None) bool

Set parameter from dtype with value val.

Parameters
par: str

Parameter name to get. This string value contains the parameter that will be obtained and the component from which it will be obtained. Components, its subcomponents, and the parameter name at the and are separated with a dot.

val: any

Value to be set. The value must be the same as the parameter used.

dtype: string or type, optional (default = None)

The type of parameter that will be obtained. If not specified, it will be detairmined automatically. If computational cost is important, it is better to specify the dtype.

Returns

bool: success or not

trigger(par) bool

Trigger a function.

Objects in the model may have a function that can be triggered. This can be done by triggering the function using the ‘par’ parameter similar to the set function, only without a parameter.

Parameters
parstr

Function in object that will be triggered. It has a similar form to the set/get par, i.e. ‘Component.subcomponent.function_name’

Returns

is_success (bool)

add_component(comp_type: str, comp_name: str, base: str = '') bool

Add component to CircAdapt object.

Parameters
comp_type: str

Type of object to create in the ComponentFactory

comp_name: str

Name of the new object to create

base: char, optional (default=’’)

Parent object of new component

Returns

is_success (bool)

set_component(par, obj) bool

Set component to the parameter of a CircAdapt object.

Parameters
par: str

Parameter of object to link object obj to

obj: str

Object to set

model_import(model_state, check_model_state=False) None

Load model_state into CircAdapt object.

Style and model_state version is automatically recognized.

Parameters
model_state: dict

model_state with data to set

obj: str

Object to set

model_export(style: str = None) dict

Return the stored model state.

Parameters
style: str (optional)

Style to follow. If not given, the default style from the model is used.

Returns

dict

save(filename: str, ext: str = None) None

Save model to filename with extention.

Parameters
filename: str

Filename to save file to. Filename must have extention .npy or .mat

ext: str (optional)

Extention of the file. If not given, the last 3 letters of the filename is used to determine the save method.

load(filename: str) None

Load a model dataset from a filename.

Parameters
filename: str

Path to file that will be loaded. The extension must be .npy or .mat.

is_success() bool

Return false if vectors contain nan.

Returns

bool

class circadapt.Walmsley2015(solver=None, path_to_circadapt=None, model_state=None)

Bases: CircAdapt

Walmsley2015.

This model is based on the MultiPatch model, published by Walmsley et al. in 2015, ‘Fast Simulation of Mechanical Heterogeneity in the Electrically Asynchronous Heart Using the MultiPatch Module’, Plos Comp. Biol. The original model was implemented in Matlab. This model is a replica in c++. By default, it uses a different solver.

In this model, the Pericardium is a bag module and contains two Chambers (left and right atria) and the TriSeg model (left and right ventricular cavities with left, right, and septal wall). The circulation is modelled with the ArtVen modules. When built, this model contains the objects:

Model.SyArt : Tube0D : Systemic arteries Model.SyVen : Tube0D : Systemic veins Model.CiSy : ArtVen : Systemic microcirculation Model.PuArt : Tube0D : Pulmonary arteries Model.PuVen : Tube0D : Pulmonary veins Model.CiPu : ArtVen : Pulmonary microcirculation Model.Peri : Bag : Pericardium Model.Peri.La : Chamber2022 : Left atrial cavity Model.Peri.La.W : Wall2022 : Left atrial wall Model.Peri.La.W.pLa1 : Patch2022 : Left atrial wall segment Model.Peri.Ra : Chamber2022 : Right atrial cavity Model.Peri.Ra.W : Wall2022 : Rigth atrial wall Model.Peri.Ra.W.pRa1 : Patch2022 : Patch of Ra Model.Peri.TriSeg : TriSeg2022 : Handles pressure in cLv and

cRv based on wall tension in wRv, wLv, and wSv

Model.Peri.TriSeg.cLv : Cavity : Left ventricular cavity Model.Peri.TriSeg.cRv : Cavity : Right ventricular cavity Model.Peri.TriSeg.wLv : Wall2022 : Left ventricular free wall Model.Peri.TriSeg.wLv.pLv1 : Patch2022 : Patch of wLv Model.Peri.TriSeg.wSv : Wall2022 : Septal wall Model.Peri.TriSeg.wSv.pSv1 : Patch2022 : Patch of wSv Model.Peri.TriSeg.wRv : Wall2022 : Right ventricular free wall Model.Peri.TriSeg.wRv.pRv1 : Patch2022 : Patch of wRv Model.Peri.SyVenRa : Valve : Ra inflow Model.Peri.RaRv : Valve : Valve between cavities Model.Peri.RvPuArt : Valve : Valve between cavities Model.Peri.PuVenLa : Valve : La inflow Model.Peri.LaLv : Valve : Valve between cavities Model.Peri.LvSyArt : Valve : Valve between cavities Model.PVC : Wall2022 : Pressure flow control Model.Timings : Timings : Sets activation timings in

patches

Each object has their own parameters, which can be found in the c++ class documentation.

Each element in this model is fully verified, and can be found in (in preparation).

load_reference()

Load reference of current model from the package.

run(n_beats: int = 1, run_stable: bool = False, export: bool = True) None

Run the model by solving the ODEs for n_beats.

The currently loaded model, model state, and parameterization will be used to run n_beats. Optional, more beats are performed until the model is hemodynamically stable (run_stable=True). By default, all data will be exported (export=True). By disabling this (export=False), the model runs faster by only solving the state variables in case a backward ODE solver is used.

Parameters

n_beats: int, optional (default: True)

Number of beats

run_stable: bool, optional (default: False)

Run beats until simulation is hemodynamically stable

export: bool, optional (default: False)

Future

is_stable() bool

Check if simulation is hemodynamically stable.

get(par: str, dtype: any = None) any

Get parameter from the model.

Parameters

par: str

Parameter name to get. This string value contains the parameter that will be obtained and the component from which it will be obtained. Components, its subcomponents, and the parameter name at the and are separated with a dot.

dtype: string or type, optional (default = None)

The type of parameter that will be obtained. If not specified, it will be detairmined automatically. If computational cost is important, it is better to specify the dtype.

Returns

Get value: type depending on dtype.

Returns the value stored in the c++ object

set(par: str, val: any, dtype=None) bool

Set parameter from dtype with value val.

Parameters

par: str

Parameter name to get. This string value contains the parameter that will be obtained and the component from which it will be obtained. Components, its subcomponents, and the parameter name at the and are separated with a dot.

val: any

Value to be set. The value must be the same as the parameter used.

dtype: string or type, optional (default = None)

The type of parameter that will be obtained. If not specified, it will be detairmined automatically. If computational cost is important, it is better to specify the dtype.

Returns

bool: success or not

trigger(par) bool

Trigger a function.

Objects in the model may have a function that can be triggered. This can be done by triggering the function using the ‘par’ parameter similar to the set function, only without a parameter.

Parameters

parstr

Function in object that will be triggered. It has a similar form to the set/get par, i.e. ‘Component.subcomponent.function_name’

Returns

is_success (bool)

add_component(comp_type: str, comp_name: str, base: str = '') bool

Add component to CircAdapt object.

Parameters

comp_type: str

Type of object to create in the ComponentFactory

comp_name: str

Name of the new object to create

base: char, optional (default=’’)

Parent object of new component

Returns

is_success (bool)

set_component(par, obj) bool

Set component to the parameter of a CircAdapt object.

Parameters

par: str

Parameter of object to link object obj to

obj: str

Object to set

model_import(model_state, check_model_state=False) None

Load model_state into CircAdapt object.

Style and model_state version is automatically recognized.

Parameters

model_state: dict

model_state with data to set

obj: str

Object to set

model_export(style: str = None) dict

Return the stored model state.

Parameters

style: str (optional)

Style to follow. If not given, the default style from the model is used.

Returns

dict

save(filename: str, ext: str = None) None

Save model to filename with extention.

Parameters

filename: str

Filename to save file to. Filename must have extention .npy or .mat

ext: str (optional)

Extention of the file. If not given, the last 3 letters of the filename is used to determine the save method.

load(filename: str) None

Load a model dataset from a filename.

Parameters

filename: str

Path to file that will be loaded. The extension must be .npy or .mat.

is_success() bool

Return false if vectors contain nan.

Returns

bool

class circadapt.VanOsta2022(solver=None, path_to_circadapt=None, model_state=None)

Bases: CircAdapt, adapt.ModelAdapt

VanOsta2022 by Nick van Osta.

This model is based on the MultiPatch model, published by Walmsley et al. in 2015, ‘Fast Simulation of Mechanical Heterogeneity in the Electrically Asynchronous Heart Using the MultiPatch Module’, Plos Comp. Biol. The original model was implemented in Matlab. This model has improved stability as it has more feedback loops to estimate the mechanical equilibrium in each iteration.

Notes

In this model, the Pericardium is a bag module and contains two Chambers (left and right atria) and the TriSeg model (left and right ventricular cavities with left, right, and septal wall). The circulation is modelled with the ArtVen modules. When built, this model contains the objects:

<table border=”1” class=”docutils”> <thead> <tr> <th>Model</th> <th>Submodel</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>SyArt</td> <td>Tube0D</td> <td>Systemic arteries</td> </tr> <tr> <td>SyVen</td> <td>Tube0D</td> <td>Systemic veins</td> </tr> <tr> <td>CiSy</td> <td>ArtVen</td> <td>Systemic microcirculation</td> </tr> <tr> <td>PuArt</td> <td>Tube0D</td> <td>Pulmonary arteries</td> </tr> <tr> <td>PuVen</td> <td>Tube0D</td> <td>Pulmonary veins</td> </tr> <tr> <td>CiPu</td> <td>ArtVen</td> <td>Pulmonary microcirculation</td> </tr> <tr> <td>Peri</td> <td>Bag</td> <td>Pericardium</td> </tr> <tr> <td>Peri.La</td> <td>Chamber2022</td> <td>Left atrial cavity</td> </tr> <tr> <td>Peri.La.W</td> <td>Wall2022</td> <td>Left atrial wall</td> </tr> <tr> <td>Peri.La.W.pLa1</td> <td>Patch2022</td> <td>Left atrial wall segment</td> </tr> <tr> <td>Peri.Ra</td> <td>Chamber2022</td> <td>Right atrial cavity</td> </tr> <tr> <td>Peri.Ra.W</td> <td>Wall2022</td> <td>Right atrial wall</td> </tr> <tr> <td>Peri.Ra.W.pRa1</td> <td>Patch2022</td> <td>Patch of Ra</td> </tr> <tr> <td>Peri.TriSeg</td> <td>TriSeg2022</td> <td>Handles pressure in cLv and cRv based on wall tension in wRv, wLv, and wSv</td> </tr> <tr> <td>Peri.TriSeg.cLv</td> <td>Cavity</td> <td>Left ventricular cavity</td> </tr> <tr> <td>Peri.TriSeg.cRv</td> <td>Cavity</td> <td>Right ventricular cavity</td> </tr> <tr> <td>Peri.TriSeg.wLv</td> <td>Wall2022</td> <td>Left ventricular free wall</td> </tr> <tr> <td>Peri.TriSeg.wLv.pLv1</td> <td>Patch2022</td> <td>Patch of wLv</td> </tr> <tr> <td>Peri.TriSeg.wSv</td> <td>Wall2022</td> <td>Septal wall</td> </tr> <tr> <td>Peri.TriSeg.wSv.pSv1</td> <td>Patch2022</td> <td>Patch of wSv</td> </tr> <tr> <td>Peri.TriSeg.wRv</td> <td>Wall2022</td> <td>Right ventricular free wall</td> </tr> <tr> <td>Peri.TriSeg.wRv.pRv1</td> <td>Patch2022</td> <td>Patch of wRv</td> </tr> <tr> <td>Peri.SyVenRa</td> <td>Valve</td> <td>Ra inflow</td> </tr> <tr> <td>Peri.RaRv</td> <td>Valve</td> <td>Valve between cavities</td> </tr> <tr> <td>Peri.RvPuArt</td> <td>Valve</td> <td>Valve between cavities</td> </tr> <tr> <td>Peri.PuVenLa</td> <td>Valve</td> <td>La inflow</td> </tr> <tr> <td>Peri.LaLv</td> <td>Valve</td> <td>Valve between cavities</td> </tr> <tr> <td>Peri.LvSyArt</td> <td>Valve</td> <td>Valve between cavities</td> </tr> <tr> <td>PVC</td> <td>Wall2022</td> <td>Pressure flow control</td> </tr> <tr> <td>Timings</td> <td>Timings</td> <td>Sets activation timings in patches</td> </tr> </tbody> </table>

Each object has their own parameters, which can be found in the c++ class documentation.

Each element in this model is fully verified, and can be found in (in preparation).

circadapt.load_reference()

Load reference of current model from the package.

circadapt.run(n_beats: int = 1, run_stable: bool = False, export: bool = True) None

Run the model by solving the ODEs for n_beats.

The currently loaded model, model state, and parameterization will be used to run n_beats. Optional, more beats are performed until the model is hemodynamically stable (run_stable=True). By default, all data will be exported (export=True). By disabling this (export=False), the model runs faster by only solving the state variables in case a backward ODE solver is used.

Parameters

n_beats: int, optional (default: True)

Number of beats

run_stable: bool, optional (default: False)

Run beats until simulation is hemodynamically stable

export: bool, optional (default: False)

Future

circadapt.is_stable() bool

Check if simulation is hemodynamically stable.

circadapt.get(par: str, dtype: any = None) any

Get parameter from the model.

Parameters

par: str

Parameter name to get. This string value contains the parameter that will be obtained and the component from which it will be obtained. Components, its subcomponents, and the parameter name at the and are separated with a dot.

dtype: string or type, optional (default = None)

The type of parameter that will be obtained. If not specified, it will be detairmined automatically. If computational cost is important, it is better to specify the dtype.

Returns

Get value: type depending on dtype.

Returns the value stored in the c++ object

circadapt.set(par: str, val: any, dtype=None) bool

Set parameter from dtype with value val.

Parameters

par: str

Parameter name to get. This string value contains the parameter that will be obtained and the component from which it will be obtained. Components, its subcomponents, and the parameter name at the and are separated with a dot.

val: any

Value to be set. The value must be the same as the parameter used.

dtype: string or type, optional (default = None)

The type of parameter that will be obtained. If not specified, it will be detairmined automatically. If computational cost is important, it is better to specify the dtype.

Returns

bool: success or not

circadapt.trigger(par) bool

Trigger a function.

Objects in the model may have a function that can be triggered. This can be done by triggering the function using the ‘par’ parameter similar to the set function, only without a parameter.

Parameters

parstr

Function in object that will be triggered. It has a similar form to the set/get par, i.e. ‘Component.subcomponent.function_name’

Returns

is_success (bool)

circadapt.add_component(comp_type: str, comp_name: str, base: str = '') bool

Add component to CircAdapt object.

Parameters

comp_type: str

Type of object to create in the ComponentFactory

comp_name: str

Name of the new object to create

base: char, optional (default=’’)

Parent object of new component

Returns

is_success (bool)

circadapt.set_component(par, obj) bool

Set component to the parameter of a CircAdapt object.

Parameters

par: str

Parameter of object to link object obj to

obj: str

Object to set

circadapt.model_import(model_state, check_model_state=False) None

Load model_state into CircAdapt object.

Style and model_state version is automatically recognized.

Parameters

model_state: dict

model_state with data to set

obj: str

Object to set

circadapt.model_export(style: str = None) dict

Return the stored model state.

Parameters

style: str (optional)

Style to follow. If not given, the default style from the model is used.

Returns

dict

circadapt.save(filename: str, ext: str = None) None

Save model to filename with extention.

Parameters

filename: str

Filename to save file to. Filename must have extention .npy or .mat

ext: str (optional)

Extention of the file. If not given, the last 3 letters of the filename is used to determine the save method.

circadapt.load(filename: str) None

Load a model dataset from a filename.

Parameters

filename: str

Path to file that will be loaded. The extension must be .npy or .mat.

circadapt.is_success() bool

Return false if vectors contain nan.

Returns

bool

circadapt.get_adapt_options()

Get default adapt options.

circadapt.adapt(options: dict = {}, output: bool = False) None

Run adaptation protocol.

The adaptation protocol runs n_cycles cycles. Each cycle has two phases, namely rest adaptation and exercise adaptation. First, in exercise, the Patches and vessel wall volumes are adapted to load. In rest, vessels are adapted to flow.

Parameters

optionsdictionary, optional

Options for the protocol. To set options, use the function get_adapt_options(), which is used by default. The default is {}.

outputbool, optional

DESCRIPTION. The default is False.

Returns

senses_resultsTYPE

Only when output=True.

senses_normTYPE

Only when output=True.

actor_resultsTYPE

Only when output=True.

actor_vwallTYPE

Only when output=True.

circadapt.adapt_exercise()

Trigger all excercise adaptation functions.

circadapt.adapt_rest()

Trigger all rest adaptation functions.

circadapt.calculate_matrix()