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

Implement Temporal Subset Simulation #725

Merged
merged 18 commits into from
Mar 21, 2023
Merged

Conversation

Mythicaeda
Copy link
Contributor

@Mythicaeda Mythicaeda commented Mar 13, 2023

Description

Database Changes

  • Columns for tracking simulation start time and simulation end time were added to simulation and simulation_template. They are both nullable, but between the two tables each column must have a value for a given row in simulation. For example, if a simulation row references a template, either the template or the simulation row can provide the sim start and end time, but if a simulation row doesn't reference a template, it must provide these values.
  • A trigger was created to insert a row into simulation upon a row being inserted into plan
  • A constraint was added to simulation to allow only one row per plan (If this constraint is currently violated in the DB, the migration introducing it will fail).
  • simulation_dataset now has columns for what bounds the simulation was run over, as well as what the provided arguments were.
  • simulation_dataset's offset_from_plan_start is now solely maintained via trigger rather than by direct update.
  • The simulated_activity view was updated to have the correct start time for spans from temporal subset simulations

Merlin Changes

  • Methods for adjusting the start offset of a List of ActivityDirectives and filtering out ActivityDirectives with negative start offsets have been added to StartOffsetReducer.
  • Plan, SimulationRecord, SimulationTemplateRecord, and SimulationDatasetRecord all have had simulationStartTime and simulationEndTime added as fields.
  • getPlan was split into getPlanForValidation and getPlanForSimulation in order to avoid needlessly hitting up the database.
  • SimulationResults now has a duration field.
  • Simulation start and end time must now be specified by either the sim config or the template (see Database Changes for more details)

Breaking Changes

The following breaking changes occurred:

  1. The signature of SimulationDriver.simulate changed to
  public static <Model> SimulationResults simulate(
      final MissionModel<Model> missionModel,
      final Map<ActivityDirectiveId, ActivityDirective> schedule,
      final Instant simulationStartTime,
      final Duration simulationDuration,
      final Instant planStartTime,
      final Duration planDuration
  )
  1. The signature of CreateSimulationMessage changed to
  public CreateSimulationMessage {
    Objects.requireNonNull(missionModelId);
    Objects.requireNonNull(simulationStartTime);
    Objects.requireNonNull(simulationDuration);
    Objects.requireNonNull(planStartTime);
    Objects.requireNonNull(planDuration);
    Objects.requireNonNull(activityDirectives);
    Objects.requireNonNull(configuration);
  }
  1. The structure of a SimulationResults changed to
public SimulationResults(
        final Map<String, Pair<ValueSchema, List<ProfileSegment<RealDynamics>>>> realProfiles,
        final Map<String, Pair<ValueSchema, List<ProfileSegment<SerializedValue>>>> discreteProfiles,
        final Map<SimulatedActivityId, SimulatedActivity> simulatedActivities,
        final Map<SimulatedActivityId, UnfinishedActivity> unfinishedActivities,
        final Instant startTime,
        final Duration duration,
        final List<Triple<Integer, String, ValueSchema>> topics,
        final SortedMap<Duration, List<EventGraph<Pair<Integer, SerializedValue>>>> events)
  1. Simulation bounds need to be specified in the database by either the simulation or template rows. (See Database Changes for more information)

Verification

  • MerlinDatabaseTests were updated to reflect the added "one simulation row per plan" constraint and the "create simulation row when a plan is created" trigger.
  • Tests were added to AnchorTests.StartOffsetReducerTests to test the new static methods. Notably, since the new methods and the constructor do some input validation/special behavior on null inputs, there are tests for these cases.
  • A new set of tests, TemporalSubsetSimulationTests were added to verify that simulating a subset of a plan works. Since Aerie does not distinguish between full simulations and temporal subset simulations, the existing decomposition tests shouldn't need to be repeated here.

Documentation

Documentation ticket for the API changes can be found here.

Future work

  • Since the simulation-related fields are only initialized for a Plan object when calling getPlanForSimulation, I'd like to split them from the Plan class, either by putting them in their own class or by moving them into a subclass of Plan.
  • Adding a Plan End timestamp column, likely maintained via a trigger like simulation_dataset's offset_from_plan_start column.

@Mythicaeda Mythicaeda added breaking change A change that will require updating downstream code feature A new feature or feature request database Anything related to the database simulation Anything related to the simulation domain labels Mar 13, 2023
@Mythicaeda Mythicaeda requested a review from a team as a code owner March 13, 2023 22:47
@Mythicaeda Mythicaeda self-assigned this Mar 13, 2023
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 13, 2023 22:47 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 13, 2023 22:47 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from d163d80 to b7ee375 Compare March 13, 2023 23:06
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 13, 2023 23:06 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 13, 2023 23:06 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from b7ee375 to a1f4c0b Compare March 13, 2023 23:35
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 13, 2023 23:35 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 13, 2023 23:35 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from a1f4c0b to bd3ba6a Compare March 14, 2023 16:38
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 14, 2023 16:38 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 14, 2023 16:39 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from bd3ba6a to c962456 Compare March 14, 2023 18:16
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 14, 2023 18:16 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 14, 2023 18:16 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 14, 2023 18:16 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from c962456 to 366f83c Compare March 16, 2023 17:10
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 16, 2023 17:10 — with GitHub Actions Inactive
@mattdailis
Copy link
Collaborator

Could you fill out the Documentation section of the PR template? If no documentation has been written - could you link to the ticket to write this documentation?

I just pulled this branch and will play around a bit now - I don't expect to do a super detailed code review since we chatted about this a couple weeks ago, and it sounds like you guys had a good code walkthrough last week, but I would like to glance over it with the freshest pair of eyes I've had in a while 😅

* Update simulated_activity to use new columns
* Add trigger to maintain offset_from_plan_start
* Update MerlinDBTests to reflect new Trigger
* Change signature of SimulationDriver.simulate (Breaking Change)
* Modify existing tests to use new signature
* Split getPlan into getPlanForSimulation(gets Plan/Activity/Simulation info) and getPlanForValidation (only gets the Plan/Activity info)
* Prevent NullPointerException in StartOffsetReducer.compute
* Remove Unneeded CreateSimulationAction
* Update Get and Create Actions to reflect this
* Update PostgresCellResults to reflect these changes
* Update SimulationEngine to output final elapsed time simulation duration
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from 95cc3cc to 358bde9 Compare March 20, 2023 21:26
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 20, 2023 21:27 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 20, 2023 21:27 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 20, 2023 21:27 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda force-pushed the feat/split-sim-and-plan-start branch from 358bde9 to 6616391 Compare March 20, 2023 22:24
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 20, 2023 22:24 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 20, 2023 22:24 — with GitHub Actions Inactive
@Mythicaeda Mythicaeda temporarily deployed to e2e-test March 20, 2023 22:24 — with GitHub Actions Inactive
Copy link
Collaborator

@mattdailis mattdailis left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. I didn't pull out my fine-toothed comb, but Adrien's review, and the level of testing give me confidence in this change. I'm looking forward to exercising it more as we implement the UI portion of this feature 🚀

@Mythicaeda Mythicaeda merged commit aa4cf63 into develop Mar 21, 2023
@Mythicaeda Mythicaeda deleted the feat/split-sim-and-plan-start branch March 21, 2023 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change A change that will require updating downstream code database Anything related to the database feature A new feature or feature request simulation Anything related to the simulation domain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting simulation boundary on a subset of plan duration
3 participants