Skip to content

Fix numerical instability in Integral Collocation ODE Solver#439

Open
Mohit-Lakra wants to merge 1 commit intoGeomScale:developfrom
Mohit-Lakra:Fix_integral_collocation
Open

Fix numerical instability in Integral Collocation ODE Solver#439
Mohit-Lakra wants to merge 1 commit intoGeomScale:developfrom
Mohit-Lakra:Fix_integral_collocation

Conversation

@Mohit-Lakra
Copy link
Copy Markdown
Contributor

This PR fixes the instability issues in IntegralCollocationODESolver (Issue #120).

After investigating the solver's behavior, I identified two distinct bugs that were causing the energy explosion:

  1. The Math Fix (Missing Scaling) The core issue was a missing Jacobian scaling factor. The solver integrates on the normalized Chebyshev domain [−1,1] (width 2), but it wasn't scaling the result back to the physical time step [0,η]. This caused the solver to overshoot as if every time step was 2.0 units long, regardless of the actual step size.

Fix: I applied the correct (eta / 2.0) scaling factor to the integration step.

  1. The Logic Fix (Broken Loop) I also found that the fixed-point iteration loop was "short-circuiting." The variable X_prev was being updated to match X immediately before the error check, meaning the calculated error was always 0.0. This forced the solver to exit after just one iteration, preventing true convergence.

Fix: I moved the X_prev update to the start of the loop, ensuring the error metric actually compares the current state against the previous one.

Verification
I verified these fixes locally using a Harmonic Oscillator test case (x '′ =−x).

Before: The system was unstable, with energy growing unboundedly (radius >1.5 within 100 steps).
image

After: The solution is now stable and bounded (radius ≈1.0), confirming the physics are correct.
Screenshot 2026-01-28 at 11 18 48 PM

Closes #120

@Mohit-Lakra
Copy link
Copy Markdown
Contributor Author

@vissarion , the issue should be resolved now with the latest changes.
I’d be grateful for your feedback.

Copy link
Copy Markdown
Member

@vissarion vissarion left a comment

Choose a reason for hiding this comment

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

regression tests are mentioned (e.g. test_instability) but not appear in this PR

@vissarion
Copy link
Copy Markdown
Member

The tests should be included in the PR for reproducibility of the issue.

@Mohit-Lakra
Copy link
Copy Markdown
Contributor Author

@vissarion
Thank you for the feedback. I’ve addressed this by adding the regression test (test_instability) in a subsequent commit, so the PR now includes a reproducible test case for the issue.

@Mohit-Lakra Mohit-Lakra force-pushed the Fix_integral_collocation branch 2 times, most recently from 13ec0f0 to edb85cf Compare January 29, 2026 15:50
@Mohit-Lakra
Copy link
Copy Markdown
Contributor Author

Hi @vissarion, just a quick update

I've updated the PR to handle the "Minimal Build" environment (which lacks FFTW3 and ifopt) while ensuring the test runs correctly in full environments.

Summary of Fixes:

Regression Test: Added test/test_integral_collocation_stability.cpp to verify energy conservation and prevent future instability.

Header Fixes (integral_collocation.hpp):

Included "basis.hpp" and defined BOOST_MATH_USE_FFTW3 to resolve missing type errors.

Guarded nlp_oracles includes with #ifndef DISABLE_NLP_ORACLES to prevent build errors when ifopt is missing.

CMake Configuration:

Wrapped the new test in if(NOT DISABLE_NLP_ORACLES) in test/CMakeLists.txt.

Reason: This ensures the test is skipped during minimal CI builds (where FFTW3 is unavailable) but runs in full builds, resolving the CI failure.

@Mohit-Lakra Mohit-Lakra requested a review from vissarion January 30, 2026 17:01
@Mohit-Lakra Mohit-Lakra force-pushed the Fix_integral_collocation branch 5 times, most recently from 7f3d8de to 3d4cbd1 Compare February 19, 2026 04:42
…cale#120)

Add regression test for stability

Fix CI build: Guard NLP oracle includes

Fix CI build: Guard NLP oracle includes

Add missing headers

Improve build and run instructions for hpolytope-volume example (GeomScale#376)

Fix RK4 stage weighting to keep amplitude bounded (GeomScale#375)

Added test

Restore upstream files — not part of this fix

Restore README to upstream state
@Mohit-Lakra Mohit-Lakra force-pushed the Fix_integral_collocation branch from 61c66d3 to 5f6860b Compare February 19, 2026 04:46
#ifndef ODE_SOLVERS_INTEGRAL_COLLOCATION_HPP
#define ODE_SOLVERS_INTEGRAL_COLLOCATION_HPP

#include "basis.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this needed?

// 5. Apply degree-doubling transformation
// The transformation takes the n Chebyshev transform coefficients c[i]
// and creates a complex polynomial of order 2n with coefficients a[i]
// and creates a complex polynomial of order 2n with coefficients a[i]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unneeded empty space

void set_coord(int i, double val) { coords[i] = val; }
};

struct MockPolytope {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not using an Hpolytope and a point from volesti point class?

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.

Integral Collocation method is numerically unstable

2 participants