Skip to content

Commit 761afa8

Browse files
committed
rename datetime_goal to end_time_goal
1 parent ae6ab64 commit 761afa8

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

adaptive/runner.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class BaseRunner(metaclass=abc.ABCMeta):
8484
Convenience argument, use instead of ``goal``. The end condition for the
8585
calculation. Stop when the number of points is larger or
8686
equal than this value.
87-
datetime_goal : datetime, optional
87+
end_time_goal : datetime, optional
8888
Convenience argument, use instead of ``goal``. The end condition for the
8989
calculation. Stop when the current time is larger or equal than this
9090
value.
@@ -147,7 +147,7 @@ def __init__(
147147
*,
148148
loss_goal: float | None = None,
149149
npoints_goal: int | None = None,
150-
datetime_goal: datetime | None = None,
150+
end_time_goal: datetime | None = None,
151151
duration_goal: timedelta | None = None,
152152
executor=None,
153153
ntasks=None,
@@ -164,7 +164,7 @@ def __init__(
164164
goal,
165165
loss_goal,
166166
npoints_goal,
167-
datetime_goal,
167+
end_time_goal,
168168
duration_goal,
169169
allow_running_forever,
170170
)
@@ -422,7 +422,7 @@ def __init__(
422422
*,
423423
loss_goal: float | None = None,
424424
npoints_goal: int | None = None,
425-
datetime_goal: datetime | None = None,
425+
end_time_goal: datetime | None = None,
426426
duration_goal: timedelta | None = None,
427427
executor=None,
428428
ntasks=None,
@@ -438,7 +438,7 @@ def __init__(
438438
goal=goal,
439439
loss_goal=loss_goal,
440440
npoints_goal=npoints_goal,
441-
datetime_goal=datetime_goal,
441+
end_time_goal=end_time_goal,
442442
duration_goal=duration_goal,
443443
executor=executor,
444444
ntasks=ntasks,
@@ -503,7 +503,7 @@ class AsyncRunner(BaseRunner):
503503
Convenience argument, use instead of ``goal``. The end condition for the
504504
calculation. Stop when the number of points is larger or
505505
equal than this value.
506-
datetime_goal : datetime, optional
506+
end_time_goal : datetime, optional
507507
Convenience argument, use instead of ``goal``. The end condition for the
508508
calculation. Stop when the current time is larger or equal than this
509509
value.
@@ -580,7 +580,7 @@ def __init__(
580580
*,
581581
loss_goal: float | None = None,
582582
npoints_goal: int | None = None,
583-
datetime_goal: datetime | None = None,
583+
end_time_goal: datetime | None = None,
584584
duration_goal: timedelta | None = None,
585585
executor=None,
586586
ntasks=None,
@@ -612,7 +612,7 @@ def __init__(
612612
goal=goal,
613613
loss_goal=loss_goal,
614614
npoints_goal=npoints_goal,
615-
datetime_goal=datetime_goal,
615+
end_time_goal=end_time_goal,
616616
duration_goal=duration_goal,
617617
executor=executor,
618618
ntasks=ntasks,
@@ -799,7 +799,7 @@ def simple(
799799
*,
800800
loss_goal: float | None = None,
801801
npoints_goal: int | None = None,
802-
datetime_goal: datetime | None = None,
802+
end_time_goal: datetime | None = None,
803803
duration_goal: timedelta | None = None,
804804
):
805805
"""Run the learner until the goal is reached.
@@ -827,7 +827,7 @@ def simple(
827827
Convenience argument, use instead of ``goal``. The end condition for the
828828
calculation. Stop when the number of points is larger or
829829
equal than this value.
830-
datetime_goal : datetime, optional
830+
end_time_goal : datetime, optional
831831
Convenience argument, use instead of ``goal``. The end condition for the
832832
calculation. Stop when the current time is larger or equal than this
833833
value.
@@ -841,7 +841,7 @@ def simple(
841841
goal,
842842
loss_goal,
843843
npoints_goal,
844-
datetime_goal,
844+
end_time_goal,
845845
duration_goal,
846846
allow_running_forever=False,
847847
)
@@ -973,7 +973,8 @@ class _TimeGoal:
973973
def __init__(self, dt: timedelta | datetime | int | float):
974974
if not isinstance(dt, (timedelta, datetime)):
975975
self.dt = timedelta(seconds=dt)
976-
self.dt = dt
976+
else:
977+
self.dt = dt
977978
self.start_time = None
978979

979980
def __call__(self, _):
@@ -990,7 +991,7 @@ def auto_goal(
990991
*,
991992
loss: float | None = None,
992993
npoints: int | None = None,
993-
datetime: datetime | None = None,
994+
end_time: datetime | None = None,
994995
duration: timedelta | int | None = None,
995996
learner: BaseLearner | None = None,
996997
allow_running_forever: bool = True,
@@ -1003,7 +1004,7 @@ def auto_goal(
10031004
TODO
10041005
npoints
10051006
TODO
1006-
datetime
1007+
end_time
10071008
TODO
10081009
duration
10091010
TODO
@@ -1020,14 +1021,14 @@ def auto_goal(
10201021
kw = dict(
10211022
loss=loss,
10221023
npoints=npoints,
1023-
datetime=datetime,
1024+
end_time=end_time,
10241025
duration=duration,
10251026
allow_running_forever=allow_running_forever,
10261027
)
1027-
opts = (loss, npoints, datetime, duration) # all are mutually exclusive
1028+
opts = (loss, npoints, end_time, duration) # all are mutually exclusive
10281029
if sum(v is not None for v in opts) > 1:
10291030
raise ValueError(
1030-
"Only one of loss, npoints, datetime, duration can be specified."
1031+
"Only one of loss, npoints, end_time, duration can be specified."
10311032
)
10321033

10331034
if loss is not None:
@@ -1040,8 +1041,8 @@ def auto_goal(
10401041
return lambda learner: all(goal(l) for l, goal in zip(learner.learners, goals))
10411042
if npoints is not None:
10421043
return lambda learner: learner.npoints >= npoints
1043-
if datetime is not None:
1044-
return _TimeGoal(datetime)
1044+
if end_time is not None:
1045+
return _TimeGoal(end_time)
10451046
if duration is not None:
10461047
return _TimeGoal(duration)
10471048
if isinstance(learner, DataSaver):
@@ -1066,7 +1067,7 @@ def _goal(
10661067
goal: Callable[[BaseLearner], bool] | None,
10671068
loss_goal: float | None,
10681069
npoints_goal: int | None,
1069-
datetime_goal: datetime | None,
1070+
end_time_goal: datetime | None,
10701071
duration_goal: timedelta | None,
10711072
allow_running_forever: bool,
10721073
):
@@ -1076,18 +1077,18 @@ def _goal(
10761077
if goal is not None and (
10771078
loss_goal is not None
10781079
or npoints_goal is not None
1079-
or datetime_goal is not None
1080+
or end_time_goal is not None
10801081
or duration_goal is not None
10811082
):
10821083
raise ValueError(
1083-
"Either goal, loss_goal, npoints_goal, datetime_goal or"
1084+
"Either goal, loss_goal, npoints_goal, end_time_goal or"
10841085
" duration_goal can be specified, not multiple."
10851086
)
10861087
return auto_goal(
10871088
learner=learner,
10881089
loss=loss_goal,
10891090
npoints=npoints_goal,
1090-
datetime=datetime_goal,
1091+
end_time=end_time_goal,
10911092
duration=duration_goal,
10921093
allow_running_forever=allow_running_forever,
10931094
)

adaptive/tests/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,6 @@ def test_auto_goal():
199199

200200
learner = Learner1D(linear, (-1, 1))
201201
t_start = time.time()
202-
simple(learner, auto_goal(timedelta=1e-2, learner=learner))
202+
simple(learner, auto_goal(duration=1e-2, learner=learner))
203203
t_end = time.time()
204204
assert t_end - t_start >= 1e-2

0 commit comments

Comments
 (0)