API Reference
This section documents the Python API for driving Circulatory Autogen
programmatically, and by external tools such as the CUFLynx GUI. The
interactive tutorials
use it: generation_and_calibration.ipynb generates and simulates a model with these calls,
then calibrates it as a calibration workflow built with WorkflowBuilder
(libcuflynx.calibration_workflow), and workflow_quickstart.ipynb shows every
WorkflowBuilder call on a small model. A workflow is a file, so the notebooks, the
cuflynx-calibration-workflow command and CUFLynx's Workflow tab run the same study; see
Building a workflow in Python.
The reference pages are generated automatically from the docstrings in
src/libcuflynx/, so they stay in sync with the code.
Setup
The repository is circulatory_autogen; the installable package is libcuflynx.
Install it and import from the libcuflynx namespace — there is no import path to set up,
and no checkout is required.
pip install libcuflynx
from libcuflynx.utilities.utility_funcs import get_default_inp_data_dict
The old flat imports were removed in 0.6.0
from param_id.paramID import CVS0DParamID (no libcuflynx. prefix) resolved in
0.4.0 and 0.5.x as a shim that warned. In 0.6.0 it raises ModuleNotFoundError;
prefix the import with libcuflynx.. See CHANGELOG.md.
Public API at a glance
The entry points below cover the full generate → simulate → calibrate → analyse pipeline. Each links to its detailed reference page.
| Task | Entry point | Page |
|---|---|---|
| Build the config dict | get_default_inp_data_dict |
Utilities |
| Generate a model | generate_with_new_architecture |
Model generation |
| Run a simulation | get_simulation_helper / get_simulation_helper_from_inp_data_dict |
Simulation |
| Build observation data | ObsDataCreator |
Observation data & utilities |
| Calibrate parameters | CVS0DParamID |
Parameter identification |
| Build and run a calibration workflow | WorkflowBuilder / run_calibration_workflow |
Calibration workflows |
| Sensitivity analysis | SensitivityAnalysis |
Sensitivity analysis |
| Identifiability analysis | IdentifiabilityAnalysis |
Identifiability analysis |
| Run protocols standalone | ProtocolRunner |
Protocols |
Typical call sequence
from libcuflynx.utilities.utility_funcs import get_default_inp_data_dict
from libcuflynx.scripts.script_generate_with_new_architecture import generate_with_new_architecture
from libcuflynx.solver_wrappers import get_simulation_helper_from_inp_data_dict
from libcuflynx.utilities.obs_data_helpers import ObsDataCreator
from libcuflynx.param_id.paramID import CVS0DParamID
# 1. Configuration (the library's defaults, then mutate in code)
inp = get_default_inp_data_dict(file_prefix, input_param_file, resources_dir)
inp["sim_time"], inp["pre_time"] = 2, 20.0
# 2. Generate the model
generate_with_new_architecture(inp_data_dict=inp)
# 3. Simulate
sim = get_simulation_helper_from_inp_data_dict(inp)
sim.run()
t, y = sim.get_time(), sim.get_results(variables_to_plot, flatten=True)
# 4. Build observation data
obs = ObsDataCreator()
obs.add_protocol_info(pre_times, sim_times, params_to_change)
obs.add_data_item(entry)
obs_data_dict = obs.get_obs_data_dict()
# 5. Calibrate
pid = CVS0DParamID.init_from_dict(inp)
pid.set_ground_truth_data(obs_data_dict)
pid.set_params_for_id(params_for_id_dict)
pid.run()
pid.simulate_with_best_param_vals()
pid.plot_outputs()
resources_dir is a directory of your own holding the model's inputs:
{file_prefix}_module_array.csv (or .json) and the parameters file input_param_file
({file_prefix}_parameters.json). The package installs no example models: copy one from the
repository's resources/
directory (for example 3compartment_module_array.csv, 3compartment_parameters.json,
3compartment_obs_data.json and 3compartment_params_for_id.json), or write your own (see
Designing a model). Generated models and results go under the current
directory unless generated_models_dir and param_id_output_dir say otherwise.
get_default_inp_data_dict fills in the library's defaults, which are not the values of the
repository's user_run_files/user_inputs.yaml (for example solver_info.MaximumStep and
optimiser_options).
params_for_id_dict is the content of a {prefix}_params_for_id.json file: the whole
{"version": 1, "params": [...]} document, or its list of entries
({"targets": ["aortic_root/C"], "min": ..., "max": ..., "name_for_plotting": ...}). A list of
{vessel_name, param_name, min, max, name_for_plotting} entries is read too; there
vessel_name may be a single name or a list to share one calibrated parameter across many
vessels.