-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify ahm and pred ert subprocess call
- Loading branch information
1 parent
e8cd02c
commit bc7e623
Showing
4 changed files
with
48 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from ._create_synthetic_refcase import create_synthetic_refcase | ||
from ._create_ert_setup import create_ert_setup | ||
from ._run_subprocess import run_ert_subprocess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import glob | ||
import pathlib | ||
import subprocess | ||
|
||
|
||
def run_ert_subprocess(command: str, cwd: pathlib.Path, runpath: str) -> None: | ||
""" | ||
Helper function to run a ERT setup. | ||
Args: | ||
command: Command to run. | ||
cwd: The folder to run the command from. | ||
runpath: Runpath variable given to ERT. | ||
Returns: | ||
Nothing | ||
""" | ||
|
||
# Should revert here to use the much simpler subprocess.run when | ||
# https://github.com/equinor/libres/issues/984 is closed. See | ||
# https://github.com/equinor/flownet/pull/119 on changes to revert. | ||
with subprocess.Popen( | ||
command, | ||
cwd=cwd, | ||
shell=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, | ||
) as process: | ||
for line in process.stdout: # type: ignore | ||
print(line, end="") | ||
if ( | ||
"active realisations left, which is less than " | ||
"the minimum specified - stopping assimilation." in line | ||
or "All realizations failed!" in line | ||
): | ||
process.terminate() | ||
error_files = glob.glob(str(cwd / runpath.replace("%d", "*") / "ERROR")) | ||
raise RuntimeError(pathlib.Path(error_files[0]).read_text()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters