OpenModelica / OMSimulator

The OpenModelica FMI & SSP-based co-simulation environment.
Other
73 stars 50 forks source link

OMSimulator CI tests of Buildings are reported to end successfully while they probably don't #1391

Open casella opened 4 days ago

casella commented 4 days ago

After #1271 was fixed, the master-fmi report for Buildings 11.0.0, which uses OMSimulator, reports 1462 model simulating successfully, whereas the master-fmi-fmpy, that uses FMPy, only reports 1355. So, it seems OMSimulator has a higher simulation success rate.

However, I compared some results and I found them incorrectly reported. For example, the Buildings.ThermalZones.Detailed.Examples.FFD.NaturalConvectionWithControl simulation is reported to fail during simulation (orange cell) in the master-fmi-fmpy report, more specifically during initialization, with the following error log:

python3 -m fmpy simulate  --output-file Buildings_11_Buildings.ThermalZones.Detailed.Examples.FFD.NaturalConvectionWithControl_res.csv --start-time 0 --stop-time 3600 --timeout 400 --relative-tolerance 1e-06 --interface-type ModelExchange --solver CVode --output-interval 1.44 Buildings_11_Buildings_ThermalZones_Detailed_Examples_FFD_NaturalConvectionWithControl.fmu
src->dim_size[0] != dst->dim_size[0], 0 != -1
LOG_ASSERT        | debug   | Failed to copy array. Dimension sizes are not equal and destination array is not flexible.
LOG_ASSERT        | error   | Failed to solve the initialization problem with global homotopy with equidistant step size.
LOG_ASSERT        | debug   | Unable to solve initialization problem.
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/hudson/saved_omc/libraries/.local/lib/python3.10/site-packages/fmpy/__main__.py", line 4, in <module>
    main()
  File "/home/hudson/saved_omc/libraries/.local/lib/python3.10/site-packages/fmpy/command_line.py", line 169, in main
    result = simulate_fmu(args.fmu_filename,
  File "/home/hudson/saved_omc/libraries/.local/lib/python3.10/site-packages/fmpy/simulation.py", line 759, in simulate_fmu
    result = simulateME(model_description, fmu, start_time, stop_time, solver, step_size, relative_tolerance, start_values, apply_default_start_values, input, output, output_interval, record_events, timeout, step_finished, validate, set_stop_time)
  File "/home/hudson/saved_omc/libraries/.local/lib/python3.10/site-packages/fmpy/simulation.py", line 933, in simulateME
    fmu.exitInitializationMode()
  File "/home/hudson/saved_omc/libraries/.local/lib/python3.10/site-packages/fmpy/fmi2.py", line 280, in exitInitializationMode
    return self.fmi2ExitInitializationMode(self.component)
  File "/home/hudson/saved_omc/libraries/.local/lib/python3.10/site-packages/fmpy/fmi2.py", line 215, in w
    raise FMICallException(function=fname, status=res)
fmpy.fmi1.FMICallException: fmi2ExitInitializationMode failed with status 3 (error).

The same test in the master-fmi log reports a success (green), even though there is no result file to verify and the simulation log also mentions an initialization error.

/home/hudson/saved_omc/OMSimulator/install/bin/OMSimulator -r=Buildings_11_Buildings.ThermalZones.Detailed.Examples.FFD.NaturalConvectionWithControl_res.mat --tempDir=temp_Buildings_11_Buildings_ThermalZones_Detailed_Examples_FFD_NaturalConvectionWithControl_fmu --startTime=0 --stopTime=3600 --stepSize=1.44 --timeout=400 --tolerance=1e-06 Buildings_11_Buildings_ThermalZones_Detailed_Examples_FFD_NaturalConvectionWithControl.fmu
src->dim_size[0] != dst->dim_size[0], 0 != -1
LOG_ASSERT        | debug   | Failed to copy array. Dimension sizes are not equal and destination array is not flexible.
LOG_ASSERT        | error   | Failed to solve the initialization problem with global homotopy with equidistant step size.
LOG_ASSERT        | debug   | Unable to solve initialization problem.
error:   [fmi2logger] /var/lib/jenkins1/ws/OpenModelicaLibraryTestingWork_2/OpenModelicaLibraryTesting/Buildings_11_Buildings.ThermalZones.Detailed.Examples.FFD.NaturalConvectionWithControl/temp_Buildings_11_Buildings_ThermalZones_Detailed_Examples_FFD_NaturalConvectionWithControl_fmu/model-1nct0frg/temp/0001_Buildings_11_Buildings_ThermalZones_Detailed_Examples_FFD_NaturalConvectionWithControl (logFmi2Call): fmi2EnterInitializationMode: terminated by an assertion.
error:   [initialize] fmi2_import_exit_initialization_mode failed for FMU "model.root.Buildings_11_Buildings_ThermalZones_Detailed_Examples_FFD_NaturalConvectionWithControl"
error:   [initialize] Initialization of system "model.root" failed
error:   [simulate] Model "model" is in wrong model state
info:    0 warnings
info:    4 errors

I guess the exit code of OMSimulator is wrong - in this case, OMSimulator should return a non-zero exit code, since the simulation was not successful.

@lochel, please check with @adrpo how OMSimulator should terminate in these cases, in order to get correct CI test reports.

lochel commented 3 days ago

The model appears to get stuck in fmi2_freeInstance, which suggests there might be an issue with the FMU itself. It would be helpful if someone could investigate the FMI export to identify potential problems with the generated FMU.

casella commented 3 days ago

@arun3688 could you please check?

@lochel, what is strange is that the same FMU works fine with FMPy. Is OMSimulator calling the FMU differently?

lochel commented 3 days ago

The code gets stuck inside fmi2_freeInstance, specifically when invoking callExternalObjectDestructors:

  /* call external objects destructors */
  comp->fmuData->callback->callExternalObjectDestructors(comp->fmuData, comp->threadData);

The callExternalObjectDestructors implementation appears as follows:

void NaturalConvectionWithControl_callExternalObjectDestructors(DATA *data, threadData_t *threadData)
{
  if(data->simulationInfo->extObjs)
  {
    omc_Modelica_Blocks_Types_ExternalCombiTable1D_destructor(threadData,(data->simulationInfo->extObjs[1]));
    omc_Modelica_Blocks_Types_ExternalCombiTable1D_destructor(threadData,(data->simulationInfo->extObjs[2]));
    omc_Buildings_ThermalZones_Detailed_BaseClasses_CFDThread_destructor(threadData,(data->simulationInfo->extObjs[0]));
    free(data->simulationInfo->extObjs);
    data->simulationInfo->extObjs = 0;
  }
}

It seems the issue arises during the execution of one of the destructors. This needs further investigation by someone familiar with the runtime system to determine:

lochel commented 3 days ago

The issue description mentioned a log message that contained an incorrect function name. This has been corrected in OpenModelica/OpenModelica#13312.

casella commented 3 days ago

@arun3688 can you please look into that when you have time?

arun3688 commented 3 days ago

@casella sure i will look into this