Skip to content

Merging dev to Fay's branch #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 121 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
246db85
adding pre-commit to toml
LevanBokeria Feb 10, 2025
fa915a1
adding balck, flake8 and isort packages. creating pre-commit-config.y…
LevanBokeria Feb 10, 2025
8ebf9b4
adding packages to pre-commit file
LevanBokeria Feb 10, 2025
5bb3a75
fixing formatting errors by adding an escape character to backslashes
LevanBokeria Feb 10, 2025
bce8516
updating the pre-commit yaml
LevanBokeria Feb 10, 2025
409de95
updating the precommit file name
LevanBokeria Feb 10, 2025
106867f
removing KorakianitisMixedModel tests and expected outputs for this b…
LevanBokeria Feb 11, 2025
24cf95b
merging dev into 24-test-naghavi-model including updated gh ci, readm…
LevanBokeria Feb 11, 2025
db55ef8
basic copilot suggested test for solver as a scaffold
LevanBokeria Mar 3, 2025
f8badbd
adding tests for initialize_by_function() function
LevanBokeria Mar 6, 2025
1e18baa
reordered placement of properties and functions in the Solver.py, for…
LevanBokeria Mar 7, 2025
7ba57b8
adding tests for optimize function and initialize_by_function function
LevanBokeria Mar 7, 2025
4094dc0
adding a random seed setter to the solver test
LevanBokeria Mar 7, 2025
be1aa8f
added a test for pv_dfdt_update function
LevanBokeria Mar 7, 2025
6acafe0
added a test for the solve() function
LevanBokeria Mar 7, 2025
93c96e0
fixing the tests and file names
LevanBokeria Mar 7, 2025
40c54e5
separating out different tests in the solver test
LevanBokeria Mar 7, 2025
dcade65
fixed some tests and added docstrings
LevanBokeria Mar 7, 2025
00ca011
updating Naghavi tests. Copied over from KMM tests
LevanBokeria Mar 10, 2025
c1203ee
Merge pull request #44 from alan-turing-institute/38-solver-tests
MaxBalmus Mar 10, 2025
f379779
updating the tests
LevanBokeria Mar 10, 2025
374f3ff
Merge branch 'dev' into 24-test-naghavi-model
LevanBokeria Mar 10, 2025
5504383
Add missing JSON file from dev branch
LevanBokeria Mar 10, 2025
97c75c9
added Naghavi expected outputs;
LevanBokeria Mar 10, 2025
8c324a5
working on the tests
LevanBokeria Mar 10, 2025
7422a11
fixing Naghavi components being tested
LevanBokeria Mar 10, 2025
650584e
documentation of solver
crangelsmith Mar 11, 2025
6cefbb6
adaptable cycle slicing
crangelsmith Mar 12, 2025
a97702d
reducing the number of cycles needed in the test
crangelsmith Mar 12, 2025
833c987
attemp #1 at fix
MaxBalmus Mar 18, 2025
b00522f
small change to plotting tools to make sure that change in solver is …
MaxBalmus Mar 18, 2025
9aa008e
removed redundant printout
MaxBalmus Mar 18, 2025
6ce9188
update the tests to account for the correction of the time shift
MaxBalmus Mar 18, 2025
9cc2304
removed pyc files
MaxBalmus Mar 18, 2025
64888d9
added *pyc to .gitignore
MaxBalmus Mar 18, 2025
e4c0705
Merge pull request #47 from alan-turing-institute/46-remove-dt-shift-…
MaxBalmus Mar 19, 2025
2961ce6
Merge remote-tracking branch 'origin/dev' into dev
crangelsmith Mar 19, 2025
243e5f2
adding step in range of cycles to solver.
crangelsmith Mar 19, 2025
6de97be
fixed edge case where _Nconv was not initialized when solver failed t…
MaxBalmus Mar 19, 2025
f4fd8ba
comment updates and formatting
LevanBokeria Mar 20, 2025
3203bae
removed self._N_psv and self._N_ssv variables since they are not used…
LevanBokeria Mar 20, 2025
cdefc0f
just adding more comments
LevanBokeria Mar 20, 2025
ba1f3b8
minor formatting and enhanced docstrings for initialize_by_function f…
LevanBokeria Mar 26, 2025
73becb0
further enhancing docstrings
LevanBokeria Mar 26, 2025
930a8d1
enhancing documentation for s_u_update
LevanBokeria Mar 26, 2025
f1b1a2d
s_u_update() function argument y was defined as y:np.ndarray[float,fl…
LevanBokeria Mar 26, 2025
1d780d3
s_u_update() function argument y was defined as y:np.ndarray[float,fl…
LevanBokeria Mar 26, 2025
4cb15ea
minor formatting
LevanBokeria Mar 26, 2025
4bc580e
updated the solver test to test for multiple step sizes
LevanBokeria Mar 26, 2025
fdc90c1
updated the solver tests to include testing for multiple sizes
LevanBokeria Mar 26, 2025
3bfe075
adding 7 for step_sizes for solver tests
LevanBokeria Mar 26, 2025
715b77a
Adding a sandbox folder for exploratory scripts and notebooks
LevanBokeria Mar 27, 2025
bcfa944
removing export_min part
LevanBokeria Mar 31, 2025
e306299
removed export_min multiplication and Nconv addition to tind_fin calc…
LevanBokeria Mar 31, 2025
a43df7a
removed export_min multiplication and Nconv addition for test_Solver.…
LevanBokeria Mar 31, 2025
29b4062
wrote a notebook to regenerate KNOs. regenerated KNOs for KMM
LevanBokeria Mar 31, 2025
61e8fca
Fixed small bug which removed one last time step from the last cycle …
MaxBalmus Mar 31, 2025
30e5f35
Merge pull request #50 from alan-turing-institute/49-regenerate-test-…
LevanBokeria Mar 31, 2025
4b26be3
resolving merge conflict by incorporating dev into 42-43-second-attempt
LevanBokeria Mar 31, 2025
48848fc
changed the notebook that generates KNOs to save multiple results for…
LevanBokeria Mar 31, 2025
24dc785
modifying the tests to test for multipl cycle step sizes
LevanBokeria Mar 31, 2025
7684d18
modified to check for different cycle_step_size
LevanBokeria Apr 1, 2025
65cfdd0
changing to dynamic file paths
LevanBokeria Apr 1, 2025
2485f95
switched to logging package instead of print
LevanBokeria Apr 1, 2025
62dc7dd
minor
LevanBokeria Apr 1, 2025
fb1d3a2
changed to relative tolerance being defined as a constant
LevanBokeria Apr 1, 2025
4768c0f
updating the KMM tests to have logging, subtests for each cycle_step_…
LevanBokeria Apr 1, 2025
9641cd7
fixed missing base_dir attribute
LevanBokeria Apr 1, 2025
7eb05ca
improving docstrings
LevanBokeria Apr 1, 2025
6b90cda
Merge branch '42-43-second-attempt' into 24-test-naghavi-model
LevanBokeria Apr 1, 2025
a88c39b
updating file names
LevanBokeria Apr 1, 2025
e16f7c9
updated the typo in the file names
LevanBokeria Apr 1, 2025
ea1b3e9
generating KGOs but encountering errors
LevanBokeria Apr 1, 2025
28ff746
figures out the bug. redefining the model and solver for each cycle_s…
LevanBokeria Apr 1, 2025
ffad7c5
regenerated KGOs for KMM
LevanBokeria Apr 1, 2025
3fcf49b
setting up the model within the cycle_step_size loop
LevanBokeria Apr 2, 2025
97a9c63
merging complete
LevanBokeria Apr 2, 2025
a45b88e
updated test_Solver.py with model setup within the loop as well
LevanBokeria Apr 2, 2025
6101373
reinitialising the model and solver for each loop
LevanBokeria Apr 2, 2025
ddf5471
Merge pull request #48 from alan-turing-institute/42-43-second-attempt
MaxBalmus Apr 2, 2025
f02061d
NaghaviModel KGO and tests done
LevanBokeria Apr 2, 2025
efabcd6
merge and minor fix in generate_KMM_KGO.ipynb
LevanBokeria Apr 2, 2025
0fd95d1
deleting redundant cell
LevanBokeria Apr 2, 2025
6950d9f
minor comments removed
LevanBokeria Apr 2, 2025
26e16e0
enhancing docstrings
LevanBokeria Apr 2, 2025
12e0c12
minor docstring improvements
LevanBokeria Apr 2, 2025
bc8be54
deleted the old file with errors
LevanBokeria Apr 2, 2025
892f1d3
Merge pull request #53 from alan-turing-institute/24-test-naghavi-model
MaxBalmus Apr 2, 2025
0364343
updated pyproject.toml with new license format requirement
LevanBokeria Apr 3, 2025
a653894
updated gitignore to ignore pypi config
LevanBokeria Apr 8, 2025
1d972ff
changing the directory structure to the src format. temporarily renam…
LevanBokeria Apr 8, 2025
ca8e431
removing manual discovery of packages from toml
LevanBokeria Apr 8, 2025
ae07a71
updating setuptools required version
LevanBokeria Apr 8, 2025
0e2bb7b
updating toml
LevanBokeria Apr 8, 2025
e4811b7
Update README.md
LevanBokeria Apr 8, 2025
124eb9f
Update README.md
LevanBokeria Apr 8, 2025
fa0bf76
changing the name back to ModularCirc
LevanBokeria Apr 8, 2025
925a093
decided to stay on testpypi for now
LevanBokeria Apr 8, 2025
1f3a859
Update README.md
LevanBokeria Apr 8, 2025
6d181f5
Update README.md
LevanBokeria Apr 8, 2025
4881208
bumping up the release version
LevanBokeria Apr 8, 2025
471a7f6
updating to ignore vscode settings
LevanBokeria Apr 8, 2025
6104cb0
deleting the .vscode/
LevanBokeria Apr 8, 2025
d525ab4
ignoring .vscode
LevanBokeria Apr 8, 2025
50988a5
removing username from package name
LevanBokeria Apr 8, 2025
b638248
ignoring __pycache__ inside Tutorials
LevanBokeria Apr 9, 2025
4343976
Merge pull request #56 from alan-turing-institute/45-publish-in-pypi
MaxBalmus Apr 10, 2025
c4703a7
adding automatic publishing yml file
LevanBokeria Apr 10, 2025
4b966ac
env name change
LevanBokeria Apr 10, 2025
852f38c
Update README.md
LevanBokeria Apr 10, 2025
096881f
updating the release number
LevanBokeria Apr 10, 2025
1e93797
Update publish.yml
LevanBokeria Apr 10, 2025
1e8ead5
Merge branch 'dev' into 21-add-pre-commit-hooks.
LevanBokeria Apr 14, 2025
ad787a5
Merge branch 'dev' into 21-add-pre-commit-hooks
LevanBokeria Apr 14, 2025
b342021
pre-commits unleashed
LevanBokeria Apr 14, 2025
1f66e5b
Merge pull request #59 from alan-turing-institute/57-automatic-pypi-p…
LevanBokeria Apr 14, 2025
0dc2a1f
fixed pre-commit yaml
LevanBokeria Apr 14, 2025
d1b59cc
addint CONTRIBUTING.md
LevanBokeria Apr 14, 2025
c70965c
explaining the pre-commit hooks
LevanBokeria Apr 14, 2025
fc87fa6
Merge branch 'dev' into 21-add-pre-commit-hooks
LevanBokeria Apr 14, 2025
c555f5d
Merge pull request #60 from alan-turing-institute/21-add-pre-commit-h…
LevanBokeria Apr 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ jobs:
environment-file: environment.yml
python-version: '3.10'
auto-activate-base: false

- name: Install dependencies
run: |
run: |
python -m pip install --upgrade pip
pip install setuptools --upgrade
pip install ./

- name: Run tests
run: |
run: |
python -m unittest discover -s tests

build-venv:
Expand Down Expand Up @@ -76,4 +76,4 @@ jobs:
- name: Run tests
run: |
source venv/bin/activate
python -m unittest discover -s tests
python -m unittest discover -s tests
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Upload Python Package to PyPI when a Release is Created

on:
release:
types: [created]

jobs:
pypi-publish:
name: Publish release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi_release
url: https://pypi.org/p/ModularCirc
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel build
- name: Build package
run: |
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,11 @@ cython_debug/
/Tutorials
.DS_Store
/playground_files

*.pyc

# Ignore the PyPI configuration file
.pypirc

# Ignore vscode settings
.vscode/
56 changes: 56 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace # remove trailing whitespace
- id: end-of-file-fixer # ensure files end with a newline
- id: check-yaml # check YAML files for syntax errors
- id: check-json # check JSON files for syntax errors
- id: check-added-large-files # check for large files
args: ['--maxkb=500'] # set the max file size to 500KB
- id: check-case-conflict # check for case conflicts in filenames.
- id: check-merge-conflict # This hook checks for merge conflict markers in files.
# It ensures that there are no unresolved merge conflicts in the codebase.
- id: check-symlinks # check for broken symlinks
# - id: debug-statements
- id: mixed-line-ending # check for mixed line endings, meaning that
# a file contains both CRLF and LF line endings. This can cause issues
# when working with files across different operating systems.

# - repo: https://github.com/psf/black
# rev: 25.1.0 # Use the latest stable version
# hooks:
# - id: black

# - repo: https://github.com/PyCQA/flake8
# rev: 7.1.1 # Use the latest stable version
# hooks:
# - id: flake8

# - repo: https://github.com/pre-commit/mirrors-isort
# rev: 6.0.0 # Use the latest stable version
# hooks:
# - id: isort

# - repo: https://github.com/astral-sh/ruff-pre-commit
# rev: "v0.11.5"
# hooks:
# # first, lint + autofix
# - id: ruff
# types_or: [python, pyi, jupyter]
# args: ["--fix", "--show-fixes"]
# # then, format
# - id: ruff-format

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.15.0"
# hooks:
# - id: mypy
# files: src
# args: []
# additional_dependencies:
# - pytest
47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
See the [Scientific Python Developer Guide][spc-dev-intro] for a detailed
description of best practices for developing scientific packages.

[spc-dev-intro]: https://learn.scientific-python.org/development/

# Setting up a development environment manually

You can set up a development environment by running:

```zsh
python3 -m venv venv # create a virtualenv called venv
source ./venv/bin/activate # now `python` points to the virtualenv python
pip install -v -e ".[dev]" # -v for verbose, -e for editable, [dev] for dev dependencies
```

# Post setup

You should prepare pre-commit, which will help you by checking that commits pass
required checks:

```bash
pip install pre-commit # or brew install pre-commit on macOS
pre-commit install # this will install a pre-commit hook into the git repo
```

You can also/alternatively run `pre-commit run` (changes only) or
`pre-commit run --all-files` to check even without installing the hook.

# Testing

This repo uses `unittest` for testing. You can run locally the tests by running the following command:

```bash
python -m unittest discover -s tests
```
there is also a autamtated test pipeline that runs the tests on every push to the repository (see [here](.github/workflows/ci.yml)).


# Pre-commit

This project uses pre-commit for all style checking. Install pre-commit and run:

```bash
pre-commit run -a
```

to check all files.
1 change: 0 additions & 1 deletion ModularCirc/__init__.py

This file was deleted.

37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ModularCirc

[![Actions Status][actions-badge]][actions-link]
[![PyPI version][pypi-version]][pypi-link]
[![PyPI platforms][pypi-platforms]][pypi-link]

The scope of this package is to provide a framework for building **0D models** and **simulating cardiovascular flow** and **mechanics**. Conceptually, the models can be split into three types of components:
1. **Heart chambers**
2. **Valves**
Expand All @@ -22,7 +26,7 @@ Before installation of the ModularCirc package, please setup a virtual environme

Install Conda from https://docs.conda.io/projects/conda/en/stable/user-guide/install/index.html

Run:
Run:

```
conda create --name <yourenvname>
Expand All @@ -33,21 +37,30 @@ Proceed to installing the ModularCirc package.

### Python virtual environment setup

Run `python3 -m venv venv`. This creates a virtual environment called `venv` in your base directory.
Run `python3 -m venv venv`. This creates a virtual environment called `venv` in your base directory.

Activate the python environment: `source venv/bin/activate`

Proceed to installing the ModularCirc package.

## Installation

From the repo directory, run:
To install the pip package:

```bash
python -m pip install ModularCirc_LevanBokeria
```

From source:

After downloading the GitHub repository, from the repo directory run:

```bash
pip install ./
```

This will install the package based on the `pyproject.toml` file specifications.
This will install the package based on the `pyproject.toml` file specifications.


## Steps for running basic models
1. Load the classes for the model of interest and the parameter object used to paramterise the said model:
Expand All @@ -66,14 +79,14 @@ TEMPLATE_TIME_SETUP_DICT = {
'name' : 'TimeTest',
'ncycles' : 40,
'tcycle' : 1.0,
'dt' : 0.001,
'dt' : 0.001,
'export_min' : 1
}
```
Here, `ncycles` indicates the maximum number of heart cycles to run, before the simulation finishes.
If the simulation reaches steady state faster than that, the simulation will end provided the number of cycles is higher than `export_min`.
`tcycle` indicates the duration of the heart beat and `dt` represent the time step size used in the temporal discretization.
These measurements assume that time is measured in **seconds**.
If the simulation reaches steady state faster than that, the simulation will end provided the number of cycles is higher than `export_min`.
`tcycle` indicates the duration of the heart beat and `dt` represent the time step size used in the temporal discretization.
These measurements assume that time is measured in **seconds**.
If the units used are different, ensure this is done consistently in line with other parameters.

4. Create an instance of the parameter object and used it to change the default values:
Expand Down Expand Up @@ -116,3 +129,11 @@ You can run locally the tests by running the following command:
python -m unittest discover -s tests
```
there is also a autamtated test pipeline that runs the tests on every push to the repository (see [here](.github/workflows/ci.yml)).

<!-- prettier-ignore-start -->
[actions-badge]: https://github.com/alan-turing-institute/ModularCirc/workflows/CI/badge.svg
[actions-link]: https://github.com/alan-turing-institute/ModularCirc/actions
[pypi-link]: https://pypi.org/project/ModularCirc
[pypi-platforms]: https://img.shields.io/pypi/pyversions/ModularCirc
[pypi-version]: https://img.shields.io/pypi/v/ModularCirc
<!-- prettier-ignore-end -->
4 changes: 2 additions & 2 deletions Tutorials/Tutorial_01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Involved in a larger project involving patients with pulmonary arterial hyperten

Currently, while the monitors provide a lot of cardiac data, the usefulness of the data that they provide is limited, as it is difficult to interpret and use the information to make approprate changes to patient management.

The project focuses on the development of a digital twin to aid with interpretation of the cardiac data from these monitors.
The project focuses on the development of a digital twin to aid with interpretation of the cardiac data from these monitors.

The sensitivity analysis aims to focus in on the parameters from the model that most affect pulmonary arterial pressure and cardiac output.

Expand All @@ -28,4 +28,4 @@ Using a reduced set of parameters, you can more efficiently fit the model to pat
4) Complete K fold cross validation.
5) Retrain model on all the data with the new reduced number of components.
6) Use the reduced PCA results as output and the original parameter set you created as input for emulation - use [Autoemulate](https://github.com/alan-turing-institute/autoemulate) to find the best emulator for the data, this uses the "step3" notebook.
7) Conduct a sensitivity analysis using the results from emulation using SAlib.
7) Conduct a sensitivity analysis using the results from emulation using SAlib.
Binary file not shown.
22 changes: 11 additions & 11 deletions Tutorials/Tutorial_01/circ_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def signal_get_pulse(signal, dt, num=100):
Returns:
_type_: _description_
"""
ind = np.argmin(signal)

ind = np.argmin(signal)
ncycle = len(signal)
new_signal = np.interp(np.linspace(0, ncycle, num), np.arange(ncycle), np.roll(signal, -ind))
new_dt = ncycle / (num - 1) * dt
Expand Down Expand Up @@ -80,8 +80,8 @@ def run_case(row, output_path, N_cycles, dt):
) # replace the .. with the correct Class and inputs if applicable

solver.setup(
suppress_output=True,
optimize_secondary_sv=False,
suppress_output=True,
optimize_secondary_sv=False,
conv_cols=["p_ao"],
method='LSODA'
)
Expand Down Expand Up @@ -138,7 +138,7 @@ def simulation_loader(input_directory):

file_series.sort_values('Index', inplace=True)
file_series.set_index('Index', inplace=True)

# Define a dataframe for the values collected from the simulation...
signal_df = file_series.apply(
lambda row: list(pd.read_csv(os.path.join(input_directory, row['file']), index_col='Index').to_numpy().reshape((-1))),
Expand All @@ -147,7 +147,7 @@ def simulation_loader(input_directory):
signal_df.rename(columns=template_columns, inplace=True)

return signal_df


dict_parameters_condensed_range = dict()
dict_parameters_condensed_single = dict()
Expand All @@ -166,7 +166,7 @@ def condense_dict_parameters(dict_param:dict, prev=""):
dict_parameters_condensed_range[new_key] = tuple(np.array(r) * value)
else:
dict_parameters_condensed_single[new_key] = val[0]
return
return


######## DEFINED A FUNCTION TO PLOT THE VARIANCE
Expand All @@ -186,7 +186,7 @@ def plot_variance(pca, width=8, dpi=100):
cumulative_explained_variance = np.cumsum(explained_variance_ratio)
axs[1].semilogy(grid, cumulative_explained_variance, "o-")
axs[1].set(
xlabel="Component", title="% Cumulative Variance",
xlabel="Component", title="% Cumulative Variance",
)
# Set up figure
fig.set(figwidth=8, dpi=100)
Expand All @@ -207,13 +207,13 @@ def scale_time_parameters_and_asign_to_components(df):
# 800 ms in this case

df['la.delay'] = df['la.delay'] * df['T'] / 800.

df['la.t_tr'] = df['la.t_tr'] * df['T'] / 800.
df['lv.t_tr'] = df['lv.t_tr'] * df['T'] / 800.

df['la.tau'] = df['la.tau'] * df['T'] / 800.
df['lv.tau'] = df['lv.tau'] * df['T'] / 800.

df['la.t_max'] = df['la.t_max'] * df['T'] / 800.
df['lv.t_max'] = df['lv.t_max'] * df['T'] / 800.
return
return
Loading