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

ENH: Complex step differentiation #594

Merged
merged 10 commits into from
May 9, 2024

Conversation

Gui-FernandesBR
Copy link
Member

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest tests -m slow --runslow) have passed locally
  • CHANGELOG.md has been updated (if relevant)

Current behavior

The Function.differentiate() method is the only method that can be used to derivate Function objects.

New behavior

The new, powerful, and fast Function.differentiate_complex_step() method is here!
This method will be used to speed up simulations in future PRs.

Breaking change

  • No

Additional information

This PR will close the #131 issue, a really old feature request of our repository.

@Gui-FernandesBR Gui-FernandesBR added Enhancement New feature or request, including adjustments in current codes Function Everything related to the Function class labels May 5, 2024
@Gui-FernandesBR Gui-FernandesBR added this to the Release v1.X.0 milestone May 5, 2024
@Gui-FernandesBR Gui-FernandesBR self-assigned this May 5, 2024
@Gui-FernandesBR Gui-FernandesBR requested a review from a team as a code owner May 5, 2024 03:48
@Gui-FernandesBR Gui-FernandesBR linked an issue May 5, 2024 that may be closed by this pull request
Copy link

codecov bot commented May 5, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 73.31%. Comparing base (92e93a7) to head (fc6804c).
Report is 2 commits behind head on develop.

Files Patch % Lines
rocketpy/mathutils/function.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #594      +/-   ##
===========================================
- Coverage    73.35%   73.31%   -0.05%     
===========================================
  Files           57       57              
  Lines         9429     9436       +7     
===========================================
+ Hits          6917     6918       +1     
- Misses        2512     2518       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@MateusStano MateusStano left a comment

Choose a reason for hiding this comment

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

Really good!

Questions:

  1. Are there any benefits to using the old differentiation method? Or is this one just better?
  2. Have you tried plugging this in the flight class? Does it make a difference in terms of performance? If so, why not do it in this PR?
  3. Could you add second-order differentiation to this?

@Gui-FernandesBR
Copy link
Member Author

Really good!

Questions:

  1. Are there any benefits to using the old differentiation method? Or is this one just better?

Yes, this new method only works if the function accepts complex numbers that presents an imaginary part. Also, it is required that the function should be "differentiable in complex dimension", but this is not practical insight. Therefore, the old method should still be used sometimes.

  1. Have you tried plugging this in the flight class? Does it make a difference in terms of performance? If so, why not do it in this PR?

Yes, it helps the flight class to go faster. The goal of this PR was to implement a complex step differentiation method, nothing more.
As I mentioned in the PR description: "This method will be used to speed up simulations in future PRs."

  1. Could you add second-order differentiation to this?

Let me try to implement it the next weekend.

@Gui-FernandesBR
Copy link
Member Author

@MateusStano let's forget about the second order differentiation, it was giving some errors that I really think are not worth it to debug right now.

The tests are already covering basic scenarios and I know for a fact that the flight simulations are running correctly when using the complex step method (1st order).

I would leave the second order for a future PR.

Could you approve this one please?

@MateusStano
Copy link
Member

The tests are already covering basic scenarios and I know for a fact that the flight simulations are running correctly when using the complex step method (1st order).

I would leave the second order for a future PR.

Could you approve this one please?

Okay. One more thing that would be good here is using complex diff for derivative_function. That might make a big difference for liquids/hybrids simulations

@Gui-FernandesBR Gui-FernandesBR merged commit fba6c8c into develop May 9, 2024
9 of 10 checks passed
@Gui-FernandesBR Gui-FernandesBR deleted the enh/complex-step-differentiation branch May 9, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request, including adjustments in current codes Function Everything related to the Function class
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

ENH: Different ways of differentiating
3 participants