Skip to content

Simulation with Resultfile or Flags Fail to execute #206

Closed
@NilsDressler

Description

@NilsDressler

Description

When calling
OMPython.simulaute(resultfile='/home/user/modelica/testfile0.mat')
with a result file (and most likely also with other flags, the following log message is shown

Failed to simulate simulation: [Errno 2] No such file or directory: '/tmp/tmp37u5_obx/Package.Simulation -r=/home/user/modelica/testfile0.mat'

Steps to reproduce

Minimal Example that fails

from os.path import expanduser
from OMPython import ModelicaSystem

home_dir = expanduser("~")

model_path = home_dir + '/modelica/resultfilebug/'
model_file_name = 'BouncingBall.mo'
model_name = 'BouncingBall' 
mod = ModelicaSystem(model_path + model_file_name, model_name )

mod.buildModel()

result_file_path = home_dir + '/modelica/resultfilebug/resultfiles/'
result_file_name = 'resultfile_0.mat'

mod.simulate(resultfile=result_file_path+result_file_name)

Throws followingexception:

Exception has occurred: FileNotFoundError (note: full exception trace is shown but execution is paused at: _run_module_as_main)
[Errno 2] No such file or directory: '/tmp/tmpj5k_1p6k/BouncingBall -r=~/modelica/resultfilebug/resultfiles/resultfile_0.mat'

Even though the file exists in my file system

ls /tmp/tmpqmbz5d57/BouncingBall
/tmp/tmpqmbz5d57/BouncingBall

Running

user@machine:~$ /tmp/tmpqmbz5d57/BouncingBall -r=/home/user/modelica/resultfilebug/resultfiles/resultfile_0.mat

LOG_ASSERT | debug | simulation_input_xml.c: Error: can not read file BouncingBall_init.xml as setup file to the generated simulation code.
Execution failed!

While

user@machine:/tmp/tmpq5rla9at$ ./BouncingBall -r=/home/user/modelica/resultfilebug/resultfiles/resultfile_0.mat

LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
LOG_SUCCESS | info | The simulation finished successfully.

Expected behavior

The model should just build and return the following log messages

LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.

Screenshots

If applicable, add screenshots to help explain your problem.

Version and OS

  • Python Version: Python 3.10.12
  • OMPython Version: 3.5.1
  • OpenModelica Version: 1.22.3
  • OS: Windows 11 64 bit - Code run from WSL :Ubuntu 22.04.4 LTS

Additional context

When digging into the problem and debugging I came across this:

The error message suggests that the subprocess is unable to find the executable file /tmp/tmpqmbz5d57/BouncingBall -r=/home/user/modelica/testfile0.mat

The issue here is that the provided cmd is being interpreted as a single command with spaces in its name. Instead, you should separate the executable path and the command-line arguments into separate elements of the cmd list.

So the problem is created within

p = subprocess.Popen(cmd, env=my_env)

A solution to the problem is how cmd is created. If it is a list with

  • getExeFile
  • override
  • csvinput
  • r
  • simflags

as seperate list entries, it works with my system configuration

Metadata

Metadata

Assignees

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