Skip to content

Commit b3f7713

Browse files
committed
Refactor duration to utilization duration
1 parent bb0fef4 commit b3f7713

10 files changed

Lines changed: 36 additions & 29 deletions

File tree

app/grandchallenge/components/backends/amazon_sagemaker_base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _stop_job_boto(self):
357357
def __init__(self, *args, **kwargs):
358358
super().__init__(*args, **kwargs)
359359

360-
self.__duration = None
360+
self.__utilization_duration = None
361361
self.__runtime_metrics = {}
362362

363363
self.__sagemaker_client = None
@@ -413,8 +413,8 @@ def _cloudwatch_client(self):
413413
return self.__cloudwatch_client
414414

415415
@property
416-
def duration(self):
417-
return self.__duration
416+
def utilization_duration(self):
417+
return self.__utilization_duration
418418

419419
@property
420420
def runtime_metrics(self):
@@ -536,10 +536,10 @@ def _set_duration(self, *, event):
536536
self._get_start_time(event=event)
537537
)
538538
stopped = ms_timestamp_to_datetime(self._get_end_time(event=event))
539-
self.__duration = stopped - started
539+
self.__utilization_duration = stopped - started
540540
except TypeError:
541541
logger.warning("Invalid start or end time, duration undetermined")
542-
self.__duration = None
542+
self.__utilization_duration = None
543543

544544
def _get_log_stream_name(self, *, data_log=False):
545545
response = self._logs_client.describe_log_streams(

app/grandchallenge/components/backends/base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def stderr(self):
399399

400400
@property
401401
@abstractmethod
402-
def duration(self): ...
402+
def utilization_duration(self): ...
403403

404404
@property
405405
@abstractmethod
@@ -449,12 +449,13 @@ def _max_memory_mb(self):
449449

450450
@property
451451
def compute_cost_euro_millicents(self):
452-
duration = self.duration
453-
if duration is None:
452+
utilization_duration = self.utilization_duration
453+
if utilization_duration is None:
454454
return None
455455
else:
456456
return duration_to_millicents(
457-
duration=duration, usd_cents_per_hour=self.usd_cents_per_hour
457+
duration=utilization_duration,
458+
usd_cents_per_hour=self.usd_cents_per_hour,
458459
)
459460

460461
@property
@@ -479,7 +480,7 @@ def _invocation_key(self):
479480
return safe_join(self._invocation_prefix, "invocation.json")
480481

481482
@property
482-
def _result_key(self):
483+
def _inference_result_key(self):
483484
return safe_join(
484485
self._io_prefix, ".sagemaker_shim", "inference_result.json"
485486
)
@@ -818,7 +819,7 @@ def _get_inference_result(self):
818819
try:
819820
response = self._s3_client.get_object(
820821
Bucket=settings.COMPONENTS_OUTPUT_BUCKET_NAME,
821-
Key=self._result_key,
822+
Key=self._inference_result_key,
822823
)
823824
except botocore.exceptions.ClientError as error:
824825
if error.response["Error"]["Code"] == "404":
@@ -855,11 +856,11 @@ def _get_inference_result(self):
855856
"The invocation request did not return valid json"
856857
)
857858

859+
logger.info(f"{inference_result=}")
860+
858861
if inference_result.pk != self._job_id:
859862
raise RuntimeError("Wrong result key for this job")
860863

861-
logger.info(f"{inference_result=}")
862-
863864
return inference_result
864865

865866
def _handle_completed_job(self):

app/grandchallenge/components/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ def update_status(
17441744
stderr: str = "",
17451745
error_message="",
17461746
detailed_error_message=None,
1747-
duration=None,
1747+
utilization_duration=None,
17481748
compute_cost_euro_millicents=None,
17491749
runtime_metrics=None,
17501750
):
@@ -1765,8 +1765,8 @@ def update_status(
17651765
for key, value in detailed_error_message.items()
17661766
}
17671767

1768-
if duration is not None:
1769-
self.utilization.duration = duration
1768+
if utilization_duration is not None:
1769+
self.utilization.duration = utilization_duration
17701770
self.utilization.save(update_fields=["duration"])
17711771

17721772
if compute_cost_euro_millicents is not None:

app/grandchallenge/components/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def get_update_status_kwargs(*, executor=None):
857857
return {
858858
"stdout": executor.stdout,
859859
"stderr": executor.stderr,
860-
"duration": executor.duration,
860+
"utilization_duration": executor.utilization_duration,
861861
"compute_cost_euro_millicents": executor.compute_cost_euro_millicents,
862862
"runtime_metrics": executor.runtime_metrics,
863863
}

