Exporting Dynamic Models#

This page explains how to export NeurEco Dynamic models (both ODE and Convolutional Dynamic) as FMUs for deployment and integration, and how to save them in the native NeurEco format.

Export Formats#

NeurEco Dynamic models can be exported to:

Format

Use Case

Compatibility

FMU

Simulation tools, digital twins

MATLAB/Simulink, Dymola, OpenModelica, any FMI-compatible tool

Native

NeurEco Python API

.ernn (ODE) or .ecnn (Convolutional Dynamic)

There is no C source or ONNX export for Dynamic models.

FMU Export#

Functional Mock-up Units (FMU) are the standard for model exchange in simulation environments. NeurEco exports FMU 2.0 compliant packages.

  1. Open your trained model and click Export

  2. Click FMI for Co-Simulation 2.0

  3. In the save dialog, choose the name and folder of the .fmu file

  4. The .fmu file is created in the chosen folder

FMU Export Parameters#

In Python, export_fmu takes one argument, fmu_path: the path of the .fmu file to write (the .fmu extension is added when missing). On the command line, exportFMU takes the model file, the .fmu file and the platform flag 3.

Using Exported FMUs#

In MATLAB/Simulink:

  1. Use the FMU Import block from the Simscape library

  2. Point to your exported .fmu file

  3. Connect inputs and outputs to your simulation

In Dymola/OpenModelica:

  1. Import the FMU using the standard FMU import function

  2. The model appears as a component with defined inputs/outputs

  3. Connect to your system model

In Python (FMPy):

from fmpy import simulate_fmu
import numpy as np

# Simulate the FMU
result = simulate_fmu(
    'my_model.fmu',
    start_time=0,
    stop_time=10,
    step_size=0.01,
    input=input_data,  # Your input trajectory
)

Native Format#

The native NeurEco format preserves all model information and allows continued work in NeurEco.

File extensions:

  • ODE models: .ernn

  • Convolutional Dynamic models: .ecnn

Saving a model:

# During build (recommended)
config = Dynamic.ODEBuildConfig(
    # ...
    write_model_to="./model/my_model.ernn",
)

# Or save explicitly
model.save("./model/my_model.ernn")

Loading a model:

model = Dynamic.ODE()
model.load("./model/my_model.ernn")

Export Considerations#

ODE vs. Convolutional Dynamic FMUs#

Aspect

ODE FMU

Convolutional Dynamic FMU

Initialization

Requires initial state or uses steady-state

Automatic (handles internally)

State variables

Exposed as FMU states

Hidden (window buffer)

Time step

Must match training dt

Must match training dt

Time Step Matching#

Warning

The simulation time step in the FMU environment must match the time step used during training. Using a different time step will produce incorrect results.

To check the training time step:

# The time step is determined by your training data
# Verify it matches your simulation setup
# Time lives in column 0 of each excitation array
dt_training = train_exc_list[0][1, 0] - train_exc_list[0][0, 0]
print(f"Training time step: {dt_training}")

Platform Compatibility#

FMUs contain platform-specific binaries. An FMU exported by NeurEco contains binaries for both Windows and Linux, whichever system it was exported on:

  • Windows: Windows DLLs in binaries/win64

  • Linux: Linux shared objects in binaries/linux64

The same .fmu file can therefore be used on Windows and on Linux. The Linux binaries need glibc 2.28 or newer, as in Red Hat Enterprise Linux 8 and later, and they carry their own C++ runtime, so they also load in simulation tools that use an older one.

Complete Export Example#

from NeurEco import NeurEcoDynamic as Dynamic
import os

# Load model
model = Dynamic.ODE()
model.load("./trained_model.ernn")

# Create export directory
os.makedirs("./export", exist_ok=True)

# Export to FMU
model.export_fmu("./export/model.fmu")
print("FMU exported to ./export/model.fmu")

# Verify exports
print("\nExported files:")
for root, dirs, files in os.walk("./export"):
    for file in files:
        print(f"  {os.path.join(root, file)}")

Next Steps#