Skip to content

Commit 0ffad3e

Browse files
committed
Expose computed timelim
1 parent 269e667 commit 0ffad3e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

problemtools/verifyproblem.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ def check(self, context: Context) -> bool:
16631663
max_runtime = max(runtimes)
16641664
exact_timelim = max_runtime * time_multiplier
16651665
max_runtime_str = f'{max_runtime:.3f}'
1666-
timelim = max(1, int(0.5 + exact_timelim))
1666+
timelim = max(1, int(0.5 + exact_timelim)) # TODO: properly support 2023-07 time limit computation
16671667
timelim_margin_lo = max(1, min(int(0.5 + exact_timelim / safety_margin), timelim - 1))
16681668
timelim_margin = max(timelim + 1, int(0.5 + exact_timelim * safety_margin))
16691669
else:
@@ -1673,11 +1673,12 @@ def check(self, context: Context) -> bool:
16731673
f' Solutions give timelim of {timelim} seconds, but will use provided fixed limit of {context.fixed_timelim} seconds instead'
16741674
)
16751675
timelim = context.fixed_timelim
1676-
timelim_margin = round(timelim * safety_margin) # TODO: properly support 2023-07 time limit computation
1676+
timelim_margin = round(timelim * safety_margin)
16771677

16781678
self.msg(
16791679
f' Slowest AC runtime: {max_runtime_str}, setting timelim to {timelim} secs, safety margin to {timelim_margin} secs'
16801680
)
1681+
self.problem._set_timelim(timelim)
16811682

16821683
return self._check_res
16831684

@@ -1697,6 +1698,7 @@ def __init__(self, probdir: str, args: argparse.Namespace):
16971698
self.loaded = False
16981699
self._metadata: metadata.Metadata | None = None
16991700
self._args = args
1701+
self._timelim: float | None = None
17001702

17011703
# Unfortunately must be before metadata, otherwise mypy gets confused about the type metadata.Metadata (feels like a bug)
17021704
def _set_metadata(self, metadata: metadata.Metadata) -> None: # Should only be called by ProblemConfig
@@ -1708,6 +1710,15 @@ def metadata(self) -> metadata.Metadata:
17081710
assert self._metadata is not None, 'Attempted to access config before it was set. load() or check() first.'
17091711
return self._metadata
17101712

1713+
@property
1714+
def timelim(self) -> float:
1715+
assert self._timelim is not None, 'Attempted to access timelim before it was set. check() first.'
1716+
return self._timelim
1717+
1718+
def _set_timelim(self, timelim: float) -> None: # Should only be called by Submissions
1719+
assert self._timelim is None, 'Attempted to set timelim twice'
1720+
self._timelim = timelim
1721+
17111722
def load(self) -> None:
17121723
"""Parses the problem package statically, loading up information with very little verification.
17131724

0 commit comments

Comments
 (0)