Solver and penalties update#22
Merged
Merged
Conversation
Updated NeuralBase and derived classes to allow passing custom solver types and stepsize controllers, improving flexibility for ODE integration. Added support for runtime selection of solver, rtol, atol, and dt0 parameters. Refactored __call__ methods and internal helper functions to instantiate solvers and controllers as needed.
Introduces a new penalty function, penalize_null_space, to encourage the stoichiometric matrix to have a null space of zero. Integrates this penalty into the Penalties class for NeuralRDE models, allowing configuration via null_space_alpha.
Enhanced grid styling for the rate magnitude subplot by enabling both major and minor grids with custom appearance. Updated the model fit plotting to include predicted measurements for better comparison.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces significant improvements to the neural modeling framework by adding solver flexibility, penalty extensions, and model configuration enhancements. The main focus is on enabling dynamic solver selection and configuration at runtime, along with new penalty functions for stoichiometric matrices.
- Refactored all neural model classes to support dynamic solver configuration (type, rtol, atol, dt0) in both
__call__andpredictmethods - Added null space penalty for stoichiometric matrices to enforce conservation laws
- Enhanced RateFlowODE initialization with mass constraint validation and equinox field annotations
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test.py | Simple test script demonstrating model creation and parameter flattening |
| catalax/neural/neuralbase.py | Core refactoring for solver flexibility with helper methods and abstract interface |
| catalax/neural/neuralode.py | Updated to use new dynamic solver configuration system |
| catalax/neural/rateflow.py | Enhanced with mass constraint validation, equinox fields, and solver flexibility |
| catalax/neural/universalode.py | Updated to support dynamic solver configuration |
| catalax/neural/penalties/stoich_mat.py | Added new null space penalty function |
| catalax/neural/penalties/penalties.py | Integrated null space penalty into penalty collection |
| catalax/neural/plots/rateflow.py | Improved grid display and model prediction overlay |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The default value for the reaction_size field in RateFlowODE was removed, making it a required argument. This change clarifies the initialization requirements for the class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and new features to the neural modeling codebase, focusing on solver flexibility, penalty extensions, and model configuration. The most significant changes are the refactoring of solver handling to allow dynamic selection and configuration, the addition of a null space penalty for stoichiometric matrices, and enhancements to model initialization and plotting.
Solver Flexibility and API Improvements
NeuralBase,NeuralODE,RateFlowODE,UniversalODE) to allow passing the solver type and its configuration (rtol, atol, dt0) dynamically, both in__call__andpredictmethods. This enables users to select and configure ODE solvers at runtime, improving flexibility and usability. Helper methods_create_controllerand_instantiate_solverwere added for controller and solver instantiation. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]Penalty Extensions for Stoichiometric Matrices
penalize_null_spaceto encourage the stoichiometric matrix to have a null space of zero, which can be used to enforce physical constraints (e.g., conservation laws). Integrated this penalty into thefor_rateflowpenalty collection, allowing it to be configured vianull_space_alpha. [1] [2] [3] [4]Model Initialization and Configuration
RateFlowODEinitialization to accept and validate amass_constraintmatrix, ensuring it matches the species count and enforcing shape requirements. This supports more robust modeling of conservation laws. Also, model fields now useequinoxfield annotations for better static/dynamic parameter handling. [1] [2] [3]Plotting Enhancements
plot_learned_ratesby improving grid display (major and minor ticks) and updating the right panel to overlay model predictions with measurements for clearer visualization.Miscellaneous
test.pydemonstrating model creation, neural ODE instantiation, and parameter flattening for debugging or analysis.