[fix] Combine solver solution with time offset#809
Open
Conversation
Collaborator
Author
|
I'm getting similar results with this and main at hash d39be4d
|
Collaborator
Author
|
Output from this branch: Output from main at d39be4d There are some differences in the exact solutions between these two, but they're closer than the current main: I hope we can solve this quickly |
sgossage
reviewed
Feb 17, 2026
Comment on lines
+115
to
+124
| if len(sol) == 1: | ||
| output_solution = CombinedSolution() | ||
| output_solution.t = sol[0].t + t0 | ||
| output_solution.y = sol[0].y | ||
| output_solution.status = sol[0].status | ||
| output_solution.message = sol[0].message | ||
| output_solution.t_events = sol[0].t_events | ||
| output_solution.y_events = sol[0].y_events | ||
| output_solution.success = sol[0].success | ||
| output_solution.sol = lambda t: sol[0].sol(t-t0) |
Contributor
There was a problem hiding this comment.
Suggested change
| if len(sol) == 1: | |
| output_solution = CombinedSolution() | |
| output_solution.t = sol[0].t + t0 | |
| output_solution.y = sol[0].y | |
| output_solution.status = sol[0].status | |
| output_solution.message = sol[0].message | |
| output_solution.t_events = sol[0].t_events | |
| output_solution.y_events = sol[0].y_events | |
| output_solution.success = sol[0].success | |
| output_solution.sol = lambda t: sol[0].sol(t-t0) |
sgossage
reviewed
Feb 17, 2026
Comment on lines
+127
to
+142
| else: | ||
| output_solution = CombinedSolution() | ||
| output_solution.t = np.concatenate([t0+t.t for t, t0 in zip(sol, time_sol)]) | ||
| output_solution.y = np.hstack([s.y for s in sol]) | ||
| output_solution.status = sol[-1].status | ||
| output_solution.message = sol[-1].message | ||
| output_solution.t_events = sol[-1].t_events | ||
| output_solution.y_events = sol[-1].y_events | ||
| output_solution.success = sol[-1].success | ||
|
|
||
| # dynamically create a combined sol method that can interpolate across the combined solution | ||
| def combined_sol(t): | ||
| for s, t0 in zip(sol, time_sol): | ||
| if t0 <= t <= t0 + s.t[-1]: | ||
| return s.sol(t - t0) | ||
| raise ValueError(f"Time {t} is out of bounds for the combined solution.") |
Contributor
There was a problem hiding this comment.
Suggested change
| else: | |
| output_solution = CombinedSolution() | |
| output_solution.t = np.concatenate([t0+t.t for t, t0 in zip(sol, time_sol)]) | |
| output_solution.y = np.hstack([s.y for s in sol]) | |
| output_solution.status = sol[-1].status | |
| output_solution.message = sol[-1].message | |
| output_solution.t_events = sol[-1].t_events | |
| output_solution.y_events = sol[-1].y_events | |
| output_solution.success = sol[-1].success | |
| # dynamically create a combined sol method that can interpolate across the combined solution | |
| def combined_sol(t): | |
| for s, t0 in zip(sol, time_sol): | |
| if t0 <= t <= t0 + s.t[-1]: | |
| return s.sol(t - t0) | |
| raise ValueError(f"Time {t} is out of bounds for the combined solution.") | |
| output_solution = CombinedSolution() | |
| output_solution.t = np.concatenate([t0+s.t for s, t0 in zip(sol, time_sol)]) | |
| output_solution.y = np.hstack([s.y for s in sol]) | |
| output_solution.status = sol[-1].status | |
| output_solution.message = sol[-1].message | |
| output_solution.t_events = sol[-1].t_events | |
| output_solution.y_events = sol[-1].y_events | |
| output_solution.success = sol[-1].success | |
| # dynamically create a combined sol method that can interpolate across the combined solution | |
| def combined_sol(t): | |
| for s, t0 in zip(sol, time_sol): | |
| if t0 <= t <= t0 + s.t[-1]: | |
| return s.sol(t - t0) | |
| raise ValueError(f"Time {t} is out of bounds for the combined solution.") |
Contributor
There was a problem hiding this comment.
maybe move this into a function
sgossage
reviewed
Feb 17, 2026
| return s.sol(t - t0) | ||
| raise ValueError(f"Time {t} is out of bounds for the combined solution.") | ||
|
|
||
| output_solution.sol = combined_sol |
Contributor
There was a problem hiding this comment.
Suggested change
| output_solution.sol = combined_sol | |
| output_solution.sol = combined_sol |
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.

For DCO we're doing multiple solves. We tried to implement a fix by changing the solver range to correctly account for the evolution time. However, this causes issues due to the scale differences in time that the equations evolve over.
We were doing multiple iterations of
solve_ivpto account for this time scale difference. The fix did not account for this and ends up causing systems within thedouble_COstep to fail.Here I re-implement the old method of solving the ODE's in multiple steps.
To propagate the changes to after the evolution in
step_detached, I create a "fake" solution object combines the multiple solves into a single result object with similar attributes/functions as the originalsolve_ivpobject.