Getting Started
Prerequisites
- Python 3.10 or newer (
pyproject.tomldeclaresrequires-python = ">=3.10"). Use the same interpreter for the whole project. - Git, to clone the repository.
- pip (usually bundled with Python).
- MPI (optional): needed only if you run parameter identification or sensitivity analysis with multiple processes. See MPI and system libraries below.
- Compiler / SUNDIALS (optional on Linux): the default solver, Myokit’s CVODE, compiles each model when it is first run, so it needs a C compiler, the Python development headers and SUNDIALS:
build-essential,python3-dev(orpythonX.Y-devfor the Python you use) andlibsundials-dev, or your OS equivalent.
Install the package
The repository is called circulatory_autogen; the package it installs is called
libcuflynx. Both names refer to the same project — papers and the repository use the
first, PyPI and every import uses the second.
pip install libcuflynx
That is all that is needed to import the library, run the console commands
(cuflynx-generate, cuflynx-param-id, …) and work from any directory — no checkout, and no
import path to set up. Optional capabilities are extras, because they are large;
see the size table in the README:
pip install "libcuflynx[mpi]" # multi-rank runs under mpiexec (needs a system MPI)
pip install "libcuflynx[casadi]" # model_type: casadi_python, symbolic AD gradients
pip install "libcuflynx[uq]" # the pyMC sampler
pip install "libcuflynx[emulation]" # surrogate models (pulls in torch; big)
Import from the libcuflynx namespace
The flat imports (from param_id.paramID import CVS0DParamID) were removed in 0.6.0 and
raise ModuleNotFoundError. Use from libcuflynx.param_id.paramID import CVS0DParamID.
Where an installed libcuflynx reads and writes: CUFLYNX_USER_DIR
Every stage needs a user directory — the one holding user_run_files/user_inputs.yaml
and, unless the config overrides them, resources/, module_config_user/, funcs_user/,
generated_models/ and param_id_output/. It is chosen in this order:
$CUFLYNX_USER_DIR, if set — an absolute path (~is expanded).- the circulatory_autogen checkout this
libcuflynxis being run from, if it is one (includingpip install -e .), so the developer workflow needs no configuration; - otherwise the current working directory.
After a plain pip install libcuflynx there is no checkout, so rule 2 never fires: either
run from your working directory, or point the variable at it, which is the only way to run
from anywhere else without editing a config.
export CUFLYNX_USER_DIR=/path/to/my_study # holds user_run_files/, resources/, …
cuflynx-generate False
The package ships no user_inputs.yaml of its own. cuflynx-init writes a starter study to
begin from: user_run_files/user_inputs.yaml and the 3compartment model's resources (module
array, parameters, params_for_id and obs_data), then prints what to run next. It never
overwrites a file unless given --force.
mkdir my_study && cd my_study
cuflynx-init # or: cuflynx-init /path/to/my_study
cuflynx-generate
mpiexec -n 2 cuflynx-param-id
Nothing is ever written inside the installed package — that was issue #431. Individual
directories can still be overridden per-run with resources_dir, generated_models_dir,
param_id_output_dir and external_modules_dir in user_inputs.yaml; CUFLYNX_USER_DIR
is what the defaults hang off when the config names none.
The rest of this page sets up a checkout, which is what the tutorial's shell-script
workflow (user_run_files/*.sh, resources/, module_config_user/) and any development work
need. If you only want to drive the library from Python, the pip install above is enough —
skip to Model Generation and Simulation.
Clone the repository
Clone the Circulatory Autogen project from the GitHub repository.
Note
If you have not used Git before: install Git, open a terminal, go to the folder where you want the code, then run:
git clone https://github.com/physiomelinks/circulatory_autogen
To contribute via a fork:
-
git clone https://github.com/<YourUsername>/circulatory_autogen -
git remote add upstream https://github.com/physiomelinks/circulatory_autogen
Directory layout
[project_dir] is the folder where the repository was cloned, for example:
[project_dir]: ~/Documents/git_projects/circulatory_autogen
The rest of this page assumes commands are run from a terminal and that [project_dir] is your current directory when installing.
Install Python libraries from pyproject.toml
Use the same Python you will use to run scripts and tests (check with python --version or python3 --version).
1. Create a virtual environment (recommended)
cd [project_dir]
python3 -m venv venv
source venv/bin/activate
cd [project_dir]
py -3 -m venv venv
venv\Scripts\activate.bat
cd [project_dir]
py -3 -m venv venv
venv\Scripts\Activate.ps1
If you prefer not to use a venv, skip the steps above and use python -m pip / python3 -m pip for the installs below.
2. Upgrade pip (recommended)
python -m pip install --upgrade pip
3. Install the project and dependencies
Dependencies are listed in pyproject.toml. Installing the package in editable mode pulls them in automatically.
-
Runtime only (autogeneration, parameter ID, solvers such as Myokit, etc.):
cd [project_dir] python -m pip install -e .When you choose
solver: CVODEfor CellML models, the project defaults that to theCVODE_myokitbackend. To run CellML models with libOpenCOR instead, see Optional: the libOpenCOR solver. -
With development tools (pytest, formatters, linters):
cd [project_dir] python -m pip install -e ".[dev]"
The authoritative lists are [project.dependencies] and [project.optional-dependencies] in pyproject.toml. Highlights:
-
Autogeneration:
pandas,pyyaml,rdflib,libcellml,pint, etc.libCellML 0.7.2 or later
The requirement is
libcellml>=0.7.2, installed from PyPI. 0.7.1 drops an imported unit's exponent, so models such as SN_simple fail with a units mismatch under it. If libCellML came from conda or a system package rather than pip, an older version there can make the resolver fail with a version conflict; installing into a fresh virtual environment avoids that.- Parameter identification:
mpi4py,nevergrad(CMA-ES),emcee,numdifftools, and related scientific stack. - Sensitivity analysis:
SALib,seaborn. - Development: the
devextra (e.g.pytest,pytest-mpi).
- Parameter identification:
4. Activate the venv before using the shell helpers
The shell scripts under user_run_files/ (run_param_id.sh, run_autogeneration.sh, …) run
the console commands (cuflynx-param-id, cuflynx-generate, …) found on your PATH, so
activate the venv in the shell you run them from (source venv/bin/activate). To use an
interpreter without activating its environment, set CUFLYNX_PYTHON:
CUFLYNX_PYTHON=[project_dir]/venv/bin/python ./run_param_id.sh 4
Note
user_run_files/python_path.sh only names the interpreter run_pytest.sh runs the tests
with. Its default is venv/bin/python, relative to the repository root, so a venv named
venv needs no edit.
5. Run scripts
With the project installed, the console commands are on your PATH and can be run from any
directory: cuflynx-generate, cuflynx-param-id, cuflynx-sensitivity,
cuflynx-identifiability, cuflynx-train-emulator and cuflynx-plot. Every one of them
reads user_run_files/user_inputs.yaml and takes --help. cuflynx-calibration-workflow
instead takes a calibration_workflow.json (see
Calibration workflows).
The other scripts that ship in the package are run as modules, for example:
python -m libcuflynx.scripts.<script_name>
or use the shell helper for the same stage, e.g. cd user_run_files && ./run_autogeneration.sh
(each helper invokes the matching console command, so the editable install above is a
prerequisite for them).
For a notebook-oriented walkthrough, see tutorial/interactive/generation_and_calibration.ipynb
(generation, simulation, and calibration as a workflow) or, for the calibration workflow alone in a
few minutes, tutorial/interactive/workflow_quickstart.ipynb.
6. Run the tests (optional, but do this after any change)
cd [project_dir]
./run_pytest.sh
run_pytest.sh runs pytest under mpiexec using the python_path named in user_run_files/python_path.sh.
./run_pytest.sh -n 4—-n Nis the MPI rank count, not pytest-xdist (xdist is force-disabled, because its workers conflict with MPI ranks)../run_pytest.sh -m "not slow"— skip the expensive tests.-k <expr>and any other arguments pass straight through to pytest.- The
CVODE_libopencortests are markedneed_libopencorand skip unless libOpenCOR is installed (see below). -
Equivalent without the script (handy if
python_path.shis set for someone else’s machine):mpiexec -n 1 venv/bin/python -m pytest -p no:xdist
Optional third-party backends (not part of Circulatory Autogen)
Circulatory Autogen itself is fully open source (Apache License 2.0) and everything described in this documentation works without installing anything below.
This section describes optional, third-party software that is not part of Circulatory
Autogen. It is not bundled with it, not installed by pip install -e ., not required by
any feature, and not distributed under Circulatory Autogen's license. It is developed and
licensed by other parties, on their terms. Circulatory Autogen merely provides an optional
adapter so that users who already have a licence for such a product can plug it in. If
you install one, you are entering a licensing relationship with that third party, not with
this project.
AADC (Matlogica) — proprietary, optional, not included
AADC is third-party proprietary software and is NOT part of Circulatory Autogen
- Not included, not required. AADC is not shipped with Circulatory Autogen and
no feature of Circulatory Autogen depends on it. The project is fully functional,
and fully open source, without it. Nothing installs it unless you ask for the
[aadc]extra below, which is in neither[all]nor[dev]. - Not open source. AADC is a commercial product of Matlogica, distributed under Matlogica's own proprietary licence — not under Circulatory Autogen's Apache-2.0 licence, and not under any open-source licence. Its terms restrict it to academic / non-commercial use.
- You must obtain your own licence. The Circulatory Autogen maintainers do not supply, sublicense, or broker AADC licences, and cannot support licensing issues. Read and accept Matlogica's licence terms yourself, directly with Matlogica, before installing or using it.
- Its gradients are licence-gated at runtime. Forward simulation may run with a bare
pip install aadc, but anything that records a tape — the automatic-differentiation gradients, and the on-tape damping insemi_implicit— raisesRuntimeError: AADC License check failedwithout a valid licence. - Use CasADi if you want a fully open-source pipeline. CasADi (LGPL) is the
default and supported AD backend and requires no proprietary licence — see
model_type: casadi_pythonin Parameter Identification. AADC is only an optional alternative for licensed academic users; you never need it.
If, and only if, you hold a Matlogica licence and accept their terms, the optional adapter
is enabled by installing the aadc extra:
python -m pip install "libcuflynx[aadc]"
(Into the same venv you installed the project into. From a
checkout, python -m pip install -e ".[aadc]".)
The extra installs two packages from PyPI:
aadc>=2.12,<3— Matlogica's AADC, under the Matlogica EULA: non-commercial / academic use only, published as binary wheels only (no source), for Python >= 3.10.aadc-ode— ODE integration on top of AADC. Thegradient_strategy: kernelgradient ofmethod: semi_implicit_signedreplays its recorded kernel through it. Without it that strategy warns and falls back togradient_strategy: tape, which integrates the same scheme with a slower gradient.
and then selecting it in your user_inputs.yaml:
model_type: aadc_python
solver: aadc_semi_implicit
solver_info:
method: adaptive_rk45 # non-stiff forward solve; see the gradient caveat below
Available solver_info.method values for the AADC adapter are adaptive_rk45 (adaptive,
so accurate for a forward solve but untapeable — its step sequence depends on the
parameters, so it cannot produce an AD gradient), and the fixed-step implicit_euler_ift,
semi_implicit, and rk4 (the only methods that can be recorded on a tape for an AD
gradient).
method: bdf was removed from the AADC adapter
AADC previously offered a bdf method. It ran the solve inside scipy.solve_ivp with AADC
supplying only the RHS and its Jacobian, so the trajectory never reached the tape — and the
AD tape had no bdf branch, so do_ad: true silently recorded rk4 instead, making the
cost and the gradient different functions. Its RHS kernel was also taped once at t=0 with
the integrator discarding t, so a time-dependent model would have been integrated with
its t=0 right-hand side throughout. Setting method: bdf on an aadc_python model now
raises. Use semi_implicit for stiff models — subject to the accuracy warning below — or
model_type: casadi_python with method: bdf for a differentiable symbolic BDF.
AADC gradients do not work on stiff models
Only the fixed-step methods can be taped, and fixed-step schemes are inaccurate or unstable
on stiff models: on the 3compartment cardiovascular model semi_implicit deviates from
the CVODE reference by ~35% and implicit_euler_ift by orders of magnitude. Reducing dt
does not help — semi_implicit diverges under step refinement (~35% at dt=1e-3 rising
to ~280% at dt=1e-4), because its damping factor 1/(1+dt*lam) tends to 1 as dt shrinks
and the scheme degenerates into explicit forward Euler on a very stiff system. The AADC
backend probes the first second of dynamics and warns loudly when it detects a stiff model.
For gradient-based calibration of a stiff model, use CasADi cvodes (CasADi AD by CVODES
forward sensitivities), CasADi bdf, or Myokit CVODES forward sensitivity instead — see Parameter Identification. AADC's
tape gradient is appropriate only for non-stiff, state-observable, single-experiment
problems.
MPI and system libraries
Warning
mpi4py needs an MPI implementation on the machine. On Linux you may need:
sudo apt install libopenmpi-dev openmpi-bin
On macOS, for example: brew install openmpi. On Windows, install MS MPI and the SDK, and ensure the MPI bin paths are on your PATH (see Microsoft’s documentation).
Myokit (CVODE) on Linux needs a compiler, the Python development headers (Python.h; pythonX.Y-dev for a Python other than the system one) and SUNDIALS headers, for example:
sudo apt install build-essential python3-dev libsundials-dev
Expected outcome
You should now have:
- A clone of the repository at
[project_dir]. - A Python environment (venv or global) with dependencies installed from
pyproject.tomlviapip install -e .orpip install -e ".[dev]". - The ability to run
pythonand import the project aftercd [project_dir]with your chosen interpreter.
Optional: the libOpenCOR solver
libOpenCOR is OpenCOR's simulation engine as a Python library.
It runs CellML models as the CVODE_libopencor solver, an alternative to the default
CVODE_myokit:
python -m pip install -e ".[libopencor]"
solver: CVODE_libopencor
solver_info:
MaximumStep: 0.001
MaximumNumberOfSteps: 5000
rtol: 1.0e-8
atol: 1.0e-8
- libOpenCOR's wheels need Python 3.12 or later (Linux, macOS, Windows). On older Pythons the extra installs nothing and the solver says how to get it.
- It compiles the model once and is several times faster per run than
CVODE_myokiton the models inbenchmarks/solver_comparison.py; calibrations use finite-difference gradients with it. - It has no time-varying inputs (
protocol_traces/protocol_shapes) and no forward sensitivities (FSA): useCVODE_myokitfor those. - The OpenCOR desktop application is still a good way to open and run a generated model by
hand (see Model generation and simulation). CA does not
run inside OpenCOR's bundled Python: the solver name
CVODE_opencoris an alias forCVODE_libopencor.