fix: handle state events for ME2/ME3 on consecutive simulations#412
fix: handle state events for ME2/ME3 on consecutive simulations#412jschueller wants to merge 1 commit into
Conversation
|
hello @modelonrobinandersson @PeterMeisrimelModelon, what do you think ? |
|
@jschueller Sorry for the late response, I am aware of the various MRs, but we are a bit busy with other things right now. I'll get back to you when I can find some room. |
|
Do you happen to have a better reproducer of the original issue you are trying to fix here? While the added tests here would certainly traverse the added lines, the tests pass on the current master. |
|
Right, Feedthrough.fmu has 0 event indicators, so get_event_info() is never called, and the enter_event_mode → event_update → enter_continuous_time_mode sequence from the fix runs against a model with no events at all. The updated tests (both FMI2 and FMI3 now use BouncingBall.fmu) at least:
|
…initialize=False When continuing a simulation with initialize=False (e.g. after set_fmu_state() + input changes), the FMU must process potential state events before resuming integration. The FMI spec requires calling fmi2NewDiscreteStates / fmi3UpdateDiscreteStates after fmi2SetFMUstate since restored state + new inputs may trigger events. Previously, time-event checks at start time only covered ME1 and used unreliable event_info flags. PR modelon-community#109's unconditional event_update() was too aggressive because it ran on the initialize=True path too, where event_update was already called during init, violating the FMI state machine. This fix: - For initialize=False with ME2/ME3: enter_event_mode + event_update + enter_continuous_time_mode to process pending events (e.g. after set_fmu_state + input changes) - For initialize=True with ME2/ME3: extend the existing time-event check (equivalent to the ME1 check that was already in place) with proper mode transition wrappers - ME1 behavior unchanged - Add enter_event_mode() no-op override to Dummy_FMUModelME2 to prevent segfault when algorithm driver calls enter_event_mode() on test stubs Fixes modelon-community#159 Fixes modelon-community#72 Closes modelon-community#109 Tests added: - test_fmi2.py::test_consecutive_simulation_with_initialize_false - test_fmi3_sim.py::TestSimulation::test_consecutive_simulation_with_initialize_false
|
actually maybe this is a better reproducer: run.py.txt |
When continuing a simulation with initialize=False (e.g. after set_fmu_state()
Previously, time-event checks at start time only covered ME1 and used unreliable event_info flags. PR #109's unconditional event_update() was too aggressive because it ran on the initialize=True path too, where event_update was already called during init, violating the FMI state machine.
This fix:
Fixes #159
Tests added: