Runner extras¶
Stopping Criteria¶
Runners allow you to specify the stopping criterion by providing
a goal as a function that takes the learner and returns a boolean: False
for "continue running" and True for "stop". This gives you a lot of flexibility
for defining your own stopping conditions, however we also provide some common
stopping conditions as a convenience. For example, to continue until the loss is below a threshold x,
you may specify loss_goal=x. Similarly, to continue until n points have been sampled, you may
specify npoints_goal=n. See the Runner docstring for details.
auto_goal
¶
auto_goal(*, loss: float | None = None, npoints: int | None = None, end_time: datetime | None = None, duration: timedelta | int | float | None = None, learner: LearnerType | None = None, allow_running_forever: bool = True) -> Callable[[LearnerType], bool]
Extract a goal from the learners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loss
|
float
|
Stop when the loss is smaller than this value. |
None
|
npoints
|
int
|
Stop when the number of points is larger or equal than this value. |
None
|
end_time
|
datetime
|
Stop when the current time is larger or equal than this value. |
None
|
duration
|
timedelta or number
|
Stop when the current time is larger or equal than
|
None
|
learner
|
LearnerType | None
|
Learner for which to determine the goal. Only used if the learner type
is |
None
|
allow_running_forever
|
bool
|
If True, and the goal is None and the learner is not a SequenceLearner, then a goal that never stops is returned, otherwise an exception is raised. |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[BaseLearner], bool]
|
|
Source code in adaptive/runner.py
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 | |
stop_after
¶
Stop a runner after a specified time.
For example, to specify a runner that should stop after 5 minutes, one could do the following:
runner = Runner(learner, goal=stop_after(minutes=5))
To stop a runner after 2 hours, 10 minutes and 3 seconds, one could do the following:
runner = Runner(learner, goal=stop_after(hours=2, minutes=10, seconds=3))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
If more than one is specified, then they are added together |
0
|
minutes
|
float
|
If more than one is specified, then they are added together |
0
|
hours
|
float
|
If more than one is specified, then they are added together |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
goal |
callable
|
Can be used as the |
Notes
The duration specified is only a lower bound on the time that the runner will run for, because the runner only checks its goal when it adds points to its learner
Source code in adaptive/runner.py
Simple executor¶
simple
¶
simple(learner: LearnerType, goal: Callable[[LearnerType], bool] | None = None, *, loss_goal: float | None = None, npoints_goal: int | None = None, end_time_goal: datetime | None = None, duration_goal: timedelta | int | float | None = None, points_per_ask: int = 1)
Run the learner until the goal is reached.
Requests points from the learner, evaluates the function to be learned, and adds the points to the learner, until the goal is reached, blocking the current thread.
This function is useful for extracting error messages, as the learner's function is evaluated in the same thread, meaning that exceptions can simple be caught an inspected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learner
|
adaptive.BaseLearner instance
|
|
required |
goal
|
callable
|
The end condition for the calculation. This function must take the learner as its sole argument, and return True when we should stop requesting more points. |
None
|
loss_goal
|
float
|
Convenience argument, use instead of |
None
|
npoints_goal
|
int
|
Convenience argument, use instead of |
None
|
end_time_goal
|
datetime
|
Convenience argument, use instead of |
None
|
duration_goal
|
timedelta or number
|
Convenience argument, use instead of |
None
|
points_per_ask
|
int
|
The number of points to ask for between every interpolation rerun. Defaults to 1, which can introduce significant overhead on long runs. |
1
|
Source code in adaptive/runner.py
Sequential executor¶
SequentialExecutor
¶
Replay log¶
replay_log
¶
replay_log(learner: LearnerType, log: list[tuple[Literal['tell'], Any, Any] | tuple[Literal['ask'], int]]) -> None
Apply a sequence of method calls to a learner.
This is useful for debugging runners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learner
|
adaptive.BaseLearner instance
|
New learner where the log will be applied. |
required |
log
|
list
|
contains tuples: |
required |