OMJulia simulate command returns error

Hi everyone,

Someone can help me to fix below error, when trying to simulate model:

ERROR: failed process: Process(C:/Users/USUARIO/AppData/Local/Temp/jl_gGQfHg/RLC.exe, ProcessExited(3221225785)) [3221225785]

Stacktrace:
[1] pipeline_error
@ .\process.jl:525 [inlined]
[2] run(::Cmd; wait::Bool)
@ Base .\process.jl:440
[3] run
@ .\process.jl:438 [inlined]
[4] (::OMJulia.var"#28#30"{Vector{String}})()
@ OMJulia C:\Users\USUARIO.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:612
[5] withenv(f::OMJulia.var"#28#30"{Vector{String}}, keyvals::Pair{String, String})
@ Base .\env.jl:161
[6] simulate(omc::OMJulia.OMCSession; resultfile::Nothing, simflags::Nothing)
@ OMJulia C:\Users\USUARIO.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:611
[7] simulate(omc::OMJulia.OMCSession)
@ OMJulia C:\Users\USUARIO.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:563
[8] top-level scope
@ REPL[14]:1

I am using Win 10, Julia-1.6.1 and OpenModelica1.17.0-64bit.

@BLI should be able to help on this one.

I can try to help, with some limitations :open_mouth: .

I drafted a first API between Python and OpenModelica ca. 2016-2017. With some modifications and limitations, this was implemented by a MSc student in Computer Science within the OpenModelica group at Linköping University, Sweden in the spring of 2017. After the student handed in his thesis, someone in the OpenModelica group touched up and extended the code, and published it as OMPython.

By this time, my interest had switched from Python to Julia, and the OpenModelica people made a Julia version (OMJulia) ca. 2018. The syntax was changed somewhat to reflect the idea of Julia, and some ideas that had seemed “cute” in OMPython were simplified. The result was OMJulia.

I developed several examples for OMPython, and tested these also for OMJulia. I also did some initial testing of a third tool, OMMatlab, but I’m not sure whether that has been finished.

In summary: I can perhaps help you when it comes to the use of OMJulia. But if there are some problems with the Julia coding behind OMJulia, we need to get in touch with the OpenModelica people.

So… I guess OMJulia questions are not really suitable for general questions within the Julia discourse (has OMJulia been registered as an official Julia package, or is it only available via OpenModelica downloads?).

Still, in order for me to help you, you need to provide me with more than a printout of error messages. You need to provide me with some Modelica code, and the accompanying Julia code where you try to run the Modelica code. This should probably not be your actual Modelica model, but rather a simplified model which illustrates the problem and generates a similar error message.

SO: can you provide me with a Modelica file and the relevant Julia file?

Hi Bernt,

Thank you for your good will to help me.
I’m not sure if OMJulia is official Julia package. It is listed on the juliapackages.com, but can be download from github.com/OpenModelica.

Attached Julia file:

using OMJulia

using Plots

pwd()

cd("C:\\Users\\USUARIO\\Documents\\My OModelica\\OMJulia") 

pwd()

RLC=OMJulia.OMCSession()

ModelicaSystem(RLC,"RLC.mo","RLC")

simulate(RLC)
ERROR: failed process: Process(`C:/Users/USUARIO/AppData/Local/Temp/jl_iPeNZr/RLC.exe`, ProcessExited(3221225785)) [3221225785]

Stacktrace:
 [1] pipeline_error
   @ .\process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base .\process.jl:440
 [3] run
   @ .\process.jl:438 [inlined]
 [4] (::OMJulia.var"#28#30"{Vector{String}})()
   @ OMJulia C:\Users\USUARIO\.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:612
 [5] withenv(f::OMJulia.var"#28#30"{Vector{String}}, keyvals::Pair{String, String})
   @ Base .\env.jl:161
 [6] simulate(omc::OMJulia.OMCSession; resultfile::Nothing, simflags::Nothing)
   @ OMJulia C:\Users\USUARIO\.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:611
 [7] simulate(omc::OMJulia.OMCSession)
   @ OMJulia C:\Users\USUARIO\.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:563
 [8] top-level scope
   @ REPL[8]:1

and Modelica file:

model RLC "A resistor-inductor-capacitor circuit model"
	type Voltage=Real(unit="V");
	type Current=Real(unit="A");
	type Resistance=Real(unit="Ohm");
	type Capacitance=Real(unit="F");
	type Inductance=Real(unit="H");
	parameter Inductance L=1;
	parameter Capacitance C=1/3;
	parameter Voltage V_in=3;
	parameter Current i_in=3;
	Voltage V_C;
	Voltage V_R;
	Voltage V_L;
	Current i_C;
	Current i_R;
	Current i_L;

initial equation
	V_C=V_in;
	i_C=i_in;
	
equation

	C*der(V_C)=i_C;
	V_R=i_R^3 +4*i_R;
	L*der(i_L)=V_L;
	i_C=i_R;
	i_R=i_L;
	V_C+V_L+V_R=0;
