Proposal: Migrate the 6-DOF Simulation Core to Rust for Next-Level Performance
Maintainer thường phản hồi trong vòng 3 ngày
Một pull request liên quan đã được merge.
- #1156 của @ting-hong-shieh — đã merge
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
Start by reading the existing Flight integration path and u_dot_generalized, which the proposal identifies as hot-path entry points. The proposed first step is a Maturin workspace with a Rust 2D ballistic integrator benchmarked against the current SciPy implementation; no files, tests, or acceptance criteria are specified. Clarify the scope and success criteria before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Proposal: Migrate the 6-DOF Simulation Core to Rust for Next-Level Performance
Context and Motivation
Recent PRs (like the excellent #1049) have drastically optimized our Function class, but as noted in the benchmarks, the overall simulation speedup is fundamentally bounded by the architecture.
If we profile a typical RocketPy simulation, the major bottleneck is the "boundary crossing" between Python and the underlying ODE solver (like scipy's LSODA). Every time the solver takes a step, it must acquire the Python GIL, convert arrays, and call our Python-based u_dot_generalized (and aerodynamic lookups) thousands of times per flight second.
To break this barrier and achieve orders-of-magnitude speedups, we need to remove the Python interpreter from the hot path entirely.
Proposal: The "Shell and Engine" Architecture
I propose we explore migrating the core mathematical and physical models to Rust, while keeping the user-friendly Python API exactly as it is.
We would adopt a hybrid architecture:
- The Python Shell (
rocketpy): Continues handling the user API, object parsing, file reading,matplotlibplotting, and printing. - The Rust Engine (
rocketpy-core/_rocketpy_rs): A pure-math backend handling the 6-DOF equations of motion, rotation matrices, aerodynamic interpolations, and the numerical integration loop.
When a user calls Flight(...), the Python shell extracts the raw numbers/arrays from the Python objects and hands them to a single Rust function. Rust takes over, runs the entire flight integration instantly (without the GIL), and returns the final trajectory array back to Python for plotting.
Why Rust? (vs. C++ or Cython)
The Python ecosystem is undergoing a massive shift towards Rust. Major projects like Pydantic (V2), Ruff, Polars, and Cryptography have all recently migrated their cores to Rust. The advantages are clear:
- Zero-Setup Cross-Platform Builds: Dealing with MSVC/GCC/Clang compilation across Windows/Linux/macOS in C++ is famously painful. Rust’s
cargoand the Python tool Maturin make cross-platform wheel building in GitHub Actions almost effortless. - The
pip installExperience: Users will simply runpip install rocketpy. They will download pre-compiled.whlbinaries and will not need any Rust compiler installed on their machines. - Memory Safety: If it compiles in Rust, it is virtually immune to the Segmentation Faults and memory leaks that haunt C/Cython extensions.
- PyO3: The PyO3 crate provides an incredibly elegant and safe way to write Python bindings.
A Pragmatic Approach to Numerical Integrators (Keeping LSODA)
One valid concern is losing SciPy's robust LSODA solver and its automatic stiff/non-stiff adaptive time-stepping. Rewriting LSODA from scratch in pure Rust would be an enormous, error-prone academic exercise.
Instead, the most pragmatic engineering approach is to migrate our equations of motion to Rust, and wrap an existing, battle-tested C-implementation of LSODA using Rust's FFI.
By using Rust's build.rs and the cc crate, we can automatically compile a C-version of LSODA alongside our Rust code during the wheel-building process. This means our pure-Rust physics engine can call the C-based LSODA solver in nanoseconds without ever touching the Python GIL. We get the safety and speed of Rust, the maturity of LSODA, and the user still just runs pip install rocketpy seamlessly.
Massive Impact on Monte Carlo (Dispersion)
Currently, our Monte Carlo analysis relies on Python's multiprocessing, which incurs heavy overhead (process spawning, memory duplication, pickle serialization).
By migrating to Rust, we unlock true multithreading. We could eventually pass a list of 10,000 flight parameters to Rust, and using crates like Rayon, run the simulations concurrently across all CPU cores with zero Python overhead. This would make dispersion analysis nearly instantaneous.
Proposed Phased Approach
We shouldn't rewrite everything at once. A safe migration path could be:
- Phase 1 (Proof of Concept): Set up a
maturinproject workspace. Write a simple 2D ballistic trajectory integrator in Rust, import it into Python, and benchmark it against our current SciPy implementation to validate the speedup. - Phase 2 (Core Migration): Migrate
u_dot_generalizedand aerodynamic lookups to Rust. Bind it to a wrapped C-based LSODA solver via FFI. - Phase 3 (Monte Carlo): Expose a vectorized/multithreaded entry point in Rust specifically for dispersion analysis.
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 280
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của RocketPy-Team/RocketPy
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
RocketPy-Team/RocketPy#1255 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
RocketPy-Team/RocketPy#1241 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
RocketPy-Team/RocketPy#1202 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Monte Carlo test fixtures write their logs into the working directoryCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
RocketPy-Team/RocketPy#1189 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
RocketPy-Team/RocketPy#1171 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của RocketPy-Team/RocketPy
Issue tương tự
-
docs(contributing): the two things that silently block a PRCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởavailable documentation good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 95/100
Nixitov/Riptide-Native#944 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
JTHCode/secretguard#24 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: middleware documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainer thường phản hồi trong vòng 1 ngày