Skip to content

Commit 873eb0f

Browse files
committed
Add doc-string entries for loss_goal and npoints_goal
1 parent 8fcaee9 commit 873eb0f

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

adaptive/runner.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ class BaseRunner(metaclass=abc.ABCMeta):
8383
Parameters
8484
----------
8585
learner : `~adaptive.BaseLearner` instance
86-
goal : callable
86+
goal : callable, optional
8787
The end condition for the calculation. This function must take
8888
the learner as its sole argument, and return True when we should
89-
stop requesting more points.
89+
stop requesting more points. (Advanced use) Instead of providing a
90+
function, see `auto_goal` for other types that are accepted here.
91+
loss_goal : float, optional
92+
Convenience argument, use instead of ``goal``. The end condition for the
93+
calculation. Stop when the loss is smaller than this value.
94+
npoints_goal : int, optional
95+
Convenience argument, use instead of ``goal``. The end condition for the
96+
calculation. Stop when the number of points is larger or
97+
equal than this value.
9098
executor : `concurrent.futures.Executor`, `distributed.Client`,\
9199
`mpi4py.futures.MPIPoolExecutor`, `ipyparallel.Client` or\
92100
`loky.get_reusable_executor`, optional
@@ -340,7 +348,15 @@ class BlockingRunner(BaseRunner):
340348
goal : callable
341349
The end condition for the calculation. This function must take
342350
the learner as its sole argument, and return True when we should
343-
stop requesting more points.
351+
stop requesting more points. (Advanced use) Instead of providing a
352+
function, see `auto_goal` for other types that are accepted here.
353+
loss_goal : float
354+
Convenience argument, use instead of ``goal``. The end condition for the
355+
calculation. Stop when the loss is smaller than this value.
356+
npoints_goal : int
357+
Convenience argument, use instead of ``goal``. The end condition for the
358+
calculation. Stop when the number of points is larger or
359+
equal than this value.
344360
executor : `concurrent.futures.Executor`, `distributed.Client`,\
345361
`mpi4py.futures.MPIPoolExecutor`, `ipyparallel.Client` or\
346362
`loky.get_reusable_executor`, optional
@@ -465,8 +481,17 @@ class AsyncRunner(BaseRunner):
465481
goal : callable, optional
466482
The end condition for the calculation. This function must take
467483
the learner as its sole argument, and return True when we should
468-
stop requesting more points. If not provided, the runner will run
469-
forever, or until ``self.task.cancel()`` is called.
484+
stop requesting more points. (Advanced use) Instead of providing a
485+
function, see `auto_goal` for other types that are accepted here.
486+
If not provided, the runner will run forever (or stop when no more
487+
points can be added), or until ``self.task.cancel()`` is called.
488+
loss_goal : float, optional
489+
Convenience argument, use instead of ``goal``. The end condition for the
490+
calculation. Stop when the loss is smaller than this value.
491+
npoints_goal : int, optional
492+
Convenience argument, use instead of ``goal``. The end condition for the
493+
calculation. Stop when the number of points is larger or
494+
equal than this value.
470495
executor : `concurrent.futures.Executor`, `distributed.Client`,\
471496
`mpi4py.futures.MPIPoolExecutor`, `ipyparallel.Client` or\
472497
`loky.get_reusable_executor`, optional
@@ -765,8 +790,16 @@ def simple(
765790
----------
766791
learner : ~`adaptive.BaseLearner` instance
767792
goal : callable
768-
The end condition for the calculation. This function must take the
769-
learner as its sole argument, and return True if we should stop.
793+
The end condition for the calculation. This function must take
794+
the learner as its sole argument, and return True when we should
795+
stop requesting more points.
796+
loss_goal : float, optional
797+
Convenience argument, use instead of ``goal``. The end condition for the
798+
calculation. Stop when the loss is smaller than this value.
799+
npoints_goal : int, optional
800+
Convenience argument, use instead of ``goal``. The end condition for the
801+
calculation. Stop when the number of points is larger or
802+
equal than this value.
770803
"""
771804
goal = _goal(learner, goal, loss_goal, npoints_goal, allow_running_forever=False)
772805
while not goal(learner):
@@ -912,7 +945,7 @@ def auto_goal(
912945
goal: GoalTypes,
913946
learner: BaseLearner,
914947
allow_running_forever: bool = True,
915-
):
948+
) -> Callable[[BaseLearner], bool]:
916949
"""Extract a goal from the learners.
917950
918951
Parameters

docs/source/tutorial/tutorial.Learner1D.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ The `Learner1D` can be used for such functions:
124124

125125
```{code-cell} ipython3
126126
learner = adaptive.Learner1D(f_levels, bounds=(-1, 1))
127-
runner = adaptive.Runner(learner, loss_goal=0.01)
127+
runner = adaptive.Runner(learner, loss_goal=0.01) # continue until `learner.loss()<=1`
128128
```
129129

130130
```{code-cell} ipython3

0 commit comments

Comments
 (0)