end RLC;

Best regards,
Dusan

Couple of questions…

  1. In the Modelica code, you have defined type “Resistance”, but don’t use it. Your equation for V_R… errors in units?

  2. Does your code run in OpenModelica?

Hi,

Yes, I´ve checked it before trying to simulate with Julia. OpenModelica runs simulation successfully.

Below is another example with the same type of error.
Julia script:

using OMJulia

using Plots

test=OMJulia.OMCSession()

ModelicaSystem(test,"test.mo","test")

simulate(test)
failed process: Process(`C:/Users/USUARIO/AppData/Local/Temp/jl_2pt03F/test.exe`, ProcessExited(3221225785)) [3221225785]


Stacktrace:
  [1] pipeline_error
    @ .\process.jl:525 [inlined]
  [2] run(::Cmd; wait::Bool)
    @ Base .\process.jl:440
  [3] run
    @ .\process.jl:438 [inlined]
  [4] (::OMJulia.var"#28#30"{Vector{String}})()
    @ OMJulia C:\Users\USUARIO\.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:612
  [5] withenv(f::OMJulia.var"#28#30"{Vector{String}}, keyvals::Pair{String, String})
    @ Base .\env.jl:161
  [6] simulate(omc::OMJulia.OMCSession; resultfile::Nothing, simflags::Nothing)
    @ OMJulia C:\Users\USUARIO\.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:611
  [7] simulate(omc::OMJulia.OMCSession)
    @ OMJulia C:\Users\USUARIO\.julia\packages\OMJulia\Fww7A\src\OMJulia.jl:563
  [8] top-level scope
    @ In[17]:1
  [9] eval
    @ .\boot.jl:360 [inlined]
 [10] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:1094

````
Modelica script:
````
  model test
  Real y;
  input Real x;
equation
  y=(x-10)^2;
end test;
````

OK – your Modelica code runs – with a warning – in OpenModelica 1.14.1, which is the one I have on my computer.

[1] 09:02:19 Translation Warning
[RLC: 24:2-24:18]: The following equation is INCONSISTENT due to specified unit information: V_R = i_R ^ 3.0 + 4.0 * i_R


[2] 09:02:19 Translation Warning
The units of following sub-expressions need to be equal:
- sub-expression "i_R ^ 3.0 + 4.0 * i_R" has unit "Gm6.s-9.A-3.g3"
- sub-expression "V_R" has unit "V"

[3] 09:02:19 Scripting Notification
Check of RLC completed successfully.

Result (some variables):

I can now run it from Julia (I have Julia v. 1.6.1 in my laptop; I run it from a Jupyter notebook, which is located in the same directory as the Modelica file):

using OMJulia, Plots

RLC = OMJulia.OMCSession()
ModelicaSystem(RLC,"RLC.mo","RLC")

I can query the simulation settings:

julia> getSimulationOptions(RLC)
Dict{Any, Any} with 5 entries:
  "startTime" => "0"
  "stopTime"  => "1"
  "solver"    => "dassl"
  "stepSize"  => "0.002"
  "tolerance" => "1e-006"

I can check which variables are available:

showQuantities(RLC)

resulting in a data frame:

The above is useful to check the names you can request (“get”) after simulation…

Next, simulating the system and getting results:

simulate(RLC)
tm, v_L, L, v_R, i_C = getSolutions(RLC,["time","V_L", "L", "V_R", "i_C"]);

plot(tm,[v_L,L,v_R,i_C],label=["V_L" "L" "V_R" "i_C"])

leading to:

Can you recheck your code and do what I’ve done above? If your code still doesn’t work, two possible explanations:

  • there is something wrong with your OMJulia installation, or
  • OMJulia has not been updated to the latest versions of OpenModelica

To get you further, you may need to get in touch with the OpenModelica people (I hope I can help you with that; depends on whether the developer is still with the OpenModelica group).

Thanks for detailed answer!
I’ve repeated all steps you shown here, and could replicate everything, except simulate() which throw the error again :confounded:

Yes, It would be nice if someone from OpenModelica could help me.
I was thinking to post a similar question in OM forum. Eventually I gave up not knowing which forum is appropriate for this issue.

Thanks again :+1:

I would first ask on stackoverflow with the appropriate tags (openmodelica, modelica, julia)

Thanks for the suggesstion.
I’ve tried, but just one question taged modelica & julia.

I’ve contacted the guy who implemented OMJulia to see if he can help. I don’t know if he is still with the OpenModelica people, but I’ll let you know if I hear from him.

@cubakija , You can make an issue directly in the OMJulia github repository, here is the link https://github.com/OpenModelica/OMJulia.jl/issues.

I ran your example “RLC.mo” and it is working for me and I cannot reproduce the error. see below

