Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modelica_runner): Replace shell script with call directly to docker #606

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions geojson_modelica_translator/modelica/lib/runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openmodelica/openmodelica:v1.22.0-gui
FROM openmodelica/openmodelica:v1.22.1-gui

# libgfortran4 is needed to load FMU for FMUZoneAdapterZones1.mo
RUN apt update && apt --no-install-recommends install -y \
Expand All @@ -15,5 +15,8 @@ RUN echo \
omc /tmp/installMSL.mos && \
rm /tmp/installMSL.mos

# Put the om.py CLI into the container
COPY ./om.py /mnt/lib/om.py
# Install MBL 9.1.0
RUN echo \
"updatePackageIndex(); getErrorString(); installPackage(Buildings, \"9.1.0\", exactMatch=false); getErrorString();" >> /tmp/installMBL.mos && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

omc /tmp/installMBL.mos && \
rm /tmp/installMBL.mos
176 changes: 0 additions & 176 deletions geojson_modelica_translator/modelica/lib/runner/om.py

This file was deleted.

119 changes: 0 additions & 119 deletions geojson_modelica_translator/modelica/lib/runner/om_docker.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bye Felicia!

This file was deleted.

21 changes: 10 additions & 11 deletions geojson_modelica_translator/modelica/modelica_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ def _copy_over_docker_resources(self, run_path: Path, filename: Union[str, Path,
with open(run_path / 'compile_fmu.mos', 'w') as f:
f.write(template.render(**model_data))

# 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)
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 All @@ -166,14 +161,18 @@ def _subprocess_call_to_docker(self, run_path: Union[str, Path], action: str) ->
curdir = Path.cwd()
os.chdir(run_path)
stdout_log = open('stdout.log', 'w')
model_name = os.path.split(str(run_path))[-1]
image_name = 'nrel/gmt-om-runner'
mo_script = 'compile_fmu' if action == 'compile' else 'simulate'
try:
# get the relative difference between the file to run and the path which everything is running in.
# create the command to call the open modelica compiler inside the docker image
exec_call = 'docker run -v {run_path}:/mnt/shared/{model_name} {image_name} ' \
'/bin/bash -c "cd mnt/shared/{model_name} && omc {mo_script}.mos"'.format(
run_path=run_path, model_name=model_name,
image_name=image_name, mo_script=mo_script
)
# execute the command that calls docker
# make sure to simulate at a directory above the project directory!

# Use slashes for the location of the model to run. We can make these periods `.replace(os.sep, '.')`
# but must strip off the .mo extension on the model to run
# run_model = Path(file_to_run).relative_to(run_path)
exec_call = ['./om_docker.sh', action]
logger.debug(f"Calling {exec_call}")
p = subprocess.Popen(
exec_call, # type: ignore
Expand Down