Skip to content

FIX: changes Generic Motor exhaust velocity to cached property #497

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

Merged

Conversation

giovaniceotto
Copy link
Member

@giovaniceotto giovaniceotto commented Nov 30, 2023

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 --runslow) have passed locally
  • CHANGELOG.md has been updated (if relevant)

Current behavior

GenericMotor.exhaust_velocity is being decorated by funcify_method, which makes it (a float essentially) into a lambda defined Function. This causes everything that depends on it algebraically to become lambda defined Functions as well.

More specifically, this contaminates GenericMotor.mass_flow_rate, which in turn contaminates GenericMotor.propellant_mass (which actually includes an integral_function of the lambda GenericMotor.exhaust_velocity 🫣). Well, in the end, this contaminates Rocket.total_mass, which is used extensively by the Flight class during a simulation.

In summary, this use of funcify_method causes the Flight class to take forever (literally) to run.

New behavior

What can I say? Changing the decorator from funcify_method to cached_property makes the sun shine once again, solving everything.

Breaking change

  • No

phmbressan
phmbressan previously approved these changes Nov 30, 2023
Copy link
Collaborator

@phmbressan phmbressan left a comment

Choose a reason for hiding this comment

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

Thank you for going through the journey to discover the bottleneck in this class. I was postponing for some time. Great finds!

Won't even start about snowball effect that the Function is currently generating that slows down the code so much. I will only say that the sooner this is fixed, the better.

Copy link

codecov bot commented Nov 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8d6f244) 70.95% compared to head (e4e83ae) 70.92%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #497      +/-   ##
==========================================
- Coverage   70.95%   70.92%   -0.04%     
==========================================
  Files          55       55              
  Lines        9262     9262              
==========================================
- Hits         6572     6569       -3     
- Misses       2690     2693       +3     
Flag Coverage Δ
unittests 70.92% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

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

I swear that I tried but I honestly have no idea of how you discovered this error in such a chain of calls.

@Gui-FernandesBR
Copy link
Member

Before merging, do you see any possibility for new unit tests here? It's quite complicated because the error was only happening due to a "snowball" effect.

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

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

LGTM

@MateusStano MateusStano changed the base branch from master to rel/v1.1.4 December 7, 2023 00:11
@MateusStano MateusStano merged commit e88b121 into rel/v1.1.4 Dec 7, 2023
@MateusStano MateusStano deleted the bug/generic-motor-exhaust-velocity-stalls-flight branch December 7, 2023 00:11
@MateusStano MateusStano mentioned this pull request Dec 7, 2023
@Gui-FernandesBR Gui-FernandesBR added the Bug Something isn't working label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

4 participants