Skip to content

Commit 9f18de3

Browse files
authored
Merge pull request #51 from ComputationalPhysiology/gotranx-support
Add support for gotranx and switch from setup.cfg to pyproject.toml
2 parents 209d401 + 617c079 commit 9f18de3

11 files changed

Lines changed: 320 additions & 76 deletions

File tree

.github/workflows/github-pages.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v5
1313

1414
- name: Setup Python
15-
uses: actions/setup-python@v2
15+
uses: actions/setup-python@v6
1616
with:
17-
python-version: "3.9"
17+
python-version: "3.12"
1818

1919
- name: Upgrade pip
2020
run: |
@@ -29,7 +29,7 @@ jobs:
2929
make docs
3030
3131
- name: Deploy
32-
uses: peaceiris/actions-gh-pages@v3
32+
uses: peaceiris/actions-gh-pages@v4
3333
with:
3434
github_token: ${{ secrets.GITHUB_TOKEN }}
3535
publish_dir: ./docs/build/html

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.10"]
10+
python-version: ["3.10", "3.13"]
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v5
1313
- name: Set up Python ${{ matrix.python-version }}
14-
uses: actions/setup-python@v5
14+
uses: actions/setup-python@v6
1515
with:
1616
python-version: ${{ matrix.python-version }}
1717
- name: Install package

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
.DS_Store
2+
docs/source/hodgkin_huxley_gotranx.md
23
demo/*.png
34
demo/*.dot
45
docs/source/hodgkin_huxley.md

.pre-commit-config.yaml

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,28 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v6.0.0
44
hooks:
5-
- id: check-yaml
6-
- id: end-of-file-fixer
75
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
89
- id: check-docstring-first
910
- id: debug-statements
11+
- id: check-toml
1012

11-
- repo: https://github.com/asottile/reorder-python-imports
12-
rev: v3.16.0
13-
hooks:
14-
- id: reorder-python-imports
15-
exclude: ^demo/
16-
17-
- repo: https://github.com/psf/black-pre-commit-mirror
18-
rev: 25.9.0
19-
hooks:
20-
- id: black
21-
22-
- repo: https://github.com/pre-commit/pre-commit-hooks
23-
rev: v2.0.0
24-
hooks:
25-
- id: flake8
26-
27-
- repo: https://github.com/asottile/add-trailing-comma
28-
rev: v4.0.0
29-
hooks:
30-
- id: add-trailing-comma
31-
32-
- repo: https://github.com/asottile/setup-cfg-fmt
33-
rev: v3.1.0
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
# Ruff version.
15+
rev: 'v0.14.1'
3416
hooks:
35-
- id: setup-cfg-fmt
17+
# Run the linter.
18+
- id: ruff-check
19+
args: [ --fix ]
20+
# Run the formatter.
21+
- id: ruff-format
3622

3723
- repo: https://github.com/pre-commit/mirrors-mypy
3824
rev: v1.18.2
3925
hooks:
4026
- id: mypy
27+
additional_dependencies: ["types-attrs"]
28+
files: ^src/|^tests/
29+
args: ["--config-file", "pyproject.toml"]

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ docs: ## generate Sphinx HTML documentation, including API docs
6969
rm -f docs/source/modelgraph.rst´
7070
rm -f docs/source/modules.rst
7171
jupytext demo/hodgkin_huxley.py -o docs/source/hodgkin_huxley.md
72+
jupytext demo/hodgkin_huxley_gotranx.py -o docs/source/hodgkin_huxley_gotranx.md
7273
sphinx-apidoc -o docs/source src/modelgraph
7374
cd docs && make html
7475

demo/hodgkin_huxley.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# # Demo
1+
# # Demo gotran
22
#
3-
# In this demo we will demonstrate how you can use the python API to visualize the dependencies in the Hodgkin Huxley model of the squid axon from 1952. This model is taken from <https://models.cellml.org/workspace/hodgkin_huxley_1952> and converted to a gotran `.ode` file using `gotran` and the `cellml2gotran` script
3+
# In this demo we will demonstrate how you can use the python API to visualize the dependencies
4+
# in the Hodgkin Huxley model of the squid axon from 1952. This model is taken
5+
# from <https://models.cellml.org/workspace/hodgkin_huxley_1952> and converted to a
6+
# gotran `.ode` file using `gotran` and the `cellml2gotran` script
47
#
58
# First we make the necessary imports
69

demo/hodgkin_huxley_gotranx.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# # Demo gotranx
2+
#
3+
# In this demo we will demonstrate how you can use the python API to visualize the dependencies
4+
# in the Hodgkin Huxley model of the squid axon from 1952. This model is taken
5+
# from <https://models.cellml.org/workspace/hodgkin_huxley_1952> and converted to a
6+
# gotran `.ode` file using `gotran` and the `cellml2gotran` script
7+
#
8+
# First we make the necessary imports
9+
10+
import gotranx
11+
import matplotlib.pyplot as plt
12+
import networkx as nx
13+
from modelgraph import DependencyGraph
14+
15+
# and load the ode file
16+
17+
ode = gotranx.load_ode("hodgkin_huxley_squid_axon_model_1952_original.ode")
18+
19+
# Next we build the dependency graph
20+
21+
graph = DependencyGraph(ode)
22+
23+
# and get the graph of the expressions that depends on the parameter `g_Na`
24+
25+
G_g_Na = graph.inv_dependency_graph("g_Na")
26+
27+
# We plot this using `matplotlib`
28+
29+
nx.draw(G_g_Na, with_labels=True, font_size=10, node_size=2000)
30+
plt.savefig("g_Na_mpl_gotranx.png")
31+
32+
# ![_](_static/g_Na_mpl.png)
33+
#
34+
# and using `pydot`
35+
36+
P_g_Na = nx.nx_pydot.to_pydot(G_g_Na)
37+
P_g_Na.write_png("g_Na_pydot_gotranx.png")
38+
39+
# ![_](_static/g_Na_pydot.png)
40+
#
41+
# Finally we grab the graph of the dependencies of `dV_dt`
42+
43+
# Visualize what dV_dt depdens on
44+
G_dV_dt = graph.dependency_graph("dV_dt")
45+
# and visualize this using `pydot`
46+
#
47+
48+
P_dV_dt = nx.nx_pydot.to_pydot(G_dV_dt)
49+
P_dV_dt.write_png("dV_dt_pydot_gotranx.png")
50+
51+
# ![_](_static/dV_dt_pydot.png)

docs/source/index.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
|codecov| |CI| |github pages| |pre-commit.ci status|
1+
|CI| |github pages| |pre-commit.ci status|
22

33
modelgraph
44
==========
@@ -29,10 +29,10 @@ code snippet
2929
.. code:: python
3030
3131
from modelgraph import DependencyGraph
32-
import gotran
32+
import gotranx
3333
3434
# Load ode using gotran
35-
ode = gotran.load_ode("hodgkin_huxley_squid_axon_model_1952_original.ode")
35+
ode = gotranx.load_ode("hodgkin_huxley_squid_axon_model_1952_original.ode")
3636
# Build dependency graph
3737
graph = DependencyGraph(ode)
3838
# Get the components that depends on g_Na (we call this inverse dependents)
@@ -139,8 +139,6 @@ License
139139

140140
MIT
141141

142-
.. |codecov| image:: https://codecov.io/gh/ComputationalPhysiology/modelgraph/branch/main/graph/badge.svg?token=C4YKKMJ4H8
143-
:target: https://codecov.io/gh/ComputationalPhysiology/modelgraph
144142
.. |CI| image:: https://github.com/ComputationalPhysiology/modelgraph/actions/workflows/main.yml/badge.svg
145143
:target: https://github.com/ComputationalPhysiology/modelgraph/actions/workflows/main.yml
146144
.. |github pages| image:: https://github.com/ComputationalPhysiology/modelgraph/actions/workflows/github-pages.yml/badge.svg
@@ -154,6 +152,7 @@ MIT
154152
:caption: Contents:
155153

156154
hodgkin_huxley
155+
hodgkin_huxley_gotranx
157156
modules
158157

159158

pyproject.toml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
[build-system]
2+
requires = ["setuptools>=61.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "modelgraph"
7+
version = "1.0.1"
8+
description = "Tool for extracting dependency graphs from gotran ODE models"
9+
authors = [{name = "Henrik Finsberg", email = "henriknf@simula.no"}]
10+
license = {text = "MIT"}
11+
classifiers = [
12+
"License :: OSI Approved :: MIT License",
13+
"Programming Language :: Python :: 3",
14+
"Programming Language :: Python :: 3 :: Only",
15+
]
16+
keywords = ["ODE", "models", "graphs", "dependencies"]
17+
requires-python = ">=3.8"
18+
dependencies = [
19+
"click",
20+
"networkx",
21+
"pydot",
22+
"importlib-metadata;python_version<'3.8'",
23+
]
24+
25+
[project.readme]
26+
file = "README.md"
27+
content-type = "text/markdown"
28+
29+
[project.urls]
30+
Homepage = "https://github.com/ComputationalPhysiology/modelgraph"
31+
32+
[project.optional-dependencies]
33+
dev = [
34+
"Sphinx",
35+
"black",
36+
"build",
37+
"bump2version",
38+
"flake8",
39+
"ipython",
40+
"isort",
41+
"mypy",
42+
"pdbpp",
43+
"pip",
44+
"pre-commit",
45+
"sphinx",
46+
"twine",
47+
"wheel",
48+
]
49+
docs = [
50+
"Sphinx",
51+
"jupytext",
52+
"myst-parser",
53+
"gotran",
54+
"gotranx",
55+
"sphinx-press-theme",
56+
]
57+
gui = ["streamlit"]
58+
plot = [
59+
"matplotlib",
60+
"pydot",
61+
]
62+
test = [
63+
"gotran",
64+
"gotranx",
65+
"pytest",
66+
"pytest-cov",
67+
]
68+
69+
[tool.setuptools]
70+
package-dir = {"" = "src"}
71+
zip-safe = false
72+
license-files = ["LICENSE"]
73+
include-package-data = false
74+
75+
[tool.setuptools.packages.find]
76+
where = ["src"]
77+
namespaces = false
78+
79+
[tool.flake8]
80+
exclude = "docs"
81+
ignore = "E203, E266, E501, W503, E731"
82+
max-line-length = "88"
83+
max-complexity = "18"
84+
select = "B,C,E,F,W,T4"
85+
86+
[tool.aliases]
87+
test = "pytest"
88+
89+
[tool.pytest.ini_options]
90+
addopts = "--cov=src/modelgraph --cov-report html --cov-report xml --cov-report term-missing -v"
91+
testpaths = ["tests"]
92+
93+
[tool.mypy]
94+
files = ["src/modelgraph", "tests"]
95+
ignore_missing_imports = true
96+
exclude = "docs"
97+
98+
[tool.coverage.run]
99+
omit = [
100+
"src/modelgraph/gui.py",
101+
"src/modelgraph/cli.py",
102+
"src/modelgraph/__main__.py",
103+
]
104+
105+
106+
[tool.ruff]
107+
108+
# Exclude a variety of commonly ignored directories.
109+
exclude = [
110+
"examples",
111+
".bzr",
112+
".direnv",
113+
".eggs",
114+
".git",
115+
".hg",
116+
".mypy_cache",
117+
".nox",
118+
".pants.d",
119+
".pytype",
120+
".ruff_cache",
121+
".svn",
122+
".tox",
123+
".venv",
124+
"__pypackages__",
125+
"_build",
126+
"buck-out",
127+
"build",
128+
"dist",
129+
"node_modules",
130+
"venv",
131+
"submit.py"
132+
]
133+
134+
# Same as Black.
135+
line-length = 110
136+
137+
# Assume Python 3.10.
138+
target-version = "py310"
139+
140+
[tool.ruff.lint]
141+
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
142+
select = ["E", "F"]
143+
ignore = ["E402", "E741", "E743", "E731"]
144+
145+
# Allow autofix for all enabled rules (when `--fix`) is provided.
146+
fixable = ["A", "B", "C", "D", "E", "F"]
147+
unfixable = []
148+
149+
# Allow unused variables when underscore-prefixed.
150+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
151+
152+
153+
[tool.ruff.lint.mccabe]
154+
# Unlike Flake8, default to a complexity level of 10.
155+
max-complexity = 10

0 commit comments

Comments
 (0)