julia> using OMJulia                                                                                                                                                                                                                                                                                                                                                                          
julia> omc = OMJulia.OMCSession()                                                                                                                                                                                                                                                                                                                                                             
julia> ModelicaSystem(omc, "RLC.mo", "RLC")                                                                                                                                                                                                                                                                                                                                                   
julia> sendExpression(omc, "getVersion()")                                                                                                                                                     
"OpenModelica v1.19.0-dev-66-g2e932dc95f (64-bit)"                                                                                                                                                                                                                                                                                                                                            
julia> simulate(omc)                                                                                                                                                                           
LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.                                                                                                
LOG_SUCCESS       | info    | The simulation finished successfully.                                                                                                                                                                                                                                                                                                                           
julia> getWorkDirectory(omc)                                                                                                                                                                   
"C:/Users/arupa54/AppData/Local/Temp/jl_onboRe"                                                                                                                                                                                                                                                                                                                                   
julia> getSolutions(omc, "C")                                                                                                                                                                  
1-element Array{Array{Float64,1},1}:                                                                                                                                                           
 [0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333
333333333  …  0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.333333333333333
3, 0.3333333333333333]

From the above discussion i see that it works in OMEdit, but not from OMJulia, We made a new fix to OMJulia regarding the simulation executable in windows, https://github.com/OpenModelica/OMJulia.jl/commit/980eba4f5bb30c58b0935f949d0d84889a771f7d, This is not released yet in the julia packages, So can you make sure you have the latest changes of OMJulia, If not i suggest you to download OMJulia directly from github repository to have the latest changes

julia> import Pkg
julia> Pkg.add(Pkg.PackageSpec(url="https://github.com/OpenModelica/OMJulia.jl"))

If this does not work, I see there should be a problem in temp directory, Try to start the julia as administrator mode and run the examples and see, otherwise there is an API, “getWorkDirectory()” which should give you the temp directory folder

>>> getWorkDirectory("omc")
C:/Users/arupa54/AppData/Local/Temp/jl_onboRe

Go into this directory and you will find “RLC.exe” and click the executable this should tell the problem.

Answer from OMJulia developer (Arun):

  • Your code runs on his computer. I think he used Julia v.1.4.2 (on Linux? – correction: Arun says Windows 10, see below), and most likely the latest version of OpenModelica.
  • He says that based on the error message you get, ‘… it seems there is problem in the temp directory, The simulation executable “RLC.exe” is failing, So I guess there should be some kind of permission error when executing the “RLC.exe” …’

So he suggests you do the following:

  1. Query the temp directory: julia> getWorkDirectory("RLC")
  2. Go to this directory on your computer. You should find a file RLC.exe there.
  3. Run file RLC.exe by double clicking on it. If there is a permission problem, or something, you will be told.
  4. In case of a permission problem, run Julia as administrator to see if this solves the problem.

If this doesn’t fix your problem, post an issue at https://github.com/OpenModelica/OMJulia.jl/issues .

OK?

@BLI I ran with windows-10

Thank you both guys.
I’ve tried with a new fix, but got the same error. Identical thing when I start Julia as administrator, but
when I execute RLC.exe, it gives me the following error message:

Code execution cannot continue because these files were not found: 
libsundials_nvecserial.dll
libsundails_idas.dll
libsundails_cvode.dll
libsundails_kinsol.dll
This problem can be solved reinstalling the program.

What program it is referring to, Julia?

OpenModelica uses Sundials solvers, and when you run OMJulia, you are essentially solving the problem in OpenModelica. So it seems like – when run from Julia – the produced RLC.exe file cannot find these DLLs, but when run from within OpenModelica editor, these files are found…

I think Arun needs to be consulted – or: write an issue as suggested by Arun.

@cubakija It seems the Dlls are not found, and it is because of the DLL’s are not in the PATH environment variable, I still doubt that you have not updated the OMJulia with the master version, I suggest you to uninstall OMJulia and install the OMJulia from master. If the error persists again, please add the “OpenModelica1.17.1/bin/” to the PATH environment variable and that should fix the problem

Curiously there seems to be a typo in some error messages (sundails), does this look for the right files?

I removed OMJulia and install it again:

(@v1.6) pkg> status
      Status `C:\Users\USUARIO\.julia\environments\v1.6\Project.toml`
  [7073ff75] IJulia v1.23.2
  [0f4fe800] OMJulia v0.1.0 `https://github.com/OpenModelica/OMJulia.jl#master`
  [91a5bcdd] Plots v1.15.2

then check PATH variable is OK,

C:\Program Files\OpenModelica1.17.0-64bit\bin

and simulate it, I’ve got a new error when executing RLC. exe file:

RLC.exe - Entry point not found
Procedure entry point not found
_gfortran_os_error_at in the dynamic link library
C: \ Users \ USER \ AppData \ Local \ Temp \ jl_y6LgBj \ RLC.exe.

I will post an issue at OMJulia Github

@bilderbuchi
The typo was mine, as I manually copied file names,