diff --git a/CFD.Dockerfile b/CFD.Dockerfile index e4b6dce..24bd363 100644 --- a/CFD.Dockerfile +++ b/CFD.Dockerfile @@ -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 @@ -15,4 +15,6 @@ RUN python3.7 -m pip install -r requirements_eob.txt COPY expensiveoptimbenchmark ./expensiveoptimbenchmark -RUN ln -s ./dockerCall.sh ./evaluate.sh \ No newline at end of file +RUN ln -s ./dockerCall.sh ./evaluate.sh + +ENTRYPOINT [ "/bin/bash", "-l", "-c" ] \ No newline at end of file diff --git a/expensiveoptimbenchmark/problems/DockerCFDBenchmark.py b/expensiveoptimbenchmark/problems/DockerCFDBenchmark.py index 0c3e5c9..f6137cc 100644 --- a/expensiveoptimbenchmark/problems/DockerCFDBenchmark.py +++ b/expensiveoptimbenchmark/problems/DockerCFDBenchmark.py @@ -1,5 +1,6 @@ import subprocess import numpy as np +import os class DockerCFDBenchmarkProblem: @@ -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: