OMPython icon indicating copy to clipboard operation
OMPython copied to clipboard

convertMo2Fmu fails without any log

Open javiarrobas opened this issue 1 year ago • 3 comments

Description

When using ModelicaSystem.convertMo2Fmu many times does not succeed without throwing any log or error prompt. This makes it very difficult to debug where the issue may be coming from. It'd be great if the error information from the OMC could be passed somehow to the user.

Steps to Reproduce

git clone [email protected]:positive-energy-districts/moped.git
cd moped
git checkout issue130_updateOmc
cd MoPED/Resources/Scripts/tests
make build # This builds a Docker image with all dependencies, included OMC and OMPython
make run # Starts the associated container which is called moped and mounts our Modelica library
docker exec -it moped bash # Get into the container
cd MoPED/Resources/Scripts/fmu # Go to folder with script that compiles FMU
python3 parser.py # Try to compile the FMU model MoPED.Districts.Layout4RC

That script basically aims to compile model MoPED.Districts.Layout4RC of our library and then parse certain instances in the model. Just FYI: the script invokes the following Python method for the compilation:

def compile_fmu(model_path, file_name):
    '''Compile the fmu.

    Returns
    -------
    model_path : str
        Path to Modelica class model to be compiled.
    file_name : str
        Path to .mo file with the Modelica model.

    '''

    # COMPILE FMU
    from OMPython import OMCSessionZMQ, ModelicaSystem
    omc = OMCSessionZMQ()
    model = ModelicaSystem(fileName=file_name, modelName=model_path,
                           lmodel=[os.path.join(get_root_path(),'MoPED','package.mo')],
                           commandLineOptions="-d=evaluateAllParameters")
    print('List of defined Modelica class names: {}'.format(omc.sendExpression("getClassNames()")))
    print('Compiling FMU model...')
    fmu_path = model.convertMo2Fmu(version="2.0", fmuType="cs", fileNamePrefix="<default", includeResources=True)
    print("FMU model compiled to: {}".format(fmu_path))

    return fmu_path

In the steps above, the compilation works when using the main branch (that is, if you skip the third line to checkout issue130_updateOmc. In this merge request you can see that the only difference between both branches is that in the main one, we use OpenModelica 1.21 whereas in the other one we use the nightly OpenModelica 1.23 version. Note that I've implemented a check with OpenModelica 1.22 and it does not work either.

Expected Behavior

Either the FMU compiles or some error prompt is passed to the user to give an idea of how the issue can be fixed.

Screenshots

The output that I get when following the steps above is: image

Notice that the errors shown there take place after the FMU is not being compiled.

Version and OS

  • Python Version: Python 3.10.12
  • OMPython Version: OMPython 3.4.0
  • OpenModelica Version: OpenModelica 1.23.0~dev-59-g7a41456
  • OS: ubuntu:20.04, 64 bit

(These are the versions inside the Docker container environment)

Additional Context

When the FMU compilation is successful, everything works like a charm, and the compilation of this particular model used to work when using previous versions of the OMC, namely with OpenModelica 1.21.0-1. I'm not clear on whether this is an issue with the OMC or with OMPython, so I may open an issue there as well.

javiarrobas avatar Oct 20 '23 14:10 javiarrobas

@arun3688 what do you think?

casella avatar Oct 20 '23 17:10 casella

@JavierArroyoBastida I am trying to look into the issue, i am unable to clone the repository, can you just provide your models in a zip file so that i can look into it

arun3688 avatar Oct 25 '23 08:10 arun3688

Hey @arun3688, thank you very much for looking into this! Please find here both versions of the repository I mentioned above. moped-issue130_updateOmc.zip moped-main.zip Please let me know if you have questions or there is anything I can do from my side.

javiarrobas avatar Oct 25 '23 09:10 javiarrobas