Skip to content

feat: Add static or dynamic stepsize - #312

Draft
mhovd wants to merge 1 commit into
mainfrom
sde-stepsize
Draft

feat: Add static or dynamic stepsize#312
mhovd wants to merge 1 commit into
mainfrom
sde-stepsize

Conversation

@mhovd

@mhovd mhovd commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings July 29, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::SDE and NativeSdeModel to configure step-size behavior.
  • Re-exports SdeStepSize at 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_fixed can enter an infinite loop if dt is non-finite or <= 0.0 (because step becomes 0/negative/NaN and t never advances). This should be validated to avoid hangs when users configure SdeStepSize::Fixed (or EventSteps producing an invalid dt).
    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_adaptive initializes dt to max_step without validating bounds and without clamping to the remaining interval before the first attempted step. If tf - t0 < max_step, the solver can step past tf and 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.

Comment on lines +179 to +182
SdeStepSize::EventSteps(n) => {
let dt = (tf - t0) / n.max(1) as f64;
self.solve_fixed(t0, tf, dt)
}
@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpharmsol
Branchsde-stepsize
Testbedmhovd-pgx

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

@mhovd

mhovd commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

@Siel, not sure if we actually want this in main or not, you decide.
I would appreciate if you can check the implementation for the EM solver and the handling of the stepsize, I am in shallow water in that area.

@mhovd mhovd linked an issue Aug 1, 2026 that may be closed by this pull request
@Siel
Siel marked this pull request as draft August 12, 2026 10:19
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.

Add fixed stepsize to the SDE solver

2 participants