Skip to content

Conversation

@KeshavVenkatesh
Copy link
Contributor

In this PR, I have attempted to implement the butcher tableau approach for the Tsit5 algorithm for both solving and interpolation.

I have used the coefficient values from OrdinaryDiffEqExplicitRK. I am working on extending the benchmark tests for interpolation.

Please review my changes and provide feedback for the following:

  • On the implementation for solving and interpolation.
  • The logic for benchmark tests, results and suggestions on how I can improve them. Are the numerical differences in values between two approaches acceptable?
  • Suggestions for how I can extend the benchmark tests for interpolations as well.

@KeshavVenkatesh
Copy link
Contributor Author

@ChrisRackauckas : Request you to kindly review this PR and provide your feedback

Comment on lines 1 to 8
"""
Evaluate a polynomial at Θ, given coefficients for Θ¹, Θ², ..., Θ⁶.
Assumes coeffs = [a₁, a₂, ..., a₆] for Θ¹, Θ², ..., Θ⁶.
"""
function eval_poly_theta(Θ, coeffs)
# coeffs[1]*Θ + coeffs[2]*Θ^2 + ... + coeffs[6]*Θ^6
return sum(coeffs[i] * Θ^i for i in 1:length(coeffs))
end
Copy link
Member

Choose a reason for hiding this comment

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

isn't this just evalpoly?

[@evalpoly(Θ, tableau[i,:]...) for i in 1:num_stages]
else
# For derivative: d/dΘ [a₀ + a₁*Θ + a₂*Θ² + ...] = a₁ + 2*a₂*Θ + 3*a₃*Θ² + ...
[@evalpoly(Θ, [j * tableau[i, j+1] for j in 1:(num_coeffs-1)]...) for i in 1:num_stages]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oscardssmith : Thanks for the feedback and suggestion. Apologies I was not familiar with this. Could you please check if this change looks right?

@ChrisRackauckas
Copy link
Member

Sorry was trying to get this repo passing tests again first.

This should just be added as part of the normal ExplicitRK implementation. With a field for the interpolation values added to the ExplicitRKTableau definition in DiffEqBase.

Note this is the same tableau as the one that is tested https://github.com/SciML/DiffEqDevTools.jl/blob/master/src/ode_tableaus.jl#L989

@KeshavVenkatesh
Copy link
Contributor Author

Thank you for these updates. I will work on what you said and send you a new PR tomorrow.

@KeshavVenkatesh
Copy link
Contributor Author

KeshavVenkatesh commented Dec 18, 2025

@ChrisRackauckas Could you please review the changes I have made? I will do some more testing, but I wanted to know if I have incorporated your suggestions. I have also created a new PR in DiffEqBase, can you please review that as well? Thanks!

@ChrisRackauckas
Copy link
Member

all of the generic_dense parts are missing?

@KeshavVenkatesh
Copy link
Contributor Author

all of the generic_dense parts are missing?

@ChrisRackauckas Does this involve implementing equivalent logic as in

@muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::Tsit5ConstantCache,

@ChrisRackauckas
Copy link
Member

Yes exactly, just for the ExplicitRK tableau with its generic coefficient vector.

@KeshavVenkatesh
Copy link
Contributor Author

Yes exactly, just for the ExplicitRK tableau with its generic coefficient vector.

@ChrisRackauckas Could you please review this PR and provide your feedback? I have implemented this based on my understanding of how it was implemented for Tsit5 in this code here, but I made it generic for different orders.

Comment on lines 180 to 184
function construct_tsit5_interp_matrix_auto(T::Type)
if T <: Union{Float32, Float64}
return construct_tsit5_interp_matrix(T)
else
return construct_tsit5_interp_matrix_highprecision(T)
Copy link
Member

Choose a reason for hiding this comment

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

this hsould just be dispatch

Automatically selects appropriate precision based on type.
"""
function construct_tsit5_interp_matrix_auto(T::Type)
Copy link
Member

@ChrisRackauckas ChrisRackauckas Dec 29, 2025

Choose a reason for hiding this comment

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

Suggested change
function construct_tsit5_interp_matrix_auto(T::Type)
function construct_tsit5_interp_matrix_auto(::Type{T}) where T

force specialize

High-precision version for BigFloat and other arbitrary-precision types.
We have not tested this
"""
function construct_tsit5_interp_matrix_highprecision(T::Type)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function construct_tsit5_interp_matrix_highprecision(T::Type)
function construct_tsit5_interp_matrix_highprecision(::Type{T}) where T

... and so on for all 7 stages
=
"""
function construct_tsit5_interp_matrix(T::Type = Float64)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function construct_tsit5_interp_matrix(T::Type = Float64)
function construct_tsit5_interp_matrix(::Type{Float64})

end

# In-place version
function generic_rk_interpolant!(out, Θ, dt, y₀, k, B_interp; idxs=nothing, order=0)
Copy link
Member

Choose a reason for hiding this comment

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

these aren't implementing the dense.jl dispatches required for the interpolation to be used in the solution. Check OrdinaryDiffEqCore/src/dense. See how it's done for example with OrdinaryDiffEqVerner.

@ChrisRackauckas
Copy link
Member

Sorry got behind having to revive a bit of this repo. Left some comments. Still some work to do here but on the right track

@KeshavVenkatesh
Copy link
Contributor Author

@ChrisRackauckas In the latest PR, I have incorporated the logic for dense interpolation and also addressed your comments on force specialization and dispatch support.

I will now work on benchmarking and functional tests for these changes.

@KeshavVenkatesh
Copy link
Contributor Author

@ChrisRackauckas Could you please review this pull request?

@KeshavVenkatesh
Copy link
Contributor Author

Could you please review the pull request that I sent a link to? Thanks!

@ChrisRackauckas
Copy link
Member

That looks right. Is that PR not to here?

@KeshavVenkatesh
Copy link
Contributor Author

Yes, it is. Is the PR ready to be merged?

@ChrisRackauckas
Copy link
Member

if tests are passing. needs a rebase and then those changes and yeah it looks like that makes it ready

@KeshavVenkatesh
Copy link
Contributor Author

if tests are passing. needs a rebase and then those changes and yeah it looks like that makes it ready

@ChrisRackauckas, thanks for your feedback. I will work on rebasing the PR, running the test, and getting the PR ready for landing.

Is there anything I can work on in parallel? I have a (slightly) better understanding of the codebase from the work I have done so far, and I would love to pick up any medium/large work to get a better understanding and contribute more.

Also if you have any feedback on my work so far - specifically on what I can improve - I would greatly appreciate it.

I also wanted to say that this work is really interesting and wanted to thank you for the opportunity you provided.

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.

3 participants