Skip to content

Add conditions to analytic integrators#93

Merged
clinssen merged 25 commits into
nest:mainfrom
clinssen:conditional-propagators
Jun 3, 2026
Merged

Add conditions to analytic integrators#93
clinssen merged 25 commits into
nest:mainfrom
clinssen:conditional-propagators

Conversation

@clinssen

@clinssen clinssen commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

The current ODE-toolbox release detects conditions under which singularities can occur. This PR adds a feature that allows ODE-toolbox to generate separate solvers for each of these conditions.

Please see the rendered documentation at: https://ode-toolbox-sandbox.readthedocs.io/en/latest
For an overview of changes to the documentation, please see the diff of the file index.rst: https://github.com/nest/ode-toolbox/pull/93/files#diff-3161f66a61b9ed68303607f1dbdce1c7bdcc69c42f8ea1c2051a07a579ebcf5d

N.B. after merging this, the version number of ODE-toolbox should be bumped to 3.0.0, as this feature changes the external API.

Notes for reviewers:

  • The fact that sympy variables are real numbers needs to be (and is now) explicitly set in many places by passing real=True to the sympy.Symbol constructor.
  • Split off testing requirements into a separate requirements-testing.txt.
  • Sadly, the old 1.10.1 sympy version gets stuck on test_analytic_solver_integration.py and introduces numerical errors, so I've set the test to skip for older versions and added a line into the documentation.
  • pycodestyle no longer ignores E303 (too many blank lines)

Replaces #89.

@clinssen clinssen marked this pull request as draft October 6, 2025 11:40
@clinssen clinssen force-pushed the conditional-propagators branch from 827de32 to bd883ac Compare October 16, 2025 22:11
@clinssen clinssen added this to the v3.0.0 milestone Oct 17, 2025
@clinssen clinssen force-pushed the conditional-propagators branch from 1020b1b to 74ebe4d Compare October 23, 2025 11:26
@clinssen clinssen marked this pull request as ready for review February 25, 2026 12:43
Comment thread odetoolbox/singularity_detection.py Outdated

@pnbabu pnbabu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this feature! I have a few minor comments.

Comment thread odetoolbox/sympy_helpers.py Outdated
assert type(expr) is str

if global_dict:
global_dict = global_dict.copy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why copy the dict to the same variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sympy will internally sneakily add items to this dict when it's passed to parse_expr().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you pass the same dict to sympy parse on L45, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this! I have added clearer naming (global_dict_copy) and made an extra copy for the initial and second pass.

Comment thread odetoolbox/analytic_integrator.py Outdated
Comment thread odetoolbox/singularity_detection.py Outdated
Comment thread odetoolbox/singularity_detection.py Outdated
Comment thread odetoolbox/system_of_shapes.py
initial_parse = sympy.parsing.sympy_parser.parse_expr(expr, global_dict=global_dict, local_dict=local_dict, evaluate=evaluate)
global_dict_copy = global_dict.copy()

initial_parse = sympy.parsing.sympy_parser.parse_expr(expr, global_dict=global_dict_copy, local_dict=local_dict, evaluate=evaluate)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this fail if global_dict is not present and therefore global_dict_copy is unassigned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, sorry about that—fixed now!

@clinssen clinssen requested a review from pnbabu June 2, 2026 17:09

@pnbabu pnbabu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good me, thank you!

@clinssen

clinssen commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Thank you very much for the review!

@clinssen clinssen merged commit 26415f7 into nest:main Jun 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants