Skip to content

Question: Restoring FMU state across sessions for perpetual/batch simulation fails with access violation #812

@prafull-cognite

Description

@prafull-cognite

Summary:
I am running a perpetual simulation using FMPy and a Co-Simulation FMU (FMI 2.0, Python 3.12, Windows). My workflow is to process real data in batches: I run the simulation on the currently available data, then pause and save the FMU state. When new data arrives (which could be hours or days later), I want to resume the simulation from exactly where I left off by restoring the saved state.

What I am trying:

  • Save the FMU state after running the simulation for some time (not just after initialization).
  • Store the FMU state bytes to disk (using pickle or direct file write).
  • Later, after a kernel restart or process termination, re-instantiate the FMU from the same .fmu file, and try to restore the saved state using deSerializeFMUstate and setFMUstate.

Problem:

  • When I try to restore the FMU state in a new Python session (after re-instantiating the FMU), I get:
    OSError: exception: access violation writing 0xXXXXXXXXXXXXXXX
    

Questions:

  • Is it possible to serialize an FMU state after simulation has advanced, and later restore it into a new FMU instance (across sessions or kernel restarts)?
  • Does FMPy or the FMI 2.0 standard support this use case for Co-Simulation FMUs?
  • If not, is there a recommended approach for running perpetual simulations with batch data, where each run may be separated by hours or days?
  • If this is a limitation of the FMU implementation, can FMPy detect and provide a clearer error or warning?

Environment:

  • FMPy version: latest
  • FMU type: Co-Simulation (FMI 2.0)
  • Python version: 3.12
  • OS: Windows

Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions