Skip to content

Commit

Permalink
Revert "Implement EXCLUDE_HOST for scheduler lsf driver"
Browse files Browse the repository at this point in the history
This reverts commit 5bb33aa.
  • Loading branch information
berland committed Apr 3, 2024
1 parent 9d73d96 commit ade18be
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 86 deletions.
1 change: 0 additions & 1 deletion src/ert/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def create_driver(config: QueueConfig) -> Driver:
bkill_cmd=queue_config.get("BKILL_CMD"),
bjobs_cmd=queue_config.get("BJOBS_CMD"),
bhist_cmd=queue_config.get("BHIST_CMD"),
exclude_hosts=queue_config.get("EXCLUDE_HOST", "").split(","),
queue_name=queue_config.get("LSF_QUEUE"),
resource_requirement=queue_config.get("LSF_RESOURCE"),
)
Expand Down
46 changes: 3 additions & 43 deletions src/ert/scheduler/lsf_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Mapping,
MutableMapping,
Optional,
Sequence,
Tuple,
Union,
get_args,
Expand Down Expand Up @@ -103,35 +102,6 @@ def parse_bjobs(bjobs_output: str) -> Dict[str, Dict[str, Dict[str, str]]]:
return {"jobs": data}


def parse_resource_requirement_string(
exclude_hosts: Sequence[str], resource_requirement: str
) -> str:
resource_requirements = []
if len(exclude_hosts or []) > 0:
select_list = [f"hname!='{host_name}'" for host_name in exclude_hosts]
exclude_hosts_string = " && ".join(select_list)
if resource_requirement:
if "select[" in resource_requirement:
# We split string into (before) "bla[..] bla[..] select[xxx_"
# and (after) "... bla[..] bla[..]". (we replaced one ']' with ' ')
# Then we make final string: before + &&excludes] + after
end_index = resource_requirement.rindex("]")
first_part = resource_requirement[:end_index]
second_part = resource_requirement[end_index:]
resource_requirements.append(
f"{first_part} && {exclude_hosts_string}{second_part}"
)
else:
resource_requirements.append(resource_requirement)
resource_requirements.append(f"select[{exclude_hosts_string}]")
else:
resource_requirements.append(f"select[{exclude_hosts_string}]")

elif resource_requirement:
resource_requirements.append(resource_requirement)
return " ".join(resource_requirements)


def parse_bhist(bhist_output: str) -> Dict[str, Dict[str, int]]:
data: Dict[str, Dict[str, int]] = {}
for line in bhist_output.splitlines():
Expand Down Expand Up @@ -165,7 +135,6 @@ def parse_bhist(bhist_output: str) -> Dict[str, Dict[str, int]]:
class LsfDriver(Driver):
def __init__(
self,
exclude_hosts: Optional[Sequence[str]] = None,
queue_name: Optional[str] = None,
resource_requirement: Optional[str] = None,
bsub_cmd: Optional[str] = None,
Expand All @@ -175,7 +144,6 @@ def __init__(
) -> None:
super().__init__()

self._exclude_hosts = list(exclude_hosts) if exclude_hosts else []
self._queue_name = queue_name
self._resource_requirement = resource_requirement or ""

Expand Down Expand Up @@ -229,7 +197,9 @@ async def submit(
script_path = Path(script_handle.name)
assert script_path is not None
script_path.chmod(script_path.stat().st_mode | stat.S_IEXEC)
arg_resource_requirement = self._get_resource_requirement_arg()
arg_resource_requirement = (
["-R", self._resource_requirement] if self._resource_requirement else []
)

bsub_with_args: List[str] = (
[str(self._bsub_cmd)]
Expand Down Expand Up @@ -259,16 +229,6 @@ async def submit(
self._jobs[job_id] = (iens, QueuedJob(job_state="PEND"))
self._iens2jobid[iens] = job_id

def _get_resource_requirement_arg(self) -> List[str]:
parsed_resource_requirement_string = parse_resource_requirement_string(
self._exclude_hosts, self._resource_requirement
)
return (
["-R", parsed_resource_requirement_string]
if parsed_resource_requirement_string
else []
)

async def kill(self, iens: int) -> None:
if iens not in self._iens2jobid:
logger.error(f"LSF kill failed due to missing jobid for realization {iens}")
Expand Down
38 changes: 0 additions & 38 deletions tests/unit_tests/scheduler/test_lsf_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
_Stat,
parse_bhist,
parse_bjobs,
parse_resource_requirement_string,
)

valid_jobstates: Collection[str] = list(get_args(JobState))
Expand Down Expand Up @@ -520,43 +519,6 @@ async def test_that_bsub_will_retry_and_succeed(
await driver.submit(0, "sleep 10")


@pytest.mark.parametrize(
"resource_requirement, exclude_hosts, expected_string",
[
pytest.param(None, None, "", id="None input"),
pytest.param(
"rusage[mem=512MB:swp=1GB]",
[],
"rusage[mem=512MB:swp=1GB]",
id="resource_requirement_without_select_and_no_excluded_hosts",
),
pytest.param(
None,
["linrgs12-foo", "linrgs13-bar"],
"select[hname!='linrgs12-foo' && hname!='linrgs13-bar']",
id="excluded_hosts",
),
pytest.param(
"rusage[mem=512MB:swp=1GB]",
["linrgs12-foo"],
"rusage[mem=512MB:swp=1GB] select[hname!='linrgs12-foo']",
id="resource_requirement_and_excluded_hosts",
),
pytest.param(
"select[location=='cloud']",
["linrgs12-foo", "linrgs13-bar"],
"select[location=='cloud' && hname!='linrgs12-foo' && hname!='linrgs13-bar']",
id="multiple_selects",
),
],
)
def test_parse_resource_requirement_string(
resource_requirement: str, exclude_hosts: List[str], expected_string: str
):
result_str = parse_resource_requirement_string(exclude_hosts, resource_requirement)
assert result_str == expected_string


@pytest.mark.parametrize(
"bhist_output, expected",
[
Expand Down
4 changes: 0 additions & 4 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,13 @@ def test_scheduler_create_lsf_driver():
bjobs_cmd = "bar_bjobs_cmd"
bhist_cmd = "com_bjobs_cmd"
lsf_resource = "rusage[mem=512MB:swp=1GB]"
exclude_host = "host1,host2"

queue_config_dict = {
"QUEUE_SYSTEM": "LSF",
"QUEUE_OPTION": [
("LSF", "BSUB_CMD", bsub_cmd),
("LSF", "BKILL_CMD", bkill_cmd),
("LSF", "BJOBS_CMD", bjobs_cmd),
("LSF", "BHIST_CMD", bhist_cmd),
("LSF", "EXCLUDE_HOST", exclude_host),
("LSF", "LSF_QUEUE", queue_name),
("LSF", "LSF_RESOURCE", lsf_resource),
],
Expand All @@ -541,7 +538,6 @@ def test_scheduler_create_lsf_driver():
assert str(driver._bkill_cmd) == bkill_cmd
assert str(driver._bjobs_cmd) == bjobs_cmd
assert str(driver._bhist_cmd) == bhist_cmd
assert driver._exclude_hosts == exclude_host.split(",")
assert driver._queue_name == queue_name
assert driver._resource_requirement == lsf_resource

Expand Down

0 comments on commit ade18be

Please sign in to comment.