Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facilitate solution saving at precise parameter values #172

Closed
BambOoxX opened this issue Aug 17, 2024 · 9 comments
Closed

Facilitate solution saving at precise parameter values #172

BambOoxX opened this issue Aug 17, 2024 · 9 comments

Comments

@BambOoxX
Copy link
Contributor

In SciML ODE solvers, there is a built-in saveat option that allows to save the solution at precise time steps with interpolation between actually computed points.

I know that BifurcationKit allors to use e.g. SaveAtEvent, but as advertised that is not very precise, and there is this section of the documentation, but I could not make any sense of it to save the solution at precise continuation parameter values.

Could there be some more information, or some easier interface to facilitate such precise savings of the solution ?

@rveltz
Copy link
Member

rveltz commented Aug 17, 2024

but as advertised that is not very precise

If you tune the number n_inversion it should be relatively precise, at least the precision on the parameter value is reported.

So no, there is no interface right now although with SaveAtEvent, this is very close. What is lacking is a last newton step to compute the points reported by SaveAtEvent at the precise user passed parameter values. A PR is welcomed!

@rveltz rveltz transferred this issue from bifurcationkit/BifurcationKitDocs.jl Aug 19, 2024
@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 3, 2024

I'm guessing this step should be added in

function locate_event!(event::AbstractEvent, iter, _state, verbose::Bool = true)
right ?

@rveltz
Copy link
Member

rveltz commented Oct 3, 2024

No, this is to locate the event. Once it has been located, we should do something with the event. This part is not done. I guess, we should let the user pass a finaliser function to be applied to the event. In your case, the event function would be a newton algorithm.

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 3, 2024

So you mean add a Newton iteration in

function SaveAtEvent(positions::Tuple)

or did you have something else in mind ?

@rveltz
Copy link
Member

rveltz commented Oct 3, 2024

probably the easiest would be to dispatch on SaveAtEvent the function get_event_type

success, event_pt = get_event_type(it.event, it, state, it.verbosity, status, interval_event)

Something like

function get_event_type(event::SaveAtEvent, 
                        iter::AbstractContinuationIterable, 
                        state, 
                        verbosity, 
                        status::Symbol, 
                        interval::Tuple{T, T}, 
                        ind = :; 
                        typeE = "userC") where T

# do newton here
end

This is a hack that would probably work. However, it is not a general solution because if you use a Pair of events with SaveAtEvent, it would not call the dispatched function.

The best way would be to add a finalizer function in all events ContinuousEvent, etc and call this finalizer (inplace) just after

success, event_pt = get_event_type(it.event, it, state, it.verbosity, status, interval_event)

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 3, 2024

This is a hack that would probably work. However, it is not a general solution because if you use a Pair of events with SaveAtEvent, it would not call the dispatched function.

What about a dispatch over any PairOfEvent that contains a SaveAtEvent ?

I just looked at locate_bifurcation!. I was thinking about using that as a base for the Newton steps, do you see any disavantages of using that ?

@rveltz
Copy link
Member

rveltz commented Oct 4, 2024

It depends what you want to do:

  1. if you want a solution for yourself, I provided the best hack above IMO
  2. if you want a solution for the library, we have to be really careful as some code is very sensitive (like locate_bifurcation), plus we have to provide a nice API for the user.

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 4, 2024

I would say, I'd love a solution for myself, but also for the library ;).
I was also wondering if, since we have the solution with a nice resolution in the end, we could perform an interpolation on a branch with e.g. ApproxFun and evaluate at the requested points...

@rveltz
Copy link
Member

rveltz commented Oct 5, 2024

Solved.

@rveltz rveltz closed this as completed Oct 5, 2024
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

No branches or pull requests

2 participants