Skip to content

Add vectorized solver logic and testing to dev#591

Closed
jc-macdonald wants to merge 68 commits into
mainfrom
dev_add_vectorization
Closed

Add vectorized solver logic and testing to dev#591
jc-macdonald wants to merge 68 commits into
mainfrom
dev_add_vectorization

Conversation

@jc-macdonald
Copy link
Copy Markdown
Collaborator

Describe your changes

This pull request introduces a fully vectorized and Numba-accelerated backend for epidemic simulation logic, located in vectorization_experiments.py. These functions serve as a performance-oriented alternative to the current solver implementation, which relies heavily on nested for-loops and dynamic memory access. The new backend explicitly separates the following components for modular testing and future optimization:

  • Proportion sum and exponentiation logic
  • Transition rate computation from parameter arrays (including symbolic expressions)
  • Transition amount calculation using deterministic rules
  • Flux assembly
  • Solver stepping with fixed dt

All operations are performed over preallocated NumPy arrays and are compatible with fastmath=True in Numba. This enables large performance gains while maintaining model fidelity.

A corresponding test suite is added under tests/steps_rk4/test_vector_build.py. It validates shape agreements, parameter–transition consistency, correct handling of symbolic expressions, and deterministic solver behavior. All tests now pass with real 2-population configuration files as input.

The backend is intended to be drop-in compatible with the current model parsing logic and configuration structure, with no required changes to existing user-facing YAML or CSV files.

A follow-up step will involve benchmarking this vectorized backend against the legacy solver to quantify speedup and memory improvements. We should also discuss where and how to surface this backend in the main package interface, e.g., as a solver="vectorized" option in run_simulation.

Does this pull request make any user interface changes?

No changes to user-facing files or CLI behavior are introduced. This PR is strictly additive: it introduces a new experimental backend and test suite without modifying the current simulation pipeline.

TimothyWillard and others added 30 commits June 30, 2025 17:44
Added a module for representing distributions that can be used
throughout gempyor. Started with `DistributionABC` as and abstract base
for all distributions. Implemented `FixedDistribution` and
`NormalDistribution` using that ABC. Finally, exposed a field
discriminated type to easily create distributions from config.
Added a representation for uniform distributions to
`gempyor.distributions`.
Added a representation of a poisson distribution to
`gempyor.distributions`
Added a representation for binomial distribution to
`gempyor.distributions`.
Added a lognormal distribution to `gempyor.distributions`.
Added a truncated normal distribution to `gempyor.distributions`.
Added a representation for gamma distributions to `gempyor.distributions`
Added a representation for Weibull distributions to `gempyor.distributions`. Also, fixed a return type hint error.
Unit tests and validation for the `NormalDistribution` class in `gempyor_pkg/tests/distributions/`
Unit tests and validation for the `FixedDistribution` class in `gmepyor_pkg/tests/distributions/`. Also removal of an unused parameter in the `FixedDistribution` `.sample()` method.
Unit tests and validation for the `UniformDistribution` class in `gempyor_pkg/tests/distributions/`. Also linting from a previous commit I forgot to add.
Unit tests and validation for the `LognormalDistribution` class in `gempyor_pkg/tests/distributions/` + a fix for an issue that I created in `2c5fce5`
Add tests for the `TruncatedNormalDistribution` class from `gempyor.distributions`. Also, formatting fixes and bound fixes.
Unit tests and validation for `PoissonDIstribution` class in `gempyor.distributions`. Also, formatting and bounds fixes.
Unit tests and validation for the `BinomialDistribution` class in `gempyor.distributions`. Also a bounds fix in `distributions.py`.
Unit tests and validation for the `GammaDistribution` class of `gempyor.distributions`. Also, a bounds fix in `distributions.py`.
Unit tests and validation for the `WeibullDistribution` class of `gempyor.distributions`. Also, bounds and formatting fixes.
Add `BetaDistribution`, de-duplicate `rng` code, remove unnecessary `rng` tests.
…dependency.

`test_spatial_groups()` relies on an inference config file used in the "slow" groups.
These tests are duplicates, which gets addressed in #570 , but for now we need to add both to the slow group to allow workflow success.
Remove old "slow" group, add timing feature to workflow for testing purposes (to be removed later).
Remove temporary time marker to ensure the test timing is appropriate.
Take 10 samples rather than 1 to reduce the risk of an identical series of samples being drawn (causing a test failure when arrays are compared).
use pydantic capabilities for default_factory

Co-authored-by: Timothy Willard <[email protected]>
emprzy and others added 19 commits July 25, 2025 17:29
…ion_from_confuse_config()`

This code is presently broken.
…ion_from_confuse_config()`

This code is presently broken.
Add new `__call__` syntactic sugar to `Distributions`.
…-into-gem.parameters

Incorporate `gempyor.distributions` into `gempyor.parameters`
@jc-macdonald jc-macdonald self-assigned this Jul 30, 2025
@jc-macdonald jc-macdonald added gempyor Concerns the Python core. medium priority Medium priority. performance Performance related improvements, either runtime or memory. labels Jul 30, 2025
@jc-macdonald
Copy link
Copy Markdown
Collaborator Author

closed do to wrong merge base

@jc-macdonald jc-macdonald deleted the dev_add_vectorization branch July 30, 2025 21:27
@jc-macdonald jc-macdonald restored the dev_add_vectorization branch July 30, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gempyor Concerns the Python core. medium priority Medium priority. performance Performance related improvements, either runtime or memory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants