Skip to content

--generateSymbolicLinearization causes error for some models #274

Open
@ondras12345

Description

@ondras12345

Description

Current implementation of ModelicaSystem sets --generateSymbolicLinearization in __init__, regardless of whether the user actually wants to perform linearization. This causes an error for some models, e.g. this one:

model.mo:

model MyModel
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1 annotation(
    Placement(transformation(origin = {-40, 40}, extent = {{-6, -6}, {6, 6}})));
  Modelica.Clocked.RealSignals.Sampler.Hold hold1 annotation(
    Placement(transformation(origin = {20, 40}, extent = {{-6, -6}, {6, 6}})));
  Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock periodicClock1(period = 0.1)  annotation(
    Placement(transformation(origin = {-80, 0}, extent = {{-6, -6}, {6, 6}})));
  Modelica.Blocks.Interfaces.RealInput u annotation(
    Placement(transformation(origin = {-86, 40}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {-86, 30}, extent = {{-20, -20}, {20, 20}})));
  Modelica.Clocked.RealSignals.Periodic.TransferFunction transferFunction(b = {1}, a = {1, -1})  annotation(
    Placement(transformation(origin = {-12, 40}, extent = {{-10, -10}, {10, 10}})));
  Modelica.Blocks.Interfaces.RealOutput y annotation(
    Placement(transformation(origin = {60, 40}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {60, 40}, extent = {{-10, -10}, {10, 10}})));
equation
  connect(periodicClock1.y, sample1.clock) annotation(
    Line(points = {{-74, 0}, {-40, 0}, {-40, 32}}, color = {175, 175, 175}));
  connect(u, sample1.u) annotation(
    Line(points = {{-86, 40}, {-48, 40}}, color = {0, 0, 127}));
  connect(sample1.y, transferFunction.u) annotation(
    Line(points = {{-34, 40}, {-24, 40}}, color = {0, 0, 127}));
  connect(transferFunction.y, hold1.u) annotation(
    Line(points = {{0, 40}, {12, 40}}, color = {0, 0, 127}));
  connect(y, hold1.y) annotation(
    Line(points = {{60, 40}, {26, 40}}, color = {0, 0, 127}));

annotation(
    uses(Modelica(version = "4.0.0")));
end MyModel;

with demo.py:

#!/usr/bin/env python3
from OMPython import ModelicaSystem

# note the raiseerrors=True
mod = ModelicaSystem("model.mo", "MyModel", ["Modelica"], raiseerrors=True)
# this should be enough to demonstrate the error

Running demo.py results in the following exception:

Traceback (most recent call last):
  File "/home/ondra/tmp/lin-demo/./demo.py", line 4, in <module>
    mod = ModelicaSystem("model.mo", "MyModel", ["Modelica"], raiseerrors=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ondra/source/repos/OMPython/OMPython/ModelicaSystem.py", line 228, in __init__
    self.buildModel(variableFilter)
  File "/home/ondra/source/repos/OMPython/OMPython/ModelicaSystem.py", line 352, in buildModel
    self._check_error()
  File "/home/ondra/source/repos/OMPython/OMPython/ModelicaSystem.py", line 332, in _check_error
    self._raise_error(errstr=errstr)
  File "/home/ondra/source/repos/OMPython/OMPython/ModelicaSystem.py", line 336, in _raise_error
    raise ModelicaSystemError(f"OM error: {errstr}")
OMPython.ModelicaSystem.ModelicaSystemError: OM error: [/var/lib/jenkins/ws/LINUX_BUILDS/tmp.build/openmodelica-1.25.0/OMCompiler/Compiler/BackEnd/Differentiate.mo:268:5-268:157:writable] Error: Derivative of expression "transferFunction.x1 = (transferFunction.u - transferFunction.a[2] * previous(transferFunction.x[1])) / transferFunction.a[1]" w.r.t. "dummyVarD" is non-existent.
Error: Internal error SymbolicJacobian.deriveAll failed
[/var/lib/jenkins/ws/LINUX_BUILDS/tmp.build/openmodelica-1.25.0/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:2474:7-2474:74:writable] Error: Internal error SymbolicJacobian.generateSymbolicJacobian failed
[/var/lib/jenkins/ws/LINUX_BUILDS/tmp.build/openmodelica-1.25.0/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:2265:9-2265:79:writable] Error: Internal error function createJacobian failed

Ideally, it should be possible to simulate this model while keeping raiseerrors=True.

Version and OS

  • Python Version: 3.12.3
  • OMPython Version: 0b63a2b
  • OpenModelica Version: 1.25.0
  • OS: Ubuntu 24.04.2 LTS

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions