Skip to content

Conversation

ErikQQY
Copy link
Member

@ErikQQY ErikQQY commented Jul 14, 2025

Part of #336

Some TODOs:

  • Multi-points BVP are encountering some DI issues, but two-point BVP are fine, need to dig deeper to see what's going wrong.
  • Need some patches in SciMLBase.jl and DiffEqBase.jl for better interface.
  • More docstrings and documentations

Copy link
Contributor

github-actions bot commented Jul 14, 2025

Benchmark Results

Click to check benchmark results
master 8a6fc74... master / 8a6fc74...
Simple Pendulum/IIP/BoundaryValueDiffEqMIRK.MIRK2() 0.582 ± 0.015 s 0.587 ± 0.015 s 0.992 ± 0.037
Simple Pendulum/IIP/BoundaryValueDiffEqMIRK.MIRK3() 13.5 ± 0.57 ms 13.6 ± 0.54 ms 0.991 ± 0.057
Simple Pendulum/IIP/BoundaryValueDiffEqMIRK.MIRK4() 3.11 ± 0.16 ms 3.13 ± 0.19 ms 0.993 ± 0.078
Simple Pendulum/IIP/BoundaryValueDiffEqMIRK.MIRK5() 9.19 ± 1.3 ms 9.28 ± 1.3 ms 0.99 ± 0.2
Simple Pendulum/IIP/BoundaryValueDiffEqMIRK.MIRK6() 1.6 ± 0.2 ms 1.62 ± 0.29 ms 0.989 ± 0.22
Simple Pendulum/IIP/MultipleShooting(10, Tsit5; grid_coarsening = false) 1.86 ± 0.66 ms 1.9 ± 0.66 ms 0.979 ± 0.49
Simple Pendulum/IIP/MultipleShooting(10, Tsit5; grid_coarsening = true) 3.14 ± 0.99 ms 3.16 ± 0.97 ms 0.994 ± 0.44
Simple Pendulum/IIP/MultipleShooting(100, Tsit5; grid_coarsening = false) 0.0672 ± 0.0068 s 0.0676 ± 0.007 s 0.994 ± 0.14
Simple Pendulum/IIP/MultipleShooting(100, Tsit5; grid_coarsening = true) 0.0802 ± 0.0076 s 0.0802 ± 0.012 s 1 ± 0.18
Simple Pendulum/IIP/Shooting(Tsit5()) 0.251 ± 0.078 ms 0.256 ± 0.078 ms 0.982 ± 0.43
Simple Pendulum/OOP/BoundaryValueDiffEqMIRK.MIRK2() 0.73 ± 0.0057 s 0.741 ± 0.016 s 0.984 ± 0.022
Simple Pendulum/OOP/BoundaryValueDiffEqMIRK.MIRK3() 16.3 ± 5 ms 16.7 ± 5.1 ms 0.98 ± 0.42
Simple Pendulum/OOP/BoundaryValueDiffEqMIRK.MIRK4() 3.58 ± 0.16 ms 3.6 ± 0.15 ms 0.995 ± 0.06
Simple Pendulum/OOP/BoundaryValueDiffEqMIRK.MIRK5() 10.7 ± 1.1 ms 10.8 ± 0.71 ms 0.989 ± 0.12
Simple Pendulum/OOP/BoundaryValueDiffEqMIRK.MIRK6() 1.86 ± 0.14 ms 1.9 ± 0.14 ms 0.975 ± 0.11
Simple Pendulum/OOP/MultipleShooting(10, Tsit5; grid_coarsening = false) 3.56 ± 2.9 ms 3.62 ± 2.9 ms 0.982 ± 1.1
Simple Pendulum/OOP/MultipleShooting(10, Tsit5; grid_coarsening = true) 6 ± 5.1 ms 6.13 ± 5.2 ms 0.978 ± 1.2
Simple Pendulum/OOP/MultipleShooting(100, Tsit5; grid_coarsening = false) 0.115 ± 0.0032 s 0.117 ± 0.0044 s 0.987 ± 0.046
Simple Pendulum/OOP/MultipleShooting(100, Tsit5; grid_coarsening = true) 0.143 ± 0.0053 s 0.142 ± 0.0072 s 1.01 ± 0.064
Simple Pendulum/OOP/Shooting(Tsit5()) 0.647 ± 0.036 ms 0.678 ± 0.045 ms 0.954 ± 0.083
time_to_load 5.34 ± 0.0033 s 5.29 ± 0.0076 s 1.01 ± 0.0016
### Benchmark Plots A plot of the benchmark results has been uploaded as an artifact to the workflow run for this PR. Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@ErikQQY ErikQQY marked this pull request as ready for review August 13, 2025 19:10
@ErikQQY ErikQQY closed this Aug 14, 2025
@ErikQQY ErikQQY reopened this Aug 14, 2025
@ErikQQY

