Skip to content

Commit

Permalink
Make ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Jan 4, 2024
1 parent 7131c0f commit b091563
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
9 changes: 1 addition & 8 deletions src/ert/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,18 @@ class _JobsJson:
class SubmitSleeper:
_submit_sleep: float
_last_started: float
_starttime: float

def __init__(self, submit_sleep: float):
self._submit_sleep = submit_sleep
self._last_started = (
time.time() - submit_sleep
) # Allow the first to start immediately
self._starttime = time.time()

async def sleep_until_we_can_submit(self):

Check failure on line 53 in src/ert/scheduler/scheduler.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

Function is missing a return type annotation
now = time.time()
# next_start_time = self._last_started + self._submit_sleep
next_start_time = max(self._last_started + self._submit_sleep, now)
delay = next_start_time - now
self._last_started = next_start_time
print(
f"at {now - self._starttime}, sleeping {max(0, delay)} until {round(self._last_started - self._starttime, 3)}"
)
await asyncio.sleep(max(0, delay))
await asyncio.sleep(max(0, next_start_time - now))


class Scheduler:
Expand Down
23 changes: 5 additions & 18 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import datetime
import json
import random
import shutil
import time
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -346,7 +346,7 @@ async def wait(iens):

@pytest.mark.parametrize(
"submit_sleep, iens_stride, realization_runtime, expected_max_running",
[(0, 1, 0.1, 10), (0.1, 1, 0.1, 2), (0.1, 2, 0.1, 2), (0.1, 3, 0.4, 5)],
[(0, 1, 0.1, 10), (0.1, 1, 0.1, 2), (0.1, 2, 0.1, 2)],
)
async def test_submit_sleep(
submit_sleep,
Expand Down Expand Up @@ -393,32 +393,22 @@ async def wait():
"submit_sleep, realization_max_runtime, max_running",
[
(0.01, 0.01, 1),
(0.01, 0.01, 10),
(0.01, 0.1, 5),
# (0.1, 1, 2),
# (0.05, 1, 5),
],
)
async def test_submit_sleep_with_max_running(
submit_sleep, realization_max_runtime, max_running, storage, tmp_path, mock_driver
):
print()
import time

run_start_times: List[float] = []
iens = 0
globalnow = time.time()

async def wait():
nonlocal run_start_times, iens, globalnow
origiens = iens
print(f"starting realization {iens} at {time.time() - globalnow}")
nonlocal run_start_times
run_start_times.append(time.time())
# If the realization runtimes are constant, we will never get into
# the situation where we can start many realizations at the same moment
iens += 1
runtime = realization_max_runtime * random.random()
await asyncio.sleep(runtime)
print(f"a realization {origiens} finished in {round(runtime,3)} seconds")

ensemble_size = 10

Expand All @@ -439,10 +429,7 @@ async def wait():
await sch.execute()

deltas = [
round(next_start - start, 3)
next_start - start
for start, next_start in zip(run_start_times[:-1], run_start_times[1:])
]
print(deltas)
# print([d.total_seconds() for d in deltas])
# 20% deviation is allowed to let tests pass with short runtimes.
assert min(deltas) >= submit_sleep * 0.8

0 comments on commit b091563

Please sign in to comment.