Skip to content

Commit

Permalink
Add support for OPTIMICA r28242, update to MSL 4, remove JModelica su…
Browse files Browse the repository at this point in the history
…pport (#480)

* Changed API for OPTIMICA to the one of version oct-r28242

For #28242

* Changed API for OPTIMICA to the one of version oct-r28242

For #28242

* Updated OCT version to 2022-05-09-master-4b0cd2bf71

* Logged translation output to file

This avoids time out due to the OutputGrabber

* Reverted script to master so that MSL is exported

This is needed for JModelica, but not OPTIMICA

* Removed non-used files

This removes buildingspy/development/jmodelica_run.template buildingspy/development/jmodelica_run_all.template

* Updated API to new version of OPTIMICA

The use of inspection allows backward compatibility with older versions of OPTIMICA and with JModelica

* Corrected syntax

* Updated to MSL 4

* Updated html image

* Remved JModelica support

* Updated change log
  • Loading branch information
mwetter authored May 11, 2022
1 parent e6c9068 commit bda4828
Show file tree
Hide file tree
Showing 28 changed files with 108 additions and 427 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cache: pip
env:
global:
- OMC_VERSION=ubuntu-2004-omc:1.19.0_dev-539-gb76366f-1
- OPTIMICA_VERSION=travis-ubuntu-1804-optimica:r26446
- OPTIMICA_VERSION=travis-ubuntu-1804-optimica:2022-05-09-master-4b0cd2bf71
- DYMOLA_VERSION=travis_ubuntu-2004_dymola:2022x-x86_64
- MPLBACKEND=agg

Expand Down Expand Up @@ -73,7 +73,6 @@ script:
- make unittest_development_error_dictionary
- make unittest_development_merger
- make unittest_development_refactor
- make unittest_development_regressiontest_jmodelica
- make unittest_development_regressiontest_openmodelica
- make unittest_development_regressiontest_optimica
- make unittest_development_regressiontest
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ unittest_development_merger:
unittest_development_refactor:
python3 buildingspy/tests/test_development_refactor.py

unittest_development_regressiontest_jmodelica:
python3 buildingspy/tests/test_development_regressiontest_jmodelica.py

unittest_development_regressiontest_openmodelica:
python3 buildingspy/tests/test_development_regressiontest_openmodelica.py

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ BuildingsPy

BuildingsPy is a Python package that can be used to

* run Modelica simulation using Dymola or JModelica
* process ``*.mat`` output files that were generated by Dymola, JModelica or OpenModelica.
* run Modelica simulation using Dymola or OPTIMICA
* process ``*.mat`` output files that were generated by Dymola, OPTIMICA or OpenModelica.
* run unit tests as part of the library development.

The package provides functions to extract data series from
Expand Down
3 changes: 3 additions & 0 deletions buildingspy/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
BuildingsPy Changelog
---------------------
- Removed JModelica support, and added support for new OPTIMICA compile_fmu API.
- For simulation and unit tests, updated the API for OPTIMICA to the one used in oct-2022-05-09-master-4b0cd2bf71
(https://github.com/lbl-srg/BuildingsPy/issues/479)
- For simulation, corrected a bug that led to an error message when a model from the Modelica Standard Library is simulated
(https://github.com/lbl-srg/BuildingsPy/issues/472)
- For unit tests, enabled option to run tests with OpenModelica.
Expand Down
4 changes: 2 additions & 2 deletions buildingspy/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ BuildingsPy

BuildingsPy is a Python package that can be used to

* run Modelica simulation using Dymola or JModelica
* process ``*.mat`` output files that were generated by Dymola, JModelica or OpenModelica.
* run Modelica simulation using Dymola or OPTIMICA
* process ``*.mat`` output files that were generated by Dymola, OPTIMICA or OpenModelica.
* run unit tests as part of the library development.

The package provides functions to extract data series from
Expand Down
20 changes: 0 additions & 20 deletions buildingspy/development/error_dictionary_jmodelica.py

This file was deleted.

161 changes: 0 additions & 161 deletions buildingspy/development/jmodelica_run.template

This file was deleted.

11 changes: 0 additions & 11 deletions buildingspy/development/jmodelica_run_all.template

This file was deleted.

2 changes: 0 additions & 2 deletions buildingspy/development/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def isValidLibrary(lib_home):
"Scripts", "Conversion", "ConvertIBPSA_from_*.mos"),
os.path.join(ibpsa_dir, "Resources",
"Scripts", "travis", "Makefile"),
os.path.join(ibpsa_dir, "Resources",
"Scripts", "github-actions", "jmodelica", "jm_ipython.sh"),
os.path.join(ibpsa_dir, "Resources",
"Scripts", "BuildingsPy", "conf.json"),
os.path.join(ibpsa_dir, "Resources",
Expand Down
62 changes: 48 additions & 14 deletions buildingspy/development/optimica_run.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Import the class that grabs stdout
import OutputGrabber as og

def process_with_timeout(target, timeout):
import multiprocessing
import time
Expand Down Expand Up @@ -35,31 +32,65 @@ def process_with_timeout(target, timeout):
def _translate(proc_num, return_dict):
import os
from pymodelica import compile_fmu
from inspect import signature

generate_html_diagnostics={{ generate_html_diagnostics }}

try:
# Grab the stdoutput
out = og.OutputGrabber()
out.start()
fmu_name = compile_fmu("{{ model }}{{ model_modifier }}",
version="2.0",
compiler_log_level='warning',
compiler_options = {"generate_html_diagnostics" : generate_html_diagnostics,
"nle_solver_tol_factor": 1e-2})
out.stop()
# OCT r28242 ignores MODELICAPATH and instead needs to have it set through a function argument.
compilation_log = "{{ model }}".replace('.', '_') + "_compile.log"
version="2.0"
compiler_log_level=f"warning:{compilation_log}"
compiler_options = {"generate_html_diagnostics" : generate_html_diagnostics,
"nle_solver_tol_factor": 1e-2} # 1e-2 is the default

sig = signature(compile_fmu)
if "modelicapath" in str(sig):
# This is the new API that uses modelicapath as a function argument.

removed_modelica_path = False
if 'MODELICAPATH' in os.environ:
modelicapath=os.environ['MODELICAPATH']
del os.environ['MODELICAPATH']
removed_modelica_path = True
else:
modelicapath=os.path.abspath('.')

fmu_name = compile_fmu("{{ model }}{{ model_modifier }}",
modelicapath=modelicapath,
version=version,
compiler_log_level=compiler_log_level,
compiler_options=compiler_options)
else:
fmu_name = compile_fmu("{{ model }}{{ model_modifier }}",
version=version,
compiler_log_level=compiler_log_level,
compiler_options=compiler_options)

if removed_modelica_path:
os.environ['MODELICAPATH'] = modelicapath

# Copy style sheets.
# This is a hack to get the css and js files to render the html diagnostics.
htm_dir = os.path.splitext(os.path.basename(fmu_name))[0] + "_html_diagnostics"
if generate_html_diagnostics and os.path.exists(htm_dir):
for fil in ["scripts.js", "style.css", "zepto.min.js"]:
for fil in ["scripts.js", "style.css", "html-diagnostics.css", "zepto.min.js"]:
src = os.path.join(".jmodelica_html", fil)
if os.path.exists(src):
des = os.path.join(htm_dir, fil)
shutil.copyfile(src, des)

# Read log file
out = None
if os.path.isfile(compilation_log):
with open(compilation_log, 'r') as f:
out = f.readlines()
else:
out = f"Error: Log file {compilation_log} does not exist."


# The standard output is returned as a list, with each line being an element
return_dict[proc_num] = {'success': True, 'fmu_name': str(fmu_name), 'stdout': out.capturedtext.split('\n')}
return_dict[proc_num] = {'success': True, 'fmu_name': str(fmu_name), 'stdout': out}

except Exception as e:
return_dict[proc_num] = {'success': False,
Expand All @@ -69,6 +100,9 @@ def _translate(proc_num, return_dict):
def _simulate(proc_num, return_dict):
from pyfmi import load_fmu

# Import the class that grabs stdout
import OutputGrabber as og

if not {{ simulate }}:
return_dict[proc_num] = {'success': False,
'message': 'No simulation requested.'}
Expand Down
Loading

0 comments on commit bda4828

Please sign in to comment.