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

Research/document desired functionality of Python (scipy) integrators #6

Open
nicklafarge opened this issue Nov 9, 2022 · 8 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@nicklafarge
Copy link
Member

nicklafarge commented Nov 9, 2022

We need to understand what functionality from [scipy.integrate.solve_ivp] (https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html) we want to see incorporated into the python API

@nicklafarge nicklafarge added the good first issue Good for newcomers label Nov 9, 2022
@nicklafarge nicklafarge added this to the Requirements and Analysis milestone Nov 9, 2022
@rjpower4
Copy link
Member

rjpower4 commented Nov 9, 2022

@DhruvJ22
Copy link

We should incorporate most of the features into our Python API. I have strikethrough the ones that are overkill/unnecessary to include for our purpose and added some comments for things that we can add.

Parameters:

  1. t_span: integration interval (to, tf)
  2. y0 {only states, no Identity even if STM is to be computed}
  3. Integration method {we can discuss which methods to include for v 1.0 in Select which Boost ODE methods to initially support #3}
  4. t_eval: specify @ti at which to store solutions
  5. dense_output
  6. events:
  • predefine common events functions like y=0, x = 1-mu and make them accessible using a string name
  • option to define a "custom" events function in python and pass that to the underneath c++
  • option for terminal and direction
  • option to get the nth, or an array of i (e.g. [1,2,5,6]) events and terminate after the last event specified.
  1. rtol, atol
  2. vectorized
  3. firsrt_step
  4. max_step
  5. jac
  6. jac_sparsity
  7. lband, uband
  8. min_step

Returns: {we should try to keep the "Returns" API similar to solve_ivp to make it easier for users to integrate forest in their existing work}

  1. t (ndarray)
  2. y (values of states at t)
  3. sol
  4. t_events (list of ndarray)
  5. y_events (list, values of states at t)
  6. n_events (new parameter, list of # event numbers corresponding to the value of t_events; e.g. [1,2,5,6])
  7. nfev
  8. njev
  9. nlu
  10. status (int, reason for algorithm termination)
  11. message (string)
  12. success (bool)

@noahsadaka
Copy link

I think that rather than have several specific axis-crossing event functions, it would be more flexible to have a single event function where you can specify an axis and a value along that axis for the hyperplane to exist at. So setting axis y and value 0 would give our typical x-axis crossing function, but users wouldn't be constrained to using only that event function or whatever other specific axis-crossing event function that is included in forest.

@rjpower4
Copy link
Member

Axis-crossing events are a special type of the more general set of affine events of the form

$$ \vec{f}\left(\vec{x}\right) = A\vec{x} + \vec{b} $$

with $\vec{x} \in \mathbb{R}^n$, $\vec{f}, \vec{b} \in \mathbb{R}^m$, $A \in \mathbb{R}^{m \times n}$. So I think that implementation should encompass most of these along. We can provide convenience methods for plane crossing events which are just cases where $A$ is a one-hot vector.

@nicklafarge
Copy link
Member Author

Agreed on all points above.

Also, I think we also should think carefully before we expose too much Python functionality (@rjpower4 and I have discussed this previously). For example, Python-defined EOMs sound convenient and fun in theory, but ultimately may defeat the point of a rapid integration package if it suddenly requires going back-and-forth to Python each step of the integrator. The convenience of Python-defined functionality may also make people less likely to implement their model/event/whatever directly in C++ (which may then benefit the user community in general). The same could be potentially said for event functions.

Not saying we shouldn't do any of those things, but it is a perspective to consider when deciding where to draw that line. For events specifically, RJ's affine event suggestion sounds great.

@DhruvJ22
Copy link

I agree that we should not expose EOMs, that is why I did not explicitly include 'fun' as an input.

I think it will be a good option to allow users to pass A and $\bar{b}$ on the Python side to define an events function. With this, the users can retain the ease of defining straightforward event functions, and I don't think it will significantly affect the C++ performance. I see it as constant variables like abs_tol that are set at the beginning of the integration loop. We can push the users to define more complex event functions, like periapsis and altitude, directly in C++, which can then be used by other community members.

@nicklafarge
Copy link
Member Author

Sounds good! Thanks for documenting all this @DhruvJ22 !

@nicklafarge
Copy link
Member Author

This discussion provides some good insight for #13 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants