feat: Add static or dynamic stepsize - #312
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurable step-size strategies for the SDE (Euler–Maruyama) solver and exposes them through the public API and native DSL, enabling fixed, per-event, or adaptive stepping.
Changes:
- Introduces
SdeStepSize(fixed / event-based / adaptive) and routes it into the Euler–Maruyama solver. - Adds builder methods on
equation::SDEandNativeSdeModelto configure step-size behavior. - Re-exports
SdeStepSizeat the crate API level.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/simulator/equation/sde/mod.rs | Threads step-size configuration through the SDE simulation pipeline and adds SDE builder methods. |
| src/simulator/equation/sde/em.rs | Implements SdeStepSize and updates EM solver to support fixed/event/adaptive stepping. |
| src/lib.rs | Re-exports SdeStepSize from the crate prelude surface. |
| src/dsl/native.rs | Adds step-size configuration to the compiled/native SDE model pathway. |
Comments suppressed due to low confidence (2)
src/simulator/equation/sde/em.rs:199
solve_fixedcan enter an infinite loop ifdtis non-finite or <= 0.0 (becausestepbecomes 0/negative/NaN andtnever advances). This should be validated to avoid hangs when users configureSdeStepSize::Fixed(orEventStepsproducing an invaliddt).
fn solve_fixed(&mut self, t0: f64, tf: f64, dt: f64) -> (Vec<f64>, Vec<DVector<f64>>) {
let mut t = t0;
let mut times = vec![t0];
let mut solution = vec![self.state.clone()];
while t < tf {
src/simulator/equation/sde/em.rs:226
solve_adaptiveinitializesdttomax_stepwithout validating bounds and without clamping to the remaining interval before the first attempted step. Iftf - t0 < max_step, the solver can step pasttfand return a final time point >tf; if bounds are non-finite or <= 0, the loop can fail to make forward progress.
let mut t = t0;
let mut dt = max_step;
let safety = 0.9;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| SdeStepSize::EventSteps(n) => { | ||
| let dt = (tf - t0) / n.max(1) as f64; | ||
| self.solve_fixed(t0, tf, dt) | ||
| } |
|
| Project | pharmsol |
| Branch | sde-stepsize |
| Testbed | mhovd-pgx |
🐰 View full continuous benchmarking report in Bencher
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
|
@Siel, not sure if we actually want this in |
No description provided.