Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
81bed7a
#285 Bump up to Python 3.10-compatible dependencies
kwabenantim Jul 15, 2026
e944ead
#285 Pin Pint to 0.25.3 in the dev requirements
kwabenantim Jul 15, 2026
615b4b6
#285 Fix model loading on sympy 1.12 and later
kwabenantim Jul 15, 2026
008108f
#285 Select test reference files per sympy version
kwabenantim Jul 15, 2026
dfc6adf
#285 Add per-sympy-version variants of the generated code references
kwabenantim Jul 15, 2026
7af23b3
#285 Version jacobian references and remove version-specific excludes
kwabenantim Jul 15, 2026
ffad5e3
#285 Document the versioned reference scheme
kwabenantim Jul 15, 2026
2032a4d
#285 Bump minimum Python to 3.10
kwabenantim Jul 15, 2026
81bb1b7
#285 Fix docs grammar and formatting
kwabenantim Jul 15, 2026
1533699
#285 Declare Python 3.10-3.14 support in metadata and docs
kwabenantim Jul 15, 2026
fb5ce1d
#285 Version linearity-check and lookup-table references per sympy ve…
kwabenantim Jul 16, 2026
732fce4
#285 Add per-sympy-version console-script and string reference variants
kwabenantim Jul 16, 2026
46736ff
#285 Version the partial-eval reference per sympy version
kwabenantim Jul 16, 2026
6dc6ae7
#285 Fix printer 1.0 comparison
kwabenantim Jul 17, 2026
2064cd2
#285 Regenerate per-sympy reference variants and version jacobian ref…
kwabenantim Jul 17, 2026
c3e2e61
#285 Use structural is_zero for sqrt exponent check and regenerate af…
kwabenantim Jul 17, 2026
a478d52
#285 Use structural is_zero for reciprocal and division checks in loo…
kwabenantim Jul 17, 2026
23e1151
#285 Fix release.txt references
kwabenantim Jul 17, 2026
f5deb05
#285 Parse sympy version with a regex to tolerate pre-release formats
kwabenantim Jul 17, 2026
ee63b09
#285 Pair each Python version with a specific sympy version in CI
kwabenantim Jul 18, 2026
dd1b001
#285 Require cellmlmanip >= 0.3.8
kwabenantim Jul 20, 2026
966a244
#285 Rebase base references to Python 3.10 output and add sympy_1_11 …
kwabenantim Jul 20, 2026
cd2034c
#285 Use flake extend-exclude
kwabenantim Jul 21, 2026
af4051f
#285 Accept any matching reference variant and rename ordering varian…
kwabenantim Jul 21, 2026
8e5fbda
Potential fix for pull request finding
mirams Jul 21, 2026
f0d6978
Apply suggestions from code review
mirams Jul 21, 2026
95e5859
#285 Remove stale tests path from isort step
kwabenantim Jul 22, 2026
88941af
#285 Refactor and document test reference-comparison helpers
kwabenantim Jul 22, 2026
004db77
#285 Move reference-comparison harness tests into test_conftest.py
kwabenantim Jul 22, 2026
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
12 changes: 8 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ ignore =
# break before binary operator - allow either style
W504,
# break after binary operator - allow either style
exclude=
.git,