app/grandchallenge/evaluation/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def update(self, instance, validated_data):
281281
]
282282
and instance.evaluation_utilization.duration is None
283283
):
284-
extra_kwargs.update(duration=now() - instance.claimed_at)
284+
extra_kwargs["utilization_duration"] = now() - instance.claimed_at
285285

286286
# calling update_status takes care of sending the notifications
287287
instance.update_status(

app/tests/algorithms_tests/test_models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def test_average_duration(settings, django_capture_on_commit_callbacks):
8686
)
8787

8888
with django_capture_on_commit_callbacks(execute=True):
89-
j.update_status(status=j.SUCCESS, duration=timedelta(minutes=5))
89+
j.update_status(
90+
status=j.SUCCESS, utilization_duration=timedelta(minutes=5)
91+
)
9092

9193
alg.refresh_from_db()
9294
assert alg.average_duration == timedelta(minutes=5)
@@ -97,7 +99,9 @@ def test_average_duration(settings, django_capture_on_commit_callbacks):
9799
)
98100

99101
with django_capture_on_commit_callbacks(execute=True):
100-
j.update_status(status=j.FAILURE, duration=timedelta(minutes=10))
102+
j.update_status(
103+
status=j.FAILURE, utilization_duration=timedelta(minutes=10)
104+
)
101105

102106
alg.refresh_from_db()
103107
assert alg.average_duration == timedelta(minutes=5)
@@ -106,7 +110,9 @@ def test_average_duration(settings, django_capture_on_commit_callbacks):
106110
j = AlgorithmJobFactory(time_limit=60)
107111

108112
with django_capture_on_commit_callbacks(execute=True):
109-
j.update_status(status=j.SUCCESS, duration=timedelta(minutes=15))
113+
j.update_status(
114+
status=j.SUCCESS, utilization_duration=timedelta(minutes=15)
115+
)
110116

111117
alg.refresh_from_db()
112118
assert alg.average_duration == timedelta(minutes=5)

app/tests/components_tests/resources/backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def execute(self):
107107
self._s3_client.upload_fileobj(
108108
Fileobj=io.BytesIO(inference_result_content),
109109
Bucket=settings.COMPONENTS_OUTPUT_BUCKET_NAME,
110-
Key=self._result_key,
110+
Key=self._inference_result_key,
111111
ExtraArgs={
112112
"Metadata": {"signature_hmac_sha256": signature},
113113
},
@@ -163,7 +163,7 @@ def get_job_params(*, job_name):
163163
)
164164

165165
@property
166-
def duration(self):
166+
def utilization_duration(self):
167167
return now() - self.__start_time
168168

169169
@property

app/tests/components_tests/test_amazon_sagemaker_training_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def test_set_duration():
258258
signing_key=b"",
259259
)
260260

261-
assert executor.duration is None
261+
assert executor.utilization_duration is None
262262

263263
executor._set_duration(
264264
event={
@@ -268,7 +268,7 @@ def test_set_duration():
268268
}
269269
)
270270

271-
assert executor.duration == timedelta(seconds=21)
271+
assert executor.utilization_duration == timedelta(seconds=21)
272272

273273

274274
def test_get_log_stream_name(settings):
@@ -579,7 +579,7 @@ def test_handle_completed_job():
579579
executor._s3_client.upload_fileobj(
580580
Fileobj=io.BytesIO(inference_result_content),
581581
Bucket=settings.COMPONENTS_OUTPUT_BUCKET_NAME,
582-
Key=executor._result_key,
582+
Key=executor._inference_result_key,
583583
ExtraArgs={
584584
"Metadata": {"signature_hmac_sha256": signature},
585585
},

app/tests/components_tests/test_backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ def test_invocation_results_signature_unverified(settings):
776776
executor._s3_client.upload_fileobj(
777777
Fileobj=io.BytesIO(inference_result_content),
778778
Bucket=settings.COMPONENTS_OUTPUT_BUCKET_NAME,
779-
Key=executor._result_key,
779+
Key=executor._inference_result_key,
780780
ExtraArgs={
781781
"Metadata": {"signature_hmac_sha256": signature},
782782
},
@@ -824,7 +824,7 @@ def test_invocation_results_signature_verified(settings):
824824
executor._s3_client.upload_fileobj(
825825
Fileobj=io.BytesIO(inference_result_content),
826826
Bucket=settings.COMPONENTS_OUTPUT_BUCKET_NAME,
827-
Key=executor._result_key,
827+
Key=executor._inference_result_key,
828828
ExtraArgs={
829829
"Metadata": {"signature_hmac_sha256": signature},
830830
},

app/tests/utilization_tests/test_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def usd_cents_per_hour(self):
2424
return 12.1
2525

2626
@property
27-
def duration(self):
27+
def utilization_duration(self):
2828
raise NotImplementedError
2929

3030
def execute(self):

0 commit comments

Comments
 (0)