Skip to content

src/bvp: fix uninitialized residual tail and size contract inconsistencies - #339

Open
abavoil wants to merge 1 commit into
bifurcationkit:masterfrom
abavoil:fix-newton-residuals
Open

src/bvp: fix uninitialized residual tail and size contract inconsistencies#339
abavoil wants to merge 1 commit into
bifurcationkit:masterfrom
abavoil:fix-newton-residuals

Conversation

@abavoil

@abavoil abavoil commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

bvp_residual for Shooting/Trapeze/Collocation allocated out = similar(X) but only wrote the prefix out[1:n*M]; the trailing 'period' slot (advertised by generate_solution and total_dim) was never written, so residual(prob, x, p) returned uninitialized memory in newton (nondeterministic results) and the AutoDiffDense Jacobian carried a garbage last row.

Fixed-interval design, consistent with #312 ('no need for phase') and #315 ('fixed final time; any unknown like tf must be a constant state'):

  • residuals fully write an output of length solution_dim and reject wrong-size input with an ArgumentError
  • generate_solution returns n*M (no dead trailing slot)
  • Base.length(DiscretizedBVP) = solution_dim; total_dim removed
  • get_periodic_orbit uses the model time interval instead of X[end]
  • remove dead bvp_jacobian(::Nothing) for Shooting (called three undefined helpers: _shooting_phase, integrate_shooting, euler_integrate) and the dangling exports
  • tests: update test/bvp/bvp.jl to the solution_dim contract, add dedicated MRE regression test test/bvp/mre_shooting_uninit.jl

(GLM 5.3 flash)

…ncies

bvp_residual for Shooting/Trapeze/Collocation allocated out = similar(X) but
only wrote the prefix out[1:n*M]; the trailing 'period' slot (advertised by
generate_solution and total_dim) was never written, so residual(prob, x, p)
returned uninitialized memory in newton (nondeterministic results) and the
AutoDiffDense Jacobian carried a garbage last row.

Fixed-interval design, consistent with bifurcationkit#312 ('no need for phase') and bifurcationkit#315
('fixed final time; any unknown like tf must be a constant state'):
- residuals fully write an output of length solution_dim and reject
  wrong-size input with an ArgumentError
- generate_solution returns n*M (no dead trailing slot)
- Base.length(DiscretizedBVP) = solution_dim; total_dim removed
- get_periodic_orbit uses the model time interval instead of X[end]
- remove dead bvp_jacobian(::Nothing) for Shooting (called three undefined
  helpers: _shooting_phase, integrate_shooting, euler_integrate) and the
  dangling exports
- tests: update test/bvp/bvp.jl to the solution_dim contract, add dedicated
  MRE regression test test/bvp/mre_shooting_uninit.jl
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.

1 participant