Skip to content

Commit

Permalink
Create joint submit script
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 27, 2024
1 parent f8f0d5c commit 1d62a28
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/ert/scheduler/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
"""Bash and other shells add an offset of 128 to the signal value when a process exited due to a signal"""


def create_submit_script(runpath: Path, executable: str, args: tuple[str, ...]) -> str:
return (
"#!/usr/bin/env bash\n"
f"cd {shlex.quote(str(runpath))}\n"
f"exec -a {shlex.quote(executable)} {executable} {shlex.join(args)}\n"
)


class FailedSubmit(RuntimeError):
pass

Expand Down
9 changes: 2 additions & 7 deletions src/ert/scheduler/lsf_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
get_args,
)

from .driver import SIGNAL_OFFSET, Driver, FailedSubmit
from .driver import SIGNAL_OFFSET, Driver, FailedSubmit, create_submit_script
from .event import Event, FinishedEvent, StartedEvent

_POLL_PERIOD = 2.0 # seconds
Expand Down Expand Up @@ -309,12 +309,7 @@ async def submit(

arg_queue_name = ["-q", self._queue_name] if self._queue_name else []
arg_project_code = ["-P", self._project_code] if self._project_code else []

script = (
"#!/usr/bin/env bash\n"
f"cd {shlex.quote(str(runpath))}\n"
f"exec -a {shlex.quote(executable)} {executable} {shlex.join(args)}\n"
)
script = create_submit_script(runpath, executable, args)
script_path: Optional[Path] = None
try:
with NamedTemporaryFile(
Expand Down
8 changes: 2 additions & 6 deletions src/ert/scheduler/openpbs_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
get_type_hints,
)

from .driver import Driver, FailedSubmit
from .driver import Driver, FailedSubmit, create_submit_script
from .event import Event, FinishedEvent, StartedEvent

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -241,11 +241,7 @@ async def submit(
[] if self._keep_qsub_output else ["-o", "/dev/null", "-e", "/dev/null"]
)

script = (
"#!/usr/bin/env bash\n"
f"cd {shlex.quote(str(runpath))}\n"
f"exec -a {shlex.quote(executable)} {executable} {shlex.join(args)}\n"
)
script = create_submit_script(runpath, executable, args)
name_prefix = self._job_prefix or ""
qsub_with_args: List[str] = [
str(self._qsub_cmd),
Expand Down
8 changes: 2 additions & 6 deletions src/ert/scheduler/slurm_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Tuple,
)

from .driver import SIGNAL_OFFSET, Driver, FailedSubmit
from .driver import SIGNAL_OFFSET, Driver, FailedSubmit, create_submit_script
from .event import Event, FinishedEvent, StartedEvent

SLURM_FAILED_EXIT_CODE_FETCH = SIGNAL_OFFSET + 66
Expand Down Expand Up @@ -181,11 +181,7 @@ async def submit(
if runpath is None:
runpath = Path.cwd()

script = (
"#!/usr/bin/env bash\n"
f"cd {shlex.quote(str(runpath))}\n"
f"exec -a {shlex.quote(executable)} {executable} {shlex.join(args)}\n"
)
script = create_submit_script(runpath, executable, args)
script_path: Optional[Path] = None
try:
with NamedTemporaryFile(
Expand Down

0 comments on commit 1d62a28

Please sign in to comment.