Add optional PyO3 Rust core acceleration#48
Merged
Conversation
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.
Motivation
Python Wrapper / Rust Coredesign that keeps RNG in Python and falls back to NumPy when the Rust extension is not available.Description
rust_core/src/lib.rs,Cargo.toml) exposingmulti_potential_gradient_rs,langevin_opinion_update_inplace, andactive_mask_step_rsas deterministic numeric kernels.massive_core/rust_core.pythat imports the compiledmassive_rust_corewhen present and otherwise provides NumPy fallbacks for the same functions.IntegratedSimulator.update_agents_with_langevinnow delegates opinion updates tolangevin_opinion_update_inplace, andActiveSet.stepdelegates toactive_mask_step, preserving previous public APIs and semantics.pyproject.toml,tests/test_rust_core_wrapper.py,docs/rust_core_plan_ES.md) documenting selection criteria, migration plan, and equivalence tests.Testing
cargo testran and passed the Rust unit test(s) for the crate (Rust tests: passed).cargo fmt/cargo fmt --checkwere run and the code was formatted (format check passed after formatting).maturin build --releaseproduced a wheel and the wheel was installed successfully, and importingmassive_rust_coresucceeded (build + import smoke test: passed).pytest tests/test_rust_core_wrapper.pyand the full Python test suitepytest tests/were executed and all tests passed (300 passed, 1 warning).Codex Task
Summary by cubic
Add an optional Rust core (
massive_rust_core) to accelerate hot numeric kernels while preserving the Python API and exact results. Falls back tonumpywhen the extension isn’t present.New Features
massive_rust_core(viapyo3/maturin) exposingmulti_potential_gradient_rs,langevin_opinion_update_inplace, andactive_mask_step_rs.massive_core.rust_corethat uses Rust if available, ornumpyfallbacks otherwise (same signatures and clipping behavior).IntegratedSimulator.update_agents_with_langevinandActiveSet.stepnow delegate to the wrapper without changing public APIs.pyproject.toml.Migration
massive_rust_coreisn’t installed.pip install maturinand runmaturin develop --release(ormaturin build --release) to installmassive_rust_core.Written for commit 4cb7c72. Summary will update on new commits.