Skip to content

setSimulationOptions is not processed properly with OM v1.26.3 and OMPython v3.6 #455

Closed

Description

@cvTHM

Description

I run into an unexpected behaviour after an update from OpenModelica v1.25.4 to v1.26.3:
I am using OMPython v3.6 for parameter studies, mainly with the ModelicaSystem()-commands.

When I try to set simulation options to a model, I can do so by the common command mod.setSimulationOptions([...]) (Accessing these options via mod.getSimulationOptions() yields exactly the entered parameters...). However, these parameters do not seem to be transferred to the model properly as they are ignored and the default values entered in the simulation setup context or annotation(experiment(...)) section in the model are used.

Steps to Reproduce

Consider the following MWE which is embedded in a package ("MWE_package") (see screenshot):

within MWE_package;

model testmodel
parameter Real scale = 1;
Real Tout;
equation
Tout = time*scale;

annotation(
    experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.1));
end testmodel;
Image

Editing this with the following lines of code and OMPython:

from OMPython import ModelicaSystem

from pathlib import Path


lib_path = Path(r"C:\Users\Voelzel\MWE_package\package.mo")
resfilepath = Path(r"D:\testres")
model_name = "MWE_package.testmodel"

startTime = 0
stopTime = 100
stepSize = 1

scaling = 2


mod = ModelicaSystem(
        fileName = str(lib_path), 
        modelName = model_name
        )

mod.setParameters([
    f"scale={scaling}",
])

mod.setSimulationOptions([
    f"startTime={startTime}",
    f"stopTime={stopTime}",
    f"stepSize={stepSize}",
])

mod.simulate(resultfile = str(resfilepath) + '/outfile.mat')

... gives the unexpected result shown in the following screenshot for the output variable Tout:

Image

As you can see, the simulation stop time time still remains at 10 s instead of the entered 100 s (the same applies to the start time or the step size as well, by the way).
The parameter scale is changed as expected.
Accessing the simulation options after the editing lines above gives:

mod.getSimulationOptions()

{'startTime': '0',
 'stopTime': '100',
 'stepSize': '1',
 'tolerance': '1e-06',
 'solver': 'dassl',
 'outputFormat': 'mat'}

Does anyone have an idea why setting the simulation options from OMPython does not work here, anymore?
Thanks in advance!

Version and OS

  • OpenModelica Version: 1.26.3
  • OS: Windows 11, 64 bit
  • OMPython version 3.6

Activity

  1. adeas31 commented on Mar 18, 2026

    @adeas31
    Member

    OMEdit and OMPython do not have any direct integration. They operate independently of each other.

    OMPython is a scripting interface that communicates with the OpenModelica compiler, while OMEdit is a graphical user interface for modeling and simulation. Any settings or changes made in one are not automatically reflected in the other.

    If you run a simulation in OMPython, you can manually load the resulting output file into OMEdit, but there is no shared state or synchronization between the two environments.

  2. cvTHM commented on Mar 18, 2026

    @cvTHM
    Author

    Thanks for that answer, I am aware of that structure - however, in the former OpenModelica version 1.25.4, this behaviour could not be observed and it was very convenient to be able to set simulation options from a session using OMPython.

  3. adeas31 commented on Mar 18, 2026

    @adeas31
    Member

    As I understand, you are trying to change the stopTime with ModelicaSystem.setSimulationOptions and this is not working.

  4. cvTHM commented on Mar 18, 2026

    @cvTHM
    Author

    As I understand, you are trying to change the stopTime with ModelicaSystem.setSimulationOptions and this is not working.

    In the combination OpenModelica v1.25.4 and OMPython v3.6 this was working quite well.

  5. adeas31 commented on Mar 18, 2026

    @adeas31
    Member

    I moved the issue to OMPython repository.

    As I remember this is already fixed in the master version. The latest OM interface is changed and now simulation options are used as arguments. See #400 , #402

    @syntron ?

  6. syntron commented on Mar 18, 2026

    @syntron
    Contributor

    As I remember this is already fixed in the master version. The latest OM interface is changed and now simulation options are used as arguments. See #400 , #402

    Correct - OMPython 3.6 (and 4.0.0) only supports OpenModelica < 1.26.0 if taking into account the simulation options. Higher versions use a modified interface for the simulation options. OMPython was adapted for this (=> PR #400, PR #402). This was done as a backward compatible change - all OM version can be used!

    Perhaps it would make sense to create an OMPython 4.0.1 with just PR #400 as bugfix release? => see PR #456 (linter checked / else untested). PR #402 depends on changes in between; thus, I would only take the one commit ...

  7. syntron commented on Mar 18, 2026

    @syntron
    Contributor

    As I'm not sure about the usage of OMPython, the patches provide the code for OMPython 3.6.1 (PR #457) and OMPython 4.0.1 (PR #456)

    @cvTHM could you please test?

  8. cvTHM commented on Mar 19, 2026

    @cvTHM
    Author

    @syntron , Thank you for your hints here. I tested your commit for OMPython v3.6.1 from PR #457 and it works well with OpenModelica v1.26.3. The simulation options can be set again with the command mod.setSimulationOptions(...).
    The workaround for backward compatibility would be, as I understand it, to simply include all setting regarding simulation options in the simulation flags passed to the mod.simulate() command in OMPython. I think this all solves my issue here!

  9. adeas31 commented on Mar 19, 2026

    @adeas31
    Member

    @cvTHM could you please also test PR #456 for v4.0.1. If that works well then I will make a new patch release 4.0.1 and perhaps there is no need to make 3.6.1.

  10. cvTHM commented on Mar 19, 2026

    @cvTHM
    Author

    Hi, PR #456 for OMpython v4.0.1 works as well as expected - simulation options can be set for a ModelicaSystem() instance by mod.setSimulationOptions({"key1":value1, ...}).

  11. self-assigned this
    on Apr 20, 2026
  12. added theissue type on Apr 20, 2026
  13. adeas31 commented on Apr 20, 2026

    @adeas31
    Member

    OMPython v4.0.1 released with the fix.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions