Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sim context tests by using the correct queue API #6629

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ert/simulator/batch_simulator_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def status(self) -> Status:
Will return the state of the simulations.
"""
return Status(
running=self._job_queue.count_status(RealizationState.RUNNING),
waiting=self._job_queue.count_status(RealizationState.WAITING),
pending=self._job_queue.count_status(RealizationState.PENDING),
complete=self._job_queue.count_status(RealizationState.SUCCESS),
failed=self._job_queue.count_status(RealizationState.FAILED),
running=self.job_queue.count_realization_state(RealizationState.RUNNING),
waiting=self.job_queue.count_realization_state(RealizationState.WAITING),
pending=self.job_queue.count_realization_state(RealizationState.PENDING),
complete=self.job_queue.count_realization_state(RealizationState.SUCCESS),
failed=self.job_queue.count_realization_state(RealizationState.FAILED),
)

def results(self) -> List[Optional[Dict[str, "npt.NDArray[np.float64]"]]]:
Expand Down
10 changes: 5 additions & 5 deletions src/ert/simulator/simulation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
for index, run_arg in enumerate(run_context):
if not run_context.is_active(index):
continue
job_queue.add_job_from_run_arg(
job_queue.add_realization_from_run_arg(
run_arg,
ert.ert_config.queue_config.job_script,
max_runtime,
Expand All @@ -68,12 +68,12 @@
):
queue_evaluators = [
partial(
job_queue.stop_long_running_jobs,

Check failure on line 71 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"JobQueue" has no attribute "stop_long_running_jobs"; maybe "stop_long_running_realizations"?
ert.ert_config.analysis_config.minimum_required_realizations,
)
]

asyncio.run(job_queue.execute(evaluators=queue_evaluators))

Check failure on line 76 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

Argument "evaluators" to "execute" of "JobQueue" has incompatible type "list[partial[Any]] | None"; expected "list[Callable[..., Any]] | None"

run_context.sim_fs.sync()

Expand Down Expand Up @@ -156,7 +156,7 @@
queue_index = self.get_run_args(iens).queue_index
if queue_index is None:
raise ValueError("Queue index not set")
return self.job_queue.realization_state(queue_index) == RealizationState.SUCCESS

Check failure on line 159 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "SUCCESS"

def didRealizationFail(self, iens: int) -> bool:
# For the purposes of this class, a failure should be anything (killed
Expand All @@ -170,7 +170,7 @@
if queue_index is not None:
return not (
self.job_queue.realization_state(queue_index)
in [RealizationState.SUCCESS, RealizationState.WAITING]

Check failure on line 173 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "SUCCESS"

Check failure on line 173 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "WAITING"
)
else:
# job was not submitted
Expand All @@ -182,10 +182,10 @@

def __repr__(self) -> str:
running = "running" if self.isRunning() else "not running"
numRunn = self.job_queue.count_status(RealizationState.RUNNING)
numSucc = self.job_queue.count_status(RealizationState.SUCCESS)
numFail = self.job_queue.count_status(RealizationState.FAILED)
numWait = self.job_queue.count_status(RealizationState.WAITING)
numRunn = self.job_queue.count_realization_state(RealizationState.RUNNING)

Check failure on line 185 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "RUNNING"
numSucc = self.job_queue.count_realization_state(RealizationState.SUCCESS)

Check failure on line 186 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "SUCCESS"
numFail = self.job_queue.count_realization_state(RealizationState.FAILED)

Check failure on line 187 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "FAILED"
numWait = self.job_queue.count_realization_state(RealizationState.WAITING)

Check failure on line 188 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "WAITING"
return (
f"SimulationContext({running}, #running = {numRunn}, "
f"#success = {numSucc}, #failed = {numFail}, #waiting = {numWait})"
Expand Down Expand Up @@ -226,7 +226,7 @@
if queue_index is None:
# job was not submitted
return None
if self.job_queue.realization_state(queue_index) == RealizationState.WAITING:

Check failure on line 229 in src/ert/simulator/simulation_context.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"type[RealizationState]" has no attribute "WAITING"
return None

return ForwardModelStatus.load(run_arg.runpath)
Expand Down
20 changes: 10 additions & 10 deletions tests/unit_tests/simulator/test_batch_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from ert.config import ErtConfig
from ert.job_queue import JobStatus
from ert.realization_state import RealizationState
from ert.simulator import BatchSimulator


Expand Down Expand Up @@ -409,13 +409,13 @@ def test_stop_sim(copy_case, storage):
def assertContextStatusOddFailures(batch_ctx, final_state_only=False):
running_status = set(
(
JobStatus.WAITING,
JobStatus.SUBMITTED,
JobStatus.PENDING,
JobStatus.RUNNING,
JobStatus.UNKNOWN,
JobStatus.EXIT,
JobStatus.DONE,
RealizationState.WAITING,
RealizationState.SUBMITTED,
RealizationState.PENDING,
RealizationState.RUNNING,
RealizationState.UNKNOWN,
RealizationState.EXIT,
RealizationState.DONE,
None, # job is not submitted yet but ok for this test
)
)
Expand All @@ -425,9 +425,9 @@ def assertContextStatusOddFailures(batch_ctx, final_state_only=False):
if not final_state_only and status in running_status:
continue
if idx % 2 == 0:
assert status == JobStatus.SUCCESS
assert status == RealizationState.SUCCESS
else:
assert status == JobStatus.FAILED
assert status == RealizationState.FAILED


def test_batch_ctx_status_failing_jobs(setup_case, storage):
Expand Down
16 changes: 10 additions & 6 deletions tests/unit_tests/simulator/test_simulation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ def test_simulation_context(setup_case, storage):
f"runpath/realization-{iens}-{iens}/iter-0"
)

assert even_ctx.job_queue.count_status(RealizationState.FAILED) == 0
assert even_ctx.job_queue.count_status(RealizationState.RUNNING) == 0
assert even_ctx.job_queue.count_status(RealizationState.SUCCESS) == size / 2
assert even_ctx.job_queue.count_realization_state(RealizationState.FAILED) == 0
assert even_ctx.job_queue.count_realization_state(RealizationState.RUNNING) == 0
assert (
even_ctx.job_queue.count_realization_state(RealizationState.SUCCESS) == size / 2
)

assert odd_ctx.job_queue.count_status(RealizationState.FAILED) == 0
assert odd_ctx.job_queue.count_status(RealizationState.RUNNING) == 0
assert odd_ctx.job_queue.count_status(RealizationState.SUCCESS) == size / 2
assert odd_ctx.job_queue.count_realization_state(RealizationState.FAILED) == 0
assert odd_ctx.job_queue.count_realization_state(RealizationState.RUNNING) == 0
assert (
odd_ctx.job_queue.count_realization_state(RealizationState.SUCCESS) == size / 2
)

for iens in range(size):
if iens % 2 == 0:
Expand Down
Loading