This comment was marked as outdated.

@ErikQQY ErikQQY closed this Aug 28, 2025
@ErikQQY ErikQQY reopened this Aug 28, 2025
@ErikQQY
Copy link
Member Author

ErikQQY commented Aug 28, 2025

I think this PR is ready to go now.

The optimal control interface still needs some more work considering the complex whole-time interval inequality(similar to @variable(model, v[1:T] >= 0, start = v_0) in JuMP.jl), but let's do that in a following PR since that would involve changing the way we build the loss function here.

if prob isa NonlinearLeastSquaresProblem
return __FastShortcutBVPCompatibleNLLSPolyalg(eltype(prob.u0))
else
return __FastShortcutBVPCompatibleNonlinearPolyalg(eltype(prob.u0))
end
end

# Some optimization algorithms (solvers from interfacing packages) don't support the __solve(prob) interface
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, we should handle this upstream, which ones?

retcode = ifelse(SciMLBase.successful_retcode(nlsol), odesol.retcode, nlsol.retcode)
return SciMLBase.solution_new_original_retcode(odesol, nlsol, retcode, nlsol.resid)
end
function __build_solution(prob::AbstractBVProblem, odesol, optsol::SciMLBase.OptimizationSolution)
retcode = ifelse(SciMLBase.successful_retcode(optsol), odesol.retcode, optsol.retcode)
return SciMLBase.solution_new_original_retcode(odesol, optsol, retcode, zeros(length(first(odesol)))) # Need a patch in SciMLBase
Copy link
Member

Choose a reason for hiding this comment

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

what needs a patch?

Comment on lines +632 to +638
zeros(T, N*M)
else
lcons_length = length(prob.lcons)
vcat(prob.lcons, zeros(T, N*M - lcons_length))
end
ucons = if isnothing(prob.ucons)
zeros(T, N*M)
Copy link
Member

Choose a reason for hiding this comment

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

Using zero is likely not good? That will mess with the stability of the solver quite a bit. If inequality constraints are given then the lcons / ucons should be required from the user.

jac_prototype = jac_prototype)
return __internal_nlsolve_problem(prob, resid_prototype, y, nlf, y, p)
else
optf = OptimizationFunction{true}(__default_cost(prob.f), AutoFiniteDiff(), # Need to investigate the ForwardDiff dual problem
Copy link
Member

Choose a reason for hiding this comment

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

what problem?

Comment on lines +694 to +699
jac_prototype = jac_prototype)
return __internal_nlsolve_problem(prob, resid_prototype, y, nlf, y, p)
else
optf = OptimizationFunction{true}(
__default_cost(prob.f), get_dense_ad(alg.jac_alg.diffmode),
cons = loss, cons_j = jac, cons_jac_prototype = jac_prototype)
Copy link
Member

Choose a reason for hiding this comment

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

It's not easy to see from this, but when doing multiple shooting with this the codegen should be a little different from the nonlinear solve. With multiple shooting you have the endpoint conditions, and you put those into the nonlinear equation to be satisfied. In the optimization, they should be moved to the equality constraints.

Copy link
Member

@ChrisRackauckas ChrisRackauckas left a comment

Choose a reason for hiding this comment

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

All of those things are small. Let's make those into issues, but merge and continue with smaller changes.

@ChrisRackauckas ChrisRackauckas merged commit 172511a into master Sep 7, 2025
45 of 61 checks passed
@ChrisRackauckas ChrisRackauckas deleted the qqy/bvp_opt branch September 7, 2025 14:27
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.

2 participants