Skip to content

Commit

Permalink
Make CFD benchmark work in container
Browse files Browse the repository at this point in the history
  • Loading branch information
8uurg committed Jul 3, 2020
1 parent 854a0f3 commit d6151d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CFD.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get install -y software-properties-common &&\
apt-get update &&\
apt-get install -y build-essential python3-pip python3.7 python3.7-dev swig &&\
python3.7 -m pip install --upgrade pip &&\
python3.7 -m pip install cython setuptools wheel
python3.7 -m pip install --upgrade cython setuptools wheel

# Install benchmark dependencies.
COPY ./requirements.txt ./requirements_eob.txt
Expand All @@ -15,4 +15,6 @@ RUN python3.7 -m pip install -r requirements_eob.txt

COPY expensiveoptimbenchmark ./expensiveoptimbenchmark

RUN ln -s ./dockerCall.sh ./evaluate.sh
RUN ln -s ./dockerCall.sh ./evaluate.sh

ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
10 changes: 7 additions & 3 deletions expensiveoptimbenchmark/problems/DockerCFDBenchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import numpy as np
import os

class DockerCFDBenchmarkProblem:

Expand All @@ -11,14 +12,17 @@ def __init__(self, name, d, lbs, ubs, vartype, direction, errval):
self.vt = np.asarray(vartype)
self.direction = 1 if direction == "min" else -1
self.errval = errval
if os.path.exists("./evaluate.sh"):
self.evalCommand = ["./evaluate.sh", self.name]
else:
self.evalCommand = ["docker", "run", "--rm", "frehbach/cfd-test-problem-suite", "./dockerCall.sh", self.name]

def evaluate(self, xs):
evalCommand = f"docker run --rm frehbach/cfd-test-problem-suite ./dockerCall.sh {self.name}"
parsedCandidate = ",".join(["%.8f" % x if xvt == 'cont' else "%i" % x for (x, xvt) in zip(xs, self.vt)])
cmd = f"{evalCommand} '{parsedCandidate}'"
cmd = f"{self.evalCommand + [parsedCandidate]}"
# print(f"Running '{cmd}'")
# res = subprocess.check_output(cmd, shell=True)
res = subprocess.check_output(["docker", "run", "--rm", "frehbach/cfd-test-problem-suite", "./dockerCall.sh", self.name, parsedCandidate])
res = subprocess.check_output(self.evalCommand + [parsedCandidate])
reslast = res.strip().split(b"\n")[-1]
# print(f"Result: {res}")
try:
Expand Down

0 comments on commit d6151d2

Please sign in to comment.