Skip to content

Commit

Permalink
Re-enable a number of tests (#585)
Browse files Browse the repository at this point in the history
* only test for 1 day so tests work and can be unskipped

* move use_m_flow_in to correct place in ambient instance template

* add container info logging and update log statements

* use OMv1.21 in container

* teeny change to log usage in om.py

* skip chp test until we figure out what OM wants in initial values

* teaser heating test step size set to 1 hour

* add pytest marker for docker tests [skip ci]

* refactor os.path to pathlib.Path in test_borefield.py

* add docstring and fix typo in ambient_water_stub.py [skip ci]

* log additional reason for simulation failure to ease debugging

* test simple cooling plant for only 1 day in the summer

* update dependencies

* `poetry update` to pick up the upgraded dependencies

* more permissive versioning of syrupy, to get additional feature releases

* update dependencies again for newer syrupy

* mark one more test as docker

* update GMT_lib snapshot because new version of syrupy

* change step_size in one test so it passes locally for me

* test that users can provide number_of_intervals instead of step_size

* add a forgotten test file to gitignore

* clean up raw/endraw tags in templates

* use local container with OMv1.22

* fix typo made when cleaning up raw/endraw tags

* set m-b dependency properly for this branch

* Revert "clean up raw/endraw tags in templates"

This reverts commit e325478.

* update dependencies

* update OM version in dockerfile and add timestamp logging

* clean up spawn scripts when running with OM

* skip teaser heating because of simulation weirdness

* one more cleanup of dymola/spawn-specific stuff no longer necessary

* include OM version in stdout.log file when running OM

* use new docker image with OMv1.22.0

* add OM version logging to the rest of the relevant functions

* use updated BuildFMU method from OM

* slightly cleaner syntax for Path.chmod in modelica_runner.py

* add cmake to base image for OpenModelica FMU compilation

* change interval & step size so local tests are happy

* remove redundant boolean in 5G instance template

* update dependencies

---------

Co-authored-by: Nicholas Long <[email protected]>
  • Loading branch information
vtnate and nllong authored Dec 14, 2023
1 parent e32ce97 commit 05e2f13
Show file tree
Hide file tree
Showing 31 changed files with 793 additions and 746 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,4 @@ tests/modelica/data/packages/*/*.c
tests/modelica/data/packages/*/dymosim
tests/management/data/sdk_project_scraps/run/baseline_scenario/system_parameter.json
geojson_modelica_translator/modelica/buildingslibrary/
not/a/real/**
# TODO: this file shoud not be writtent out, but it is... fix this eventually
geojson_modelica_translator/modelica/ets_cooling_indirect_templated.mo
not/
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
old_hidden_avoid_double_computation=Hidden.AvoidDoubleComputation;
Hidden.AvoidDoubleComputation=true;
simulateModel("{{full_model_name}}",
method="cvode",
tolerance=1e-6,
numberOfIntervals=500,
stopTime=604800.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
simulateModel("{{full_model_name}}",
method="cvode",
tolerance=1e-6,
numberOfIntervals=500,
stopTime=604800.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ def to_modelica(self, scaffold):
"""
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model to generate, its fully implemented in the coupling currently
# this stub has no model to generate, it's fully implemented in the coupling

def get_modelica_type(self, scaffold):
"""
:param scaffold: Scaffold object, Scaffold of the entire directory of the project.
"""
# this stub has no model, so there's no type
return 'UNIMPLEMENTED'
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Simulate
simulateModel("GMT_Lib.DHC.Components.Plants.Cooling.CoolingPlant",
stopTime=86400,
method="cvode",
tolerance=1e-06,
resultFile="CoolingPlant");
// Plot commands
Expand Down
5 changes: 2 additions & 3 deletions geojson_modelica_translator/modelica/lib/runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Use the OpenModelica Docker image
# We only need this file for the copy command. The image can be/is loaded in the shell script instead of here.
FROM openmodelica/openmodelica:v1.20.0-gui
FROM openmodelica/openmodelica:v1.22.0-gui

# libgfortran4 is needed to load FMU for FMUZoneAdapterZones1.mo
RUN apt update && apt --no-install-recommends install -y \
vim \
gfortran \
libpython3-dev \
curl \
cmake \
&& rm -rf /var/lib/apt/lists/*

# Install MSL 4.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ loadModel(Buildings);
loadFile("{{ file_to_load }}");getErrorString();
{% endif %}

translateModelFMU({{ model_name }});getErrorString();
buildModelFMU({{ model_name }});getErrorString();
23 changes: 16 additions & 7 deletions geojson_modelica_translator/modelica/lib/runner/om.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import logging
import os
import platform
import shutil
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -57,6 +58,7 @@ def compile_fmu(model_name) -> str:
# Call OMC to compile the model, using MSL & MBL libraries
cmd = "omc compile_fmu.mos"
logger.info(f"Calling OpenModelica compile with '{cmd}'")
os.system('omc --version')
# Uncomment this section and rebuild the container in order to pause the container
# to inpsect the container and test commands.
# import time
Expand All @@ -76,6 +78,7 @@ def run_as_fmu(fmu_name, start: Optional[float], stop: Optional[float], step: Op
# time.sleep(10000)
cmd = f"OMSimulator --startTime={start} --stopTime={stop} --stepSize={step} {fmu_name}"
logger.info(f"Calling OpenModelica simulator with '{cmd}'")
os.system('omc --version')
os.system(cmd)
return f'{fmu_name} has been simulated'

Expand All @@ -91,11 +94,18 @@ def run_with_omc() -> bool:
# Call OMC to compile the model, using MSL & MBL libraries
cmd = "omc simulate.mos"
logger.info(f"Calling OpenModelica simulate with '{cmd}'")
# Log the OM version. Wish I could get it into a log statement, but at least this prints to stdout.log.
os.system('omc --version')
if platform.system() == "Linux":
logger.info(f"This container has Linux {platform.freedesktop_os_release()['PRETTY_NAME']} on {platform.machine()} architecture")
else:
logger.info(f"This container is running: {platform.system()} on {platform.machine()} architecture")
# Uncomment this section and rebuild the container in order to pause the container
# to inpsect the container and test commands.
# import time
# time.sleep(10000)
os.system(cmd)
logger.debug("Finished simulating (timestamp to tell how long simulation took).")

# remove the 'tmp' folder that was created, because it will
# have different permissions than the user running the container
Expand Down Expand Up @@ -129,7 +139,7 @@ def run_with_omc() -> bool:
if args.action == 'help':
print(parser.print_help()) # type: ignore

logger.info('Configuring MBL path')
logger.info('Configuring MBL path for use inside the container')
configure_mbl_path()

fmu_name = None
Expand All @@ -145,14 +155,13 @@ def run_with_omc() -> bool:
compile_fmu(model)

if args.action == 'compile_and_run':
model = args.model
# model = args.model

if Path(model).is_file():
model = str((args.run_path / model)).replace(os.path.sep, '.')[:-3]
if model[0] == '.':
model = model[1:]
# if Path(model).is_file():
# model = str((args.run_path / model)).replace(os.path.sep, '.')[:-3]
# if model[0] == '.':
# model = model[1:]

logger.info(f'Running model {model} with OMC')
fmu_name = run_with_omc()

if args.action == 'run':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See also https://github.com/urbanopt/geojson-modelica-translator/blob/develop/LICENSE.md

DOCKER_USERNAME=nrel
IMG_NAME=gmt-om-runner
IMG_NAME=gmt-om-runner:v1.22.0

function create_mount_command()
# Split path somehow. Replace double-slashes with single-slashes, to ensure compatibility with
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
simulateModel("{{project_name}}.Loads.{{model_name}}",stopTime=604800, method="Cvode", tolerance=1e-06, resultFile="{{model_name}}");
createPlot(id=1, position={55, 50, 1783, 995}, y={% raw %}{{% endraw %}{% for zone in data['thermal_zones']%}"{{zone['modelica_object_name']}}.TAir", {% endfor %} {% raw %} "weaDat.weaBus.TDryBul", "datRea.y[1]", "datRea.y[2]", "datRea.y[3]", "datRea.y[4]", "datRea.y[5]", "datRea.y[6]", "datRea.y[7]"}, range={0.0, 620000.0, -30.0, 25.0}, grid=true, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}, {162,29,33}, {244,125,35}, {102,44,145}, {28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}, {162,29,33}}, patterns={LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash});{% endraw %}
simulateModel(
"{{project_name}}.Loads.{{model_name}}",
stopTime=604800,
tolerance=1e-06,
resultFile="{{model_name}}"
);
createPlot(id=1, position={55, 50, 1783, 995}, y={ {% for zone in data['thermal_zones']%}"{{zone['modelica_object_name']}}.TAir", {% endfor %} {% raw %} "weaDat.weaBus.TDryBul", "datRea.y[1]", "datRea.y[2]", "datRea.y[3]", "datRea.y[4]", "datRea.y[5]", "datRea.y[6]", "datRea.y[7]"}, range={0.0, 620000.0, -30.0, 25.0}, grid=true, colors={{28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}, {162,29,33}, {244,125,35}, {102,44,145}, {28,108,200}, {238,46,47}, {0,140,72}, {217,67,180}, {0,0,0}, {162,29,33}}, patterns={LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Solid, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash, LinePattern.Dash});{% endraw %}
5 changes: 4 additions & 1 deletion geojson_modelica_translator/modelica/modelica_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _copy_over_docker_resources(self, run_path: Path, filename: Union[str, Path,
# new om_docker.sh file name
new_om_docker = run_path / self.om_docker_path.name
shutil.copyfile(self.om_docker_path, new_om_docker)
Path.chmod(new_om_docker, 0o775)
new_om_docker.chmod(0o775)

def _subprocess_call_to_docker(self, run_path: Union[str, Path], action: str) -> int:
"""Call out to a subprocess to run the command in docker
Expand Down Expand Up @@ -253,6 +253,9 @@ def run_in_docker(self, action: str, model_name: str, file_to_load: Union[str, P
if 'Failed to build model' in stdout_log:
logger.error('Model failed to build')
exitcode = 1
elif 'division by zero at time' and 'Simulation execution failed for model:' in stdout_log:
logger.error('Model failed to run due to division by zero')
exitcode = 1
elif 'The simulation finished successfully' in stdout_log:
logger.info('Model ran successfully')
exitcode = 0
Expand Down
Loading

0 comments on commit 05e2f13

Please sign in to comment.