Skip to content

Conversation

@Routhleck
Copy link

@Routhleck Routhleck commented Feb 1, 2025

This pull request introduces several modifications to the catalax package, focusing on integrating the brainunit library for handling quantities and units, and adding functionality to the model and plotting modules. The most important changes include updating the MCMC and model simulation functions to support quantities, enhancing the plotting functions to display units, and adding new methods for model configuration.

Technical Compatibility Notes
Current implementation faces version dependency conflicts between Catalax and recent updates of Diffrax-related packages, which disrupt neural network functionalities. For unit-aware differential equation solving in BrainUnit integration, the workflow relies on diffraxu, a fork of Diffrax modified to natively handle physical units via brainunit.

Additionally, Markov Chain Monte Carlo (MCMC) operations require explicit unit stripping:

  • Pre-processing: Convert all Quantity objects to raw numerical values before sampling.
  • Post-processing: Reattach units to numerical outputs after computation.

Critical Limitation
This approach bypasses (but does not resolve) the underlying incompatibility between Catalax's dependency constraints and newer Diffrax versions.

Integration of brainunit library:

  • catalax/mcmc/mcmc.py: Updated to use brainunit.Quantity for data conversion and unit consistency checks in the run_mcmc function. [1] [2]
  • catalax/mcmc/priors.py: Added unit attribute to the Prior class and updated prior distributions to support Quantity types. [1] [2]

Enhancements to model simulation:

  • catalax/model/model.py: Updated the simulate function to handle Quantity types for initial conditions and added an origin_solve parameter to force re-setup of the simulation system. [1] [2]
  • Added a new add_term method to the model class for adding terms to the model.

Improvements to plotting functions:

These changes improve the handling of physical quantities in simulations and visualizations, ensuring consistency and clarity in the results.

Routhleck and others added 3 commits December 27, 2024 14:49
* Update

* Update

* Update

* Update

* Fail to support mcmc

* Little try mcmc

* Run HMC successfully

* Neural ode original code will report an error

* Update optimization

* Update Optimization

* Update README.md

* Update README.md

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Routhleck Routhleck changed the title [feat] Integrate with brainunit to provide physical units and unit-aware mathematical system [feat] Integrate with brainunit to provide physical units and unit-aware mathematical handing Feb 1, 2025
@JR-1991
Copy link
Owner

JR-1991 commented Feb 6, 2025

Thanks @Routhleck for the awesome contribution! I will review and test your PR beginning of next week and get back to you asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants