Skip to content

Conversation

Gui-FernandesBR
Copy link
Member

Pull request type

  • Code maintenance (refactoring, formatting, tests)

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 vs New behavior

  1. The Flight.__simulate() method is more readable
  2. Controllers can now be used with time overshoot option = True (solves ENH: Allow overshooting controllers #663)
  3. the same is valid for sensors

Controllers and Sensors Simulations should run faster!!

Breaking change

  • No

Additional information

  • I need help to review this PR carefully, although tests are passing locally.

@Gui-FernandesBR Gui-FernandesBR requested a review from a team as a code owner August 15, 2025 02:44
@Gui-FernandesBR Gui-FernandesBR self-assigned this Aug 15, 2025
@Gui-FernandesBR Gui-FernandesBR added Refactor Flight Flight Class related features labels Aug 15, 2025
@Gui-FernandesBR Gui-FernandesBR added this to the Release v1.X.0 milestone Aug 15, 2025
@Gui-FernandesBR Gui-FernandesBR linked an issue Aug 15, 2025 that may be closed by this pull request
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Flight class's __simulate() method to improve readability and enable time overshoot functionality for controllers and sensors. The main changes include:

  • Breaking down the monolithic __simulate() method into smaller, focused methods for better maintainability
  • Enabling controllers and sensors to work with time_overshoot=True option, which was previously disabled
  • Optimizing simulation performance by allowing overshootable time nodes for sensors and controllers

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rocketpy/simulation/flight.py Major refactoring of Flight simulation methods, breaking __simulate() into smaller helper methods and adding support for time overshoot with controllers/sensors
tests/integration/test_plots.py Reduced number of test flight configurations from 16 to 4 for faster test execution
tests/integration/test_flight.py Added new test for air brakes with time overshoot and renamed existing test for clarity
tests/integration/test_environment.py Minor cleanup removing unused today variable
tests/fixtures/flight/flight_fixtures.py Added new fixture for air brakes flight with time overshoot enabled

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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.

Good work! I hope this is the beginning of having a much more readable and developer friendly Flight class.

My only concern is making sure the behavior is exactly the same as before, therefore I made a single important comment on the early return of parachute triggers just to make sure we are on the same page. Of course, all the tests being green is already a big step.

Aside from that, my other suggestions are more style/naming choices. I prefer having some more standardized names for some methods, but I would approve the PR in the current state even if these suggestions are not taken, since it already does loads for readability.

self.solution,
self.sensors,
)
self.__process_sensors_and_controllers_at_current_node(node, phase)
Copy link
Collaborator

@phmbressan phmbressan Sep 22, 2025

Choose a reason for hiding this comment

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

I don't mind much, since this is a private method naming. However, do you think there might be a more scalable / descriptive name here, so as to avoid adding words to it in the future: e.g. __process_sensors_and_controllers_and...? Having trouble naming a method may indicate it may do too much.

Actually, my suggestion would be going for a more standardized approach. I have never seen a fixed convention for this, but it is nice to have some internal consistency when naming checkers/process/handlers, my two cents would be:

  • handler: returns a boolean and operate on solution variables;
  • process: can operate on solution variables, but does not return;
  • checker: returns a boolean, but only reads solution variables (e.g. does not setup phases/nodes, I did not see any pure checkers on this PR).
self.__process_sensors(...)
self.__process_controllers(...)

if self.__handle_parachute_triggers(...):
    break

while running:
    if self.__handle_simulation_events(...):
        break

    if self.time_overshoot:
        # I nested the if clauses for readability
        # Both ways are equivalent and should perform the same
        if self.__handle_overshoot(...):
            break

self.y_sol,
self.sensors,
):
return False # Early exit: parachute not deployed
Copy link
Collaborator

@phmbressan phmbressan Sep 22, 2025

Choose a reason for hiding this comment

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

Really not sure, since the code is complex, but shouldn't this be a continue (i.e. even if one trigger does not go off, there are other parachutes to check)?


return False

def __check_simulation_events(self, phase, phase_index, node_index):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the three methods inside it are handlers, I would also call this one a handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Flight Flight Class related features Refactor

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

ENH: Allow overshooting controllers

2 participants