Skip to content

Commit

Permalink
Move run_simulator function from test_check_swatinit_simulators
Browse files Browse the repository at this point in the history
  • Loading branch information
alifbe committed Aug 26, 2024
1 parent 2f307f1 commit a2c579a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
33 changes: 3 additions & 30 deletions tests/test_check_swatinit_simulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"""

import os
import subprocess
import time
from pathlib import Path

import numpy as np
Expand All @@ -31,6 +29,8 @@
)
from subscript.check_swatinit.pillarmodel import PillarModel

from .utils import run_simulator

IN_SUBSCRIPT_GITHUB_ACTIONS = os.getenv("GITHUB_REPOSITORY") == "equinor/subscript"

pd.set_option("display.max_columns", 100)
Expand Down Expand Up @@ -58,35 +58,8 @@ def run_reservoir_simulator(simulator, resmodel, perform_qc=True):
pd.DataFrame if perform_qc is True, else None
"""
Path("FOO.DATA").write_text(str(resmodel), encoding="utf8")
simulator_option = []
if "runeclipse" in simulator:
simulator_option = ["-i"]
if "flow" in simulator:
simulator_option = ["--parsing-strictness=low"]

result = subprocess.run( # pylint: disable=subprocess-run-check
[simulator] + simulator_option + ["FOO.DATA"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

if (
result.returncode != 0
and "runeclipse" in simulator
and "LICENSE FAILURE" in result.stdout.decode() + result.stderr.decode()
):
print("Eclipse failed due to license server issues. Retrying in 30 seconds.")
time.sleep(30)
result = subprocess.run( # pylint: disable=subprocess-run-check
[simulator] + simulator_option + ["FOO.DATA"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

if result.returncode != 0:
print(result.stdout.decode())
print(result.stderr.decode())
raise AssertionError(f"reservoir simulator failed in {os.getcwd()}")
run_simulator(simulator, "FOO.DATA")

if perform_qc:
return make_qc_gridframe(res2df.ResdataFiles("FOO.DATA"))
Expand Down
50 changes: 50 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import subprocess
import time
from os import getcwd


def run_simulator(simulator, data_file_path):
"""Run the given simulator (Eclipse100 or OPM-flow)
on a DATA file
Will write to cwd. Caller is responsible for starting
in a suitable directory.
If the simulator fails, the stdout and stderr will be printed.
Args:
simulator (string): Path to a working reservoir simulator
executable
data_file_path (str): Location of DATA file
Returns:
None
"""
simulator_option = []
if "runeclipse" in simulator:
simulator_option = ["-i"]
if "flow" in simulator:
simulator_option = ["--parsing-strictness=low"]

result = subprocess.run( # pylint: disable=subprocess-run-check
[simulator] + simulator_option + [data_file_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

if (
result.returncode != 0
and "runeclipse" in simulator
and "LICENSE FAILURE" in result.stdout.decode() + result.stderr.decode()
):
print("Eclipse failed due to license server issues. Retrying in 30 seconds.")
time.sleep(30)
result = subprocess.run( # pylint: disable=subprocess-run-check
[simulator] + simulator_option + [data_file_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

if result.returncode != 0:
print(result.stdout.decode())
print(result.stderr.decode())
raise AssertionError(f"reservoir simulator failed in {getcwd()}")

0 comments on commit a2c579a

Please sign in to comment.