extend-exclude =
.venv,
build,
dev-requirements,
venv,
build,
dist,
*.egg-info,
.pytest_cache,
.mypy_cache,
.ipynb_checkpoints,
18 changes: 15 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
include:
- python-version: "3.10"
sympy-version: "1.10"
- python-version: "3.11"
sympy-version: "1.11"
- python-version: "3.12"
sympy-version: "1.12"
- python-version: "3.13"
sympy-version: "1.13"
- python-version: "3.14"
sympy-version: "1.14"
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v6
uses: actions/checkout@v7
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -20,12 +31,13 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install flake8 pytest
python3 -m pip install .[test]
python3 -m pip install "sympy==${{ matrix.sympy-version }}"
- name: Lint with flake8
Comment thread
kwabenantim marked this conversation as resolved.
run: |
python3 -m flake8
- name: Test sorting with isort
run: |
python3 -m isort --verbose --check-only --diff chaste_codegen tests setup.py
python3 -m isort --verbose --check-only --diff chaste_codegen setup.py
- name: Test with pytest
run: |
python3 -m pytest --cov --cov-config=.coveragerc
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $ flake8
```

## Python version
Python 3.5+
Python 3.10+

## Documentation

Expand Down
4 changes: 2 additions & 2 deletions chaste_codegen/_chaste_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _print_ordinary_pow(self, expr):
""" Handles Pow(), handles just ordinary powers without division.
For C++ printing we need to write ``x**y`` as ``pow(x, y)`` with lowercase ``p``."""
p = precedence(expr)
if expr.exp == 0.5:
if (expr.exp - S.Half).is_zero: # expr.exp == 0.5
return 'sqrt(' + self._bracket(expr.base, p) + ')'
return 'pow(' + self._bracket(expr.base, p) + ', ' + self._bracket(expr.exp, p) + ')'

Expand Down Expand Up @@ -185,7 +185,7 @@ def _print_Mul(self, expr):
# Gather terms for numerator and denominator
a, b = [], []
for item in Mul.make_args(expr):
if item != 1.0: # In multiplications remove 1.0 * ...
if not (item - S.One).is_zero: # In multiplications remove 1.0 * ...
# Check if this is a negative power and it's not in a lookup table, so we can write it as a division
if (item.is_commutative and item.is_Pow and item.exp.is_Rational and item.exp.is_negative
and not self.lookup_table_function(item)):
Expand Down
3 changes: 2 additions & 1 deletion chaste_codegen/_linearity_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Mul,
Piecewise,
Pow,
S,
log,
)
from sympy.codegen.cfunctions import log2, log10
Expand Down Expand Up @@ -101,7 +102,7 @@ def max_kind(state_var, operands):
elif isinstance(expr, Pow):
if state_var not in expr.free_symbols:
result = max_kind(state_var, operands)
elif len(expr.args) == 2 and expr.args[1] == -1: # x/y divide is represented as x * pow(y, -1)
elif len(expr.args) == 2 and (expr.args[1] + S.One).is_zero: # x/y divide is represented as x * pow(y, -1)
# Linear iff only numerator linear
result = _check_expr(expr.args[0], state_var, membrane_voltage_var, state_vars)
else:
Expand Down
3 changes: 2 additions & 1 deletion chaste_codegen/_lookup_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sympy import (
Piecewise,
Pow,
S,
Symbol,
acos,
acosh,
Expand Down Expand Up @@ -132,7 +133,7 @@ def _set_lookup_table_if_appropriate(self, exp_func, vars_used, expr, in_pw):

# Prevent putting expressions of the form 1 / A since the expressions might cause a singularity in the table
# since expressions being analised might the bottom of a GHK equation os similar
if isinstance(expr, Pow) and expr.args[1] == -1.0:
if isinstance(expr, Pow) and (expr.args[1] + S.One).is_zero: # ... and expr.args[1] == -1.0
expr = expr.args[0]

if exp_func and expr not in self._lookup_table_expr and \
Expand Down
3 changes: 2 additions & 1 deletion chaste_codegen/_math_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def fdiff(self, argindex=1):


# MATH_FUNC_SYMPY_MAPPING provides a mapping from our specified math functions back to sympy versions.
# This can be used to put sympy function into an expression or evaluation. e.g. `expr.subs(MATH_FUNC_SYMPY_MAPPING)`.
# Apply it via subs_math_func_placeholders(), which uses expr.replace(). Do not use expr.subs() with this
# mapping as sympy >= 1.12 strictly sympifies the substitution values and rejects e.g. the sqrt function.
MATH_FUNC_SYMPY_MAPPING = {abs_: Abs, acos_: acos, cos_: cos, exp_: exp, sin_: sin, sqrt_: sqrt}


Expand Down
Loading