Skip to content

Commit

Permalink
Rename flepimop batch to submit
Browse files Browse the repository at this point in the history
Also corrected bugs in unit tests of `JobTimeLimit` with new
`BatchSystem` enum.
  • Loading branch information
TimothyWillard committed Nov 8, 2024
1 parent 97f4a0e commit 43d3be9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions flepimop/gempyor_pkg/src/gempyor/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def _job_name(name: str | None, timestamp: datetime | None) -> str:


@cli.command(
name="batch",
name="submit",
params=[config_files_argument]
+ list(config_file_options.values())
+ [
Expand Down Expand Up @@ -739,7 +739,7 @@ def _job_name(name: str | None, timestamp: datetime | None) -> str:
+ list(verbosity_options.values()),
)
@click.pass_context
def _click_batch(ctx: click.Context = mock_context, **kwargs) -> None:
def _click_submit(ctx: click.Context = mock_context, **kwargs) -> None:
"""Submit batch jobs"""
# Generic setup
now = datetime.now(timezone.utc)
Expand All @@ -754,7 +754,7 @@ def _click_batch(ctx: click.Context = mock_context, **kwargs) -> None:
or cfg["inference"]["method"].as_str() != "emcee"
):
raise NotImplementedError(
"The `flepimop batch` CLI only supports EMCEE inference jobs."
"The `flepimop submit` CLI only supports EMCEE inference jobs."
)
inference_method = cfg["inference"]["method"].as_str()
inference_method = (
Expand All @@ -776,7 +776,7 @@ def _click_batch(ctx: click.Context = mock_context, **kwargs) -> None:
if batch_system != BatchSystem.SLURM:
# Temporary limitation
raise NotImplementedError(
"The `flepimop batch` CLI only supports batch submission to slurm."
"The `flepimop submit` CLI only supports batch submission to slurm."
)
logger.info("Constructing a job to submit to %s", batch_system)
if batch_system != BatchSystem.SLURM and kwargs["email"] is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
import yaml

from gempyor.batch import _click_batch
from gempyor.batch import _click_submit


@pytest.fixture
Expand Down Expand Up @@ -34,13 +34,13 @@ def test_only_inference_emcee_supported_not_implemented_error(
yaml.dump(config, f)

runner = CliRunner()
result = runner.invoke(_click_batch, [str(config_file.absolute())])
result = runner.invoke(_click_submit, [str(config_file.absolute())])

assert result.exit_code == 1
assert isinstance(result.exception, NotImplementedError)
assert (
str(result.exception)
== "The `flepimop batch` CLI only supports EMCEE inference jobs."
== "The `flepimop submit` CLI only supports EMCEE inference jobs."
)


Expand All @@ -55,13 +55,13 @@ def test_only_slurm_batch_system_supported_not_implemented_error(
yaml.dump({"inference": {"method": "emcee"}}, f)

runner = CliRunner()
result = runner.invoke(_click_batch, args + [str(config_file.absolute())])
result = runner.invoke(_click_submit, args + [str(config_file.absolute())])

assert result.exit_code == 1
assert isinstance(result.exception, NotImplementedError)
assert (
str(result.exception)
== "The `flepimop batch` CLI only supports batch submission to slurm."
== "The `flepimop submit` CLI only supports batch submission to slurm."
)


Expand All @@ -72,7 +72,7 @@ def test_cluster_required_for_slurm_value_error(tmp_path: Path) -> None:

runner = CliRunner()
result = runner.invoke(
_click_batch,
_click_submit,
[
"--slurm",
"--simulations",
Expand Down
20 changes: 10 additions & 10 deletions flepimop/gempyor_pkg/tests/batch/test_job_time_limit_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from gempyor.batch import JobSize, JobTimeLimit
from gempyor.batch import BatchSystem, JobSize, JobTimeLimit


NONPOSITIVE_TIMEDELTAS = (timedelta(), timedelta(hours=-1.0), timedelta(days=-3.0))
Expand All @@ -31,14 +31,16 @@ def test_time_limit_non_positive_value_error(time_limit: timedelta) -> None:
timedelta(minutes=12345),
),
)
@pytest.mark.parametrize("batch_system", (None, "aws", "local", "slurm"))
@pytest.mark.parametrize(
"batch_system", (None, BatchSystem.AWS, BatchSystem.LOCAL, BatchSystem.SLURM)
)
def test_format_output_validation(
time_limit: timedelta, batch_system: Literal["aws", "local", "slurm"] | None
time_limit: timedelta, batch_system: BatchSystem | None
) -> None:
job_time_limit = JobTimeLimit(time_limit=time_limit)
formatted_time_limit = job_time_limit.format(batch_system=batch_system)
assert isinstance(formatted_time_limit, str)
if batch_system == "slurm":
if batch_system == BatchSystem.SLURM:
assert re.match(r"^[0-9]+\:[0-9]{2}\:[0-9]{2}$", formatted_time_limit)
else:
assert formatted_time_limit.isdigit()
Expand All @@ -50,15 +52,13 @@ def test_format_output_validation(
(timedelta(hours=1), None, "60"),
(timedelta(seconds=20), None, "1"),
(timedelta(days=2, hours=3, minutes=45), None, "3105"),
(timedelta(hours=1), "slurm", "1:00:00"),
(timedelta(seconds=20), "slurm", "0:00:20"),
(timedelta(days=1, hours=2, minutes=34, seconds=5), "slurm", "26:34:05"),
(timedelta(hours=1), BatchSystem.SLURM, "1:00:00"),
(timedelta(seconds=20), BatchSystem.SLURM, "0:00:20"),
(timedelta(days=1, hours=2, minutes=34, seconds=5), BatchSystem.SLURM, "26:34:05"),
),
)
def test_format_exact_results(
time_limit: timedelta,
batch_system: Literal["aws", "local", "slurm"] | None,
expected: str,
time_limit: timedelta, batch_system: BatchSystem | None, expected: str
) -> None:
job_time_limit = JobTimeLimit(time_limit=time_limit)
assert job_time_limit.format(batch_system=batch_system) == expected
Expand Down

0 comments on commit 43d3be9

Please sign in to comment.