Skip to content

Add loss_goal, npoints_goal, and an auto_goal function and use it in the runners #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e7f2179
Add an auto_goal function and use it in the Runner
basnijholt Oct 14, 2022
30bccb7
Use new auto goal functionality
basnijholt Oct 14, 2022
d4359a4
Replace point goals
basnijholt Oct 14, 2022
17650f1
use auto_goal in runner.simple
basnijholt Oct 14, 2022
8fc4db7
fix comment
basnijholt Oct 14, 2022
3e68f44
fix doc-string
basnijholt Oct 14, 2022
0836e68
Fixes regarding > vs ≥
basnijholt Oct 14, 2022
fbc686c
Fix docstring formatting
basnijholt Oct 14, 2022
d7f6b9c
Add auto_goal to the docs
basnijholt Oct 14, 2022
84808a1
make compatible with older Python versions
basnijholt Oct 14, 2022
7900b5a
Import fixes
basnijholt Oct 14, 2022
05be948
Use loss_goal and npoints_goal
basnijholt Nov 14, 2022
efe4a44
DataSaver fix
basnijholt Nov 14, 2022
dbd81c3
Use ImportError instead of ModuleNotFoundError
basnijholt Nov 14, 2022
8fcaee9
Use flake8 from GitHub
basnijholt Nov 14, 2022
873eb0f
Add doc-string entries for loss_goal and npoints_goal
basnijholt Nov 14, 2022
470c58f
do not make goal keyword-only
basnijholt Nov 14, 2022
11e14c4
add test_auto_goal
basnijholt Nov 14, 2022
2a77ca2
Implement losses explicitly
basnijholt Nov 15, 2022
6f3437a
Remove unused variable
basnijholt Nov 15, 2022
be14576
pass parameters and add doc-strings
basnijholt Nov 17, 2022
0f7d320
Allow timedelta_goal to be an int
basnijholt Nov 17, 2022
8b300de
Test timedelta goal
basnijholt Nov 21, 2022
ae6ab64
rename timedelta to duration
basnijholt Nov 21, 2022
761afa8
rename datetime_goal to end_time_goal
basnijholt Nov 21, 2022
c96e5a4
complete doc-string of auto_goal
basnijholt Nov 22, 2022
84bd796
No longer restrict scikit-learn
basnijholt Nov 23, 2022
68b3143
fix type annotations
basnijholt Nov 23, 2022
881a2d3
Update "Stopping Criteria" Runner docs
basnijholt Nov 23, 2022
efb46f1
Fix loss in tutorial
basnijholt Nov 23, 2022
563a633
Add missing end_time_goal and duration_goal to doc-string
basnijholt Nov 23, 2022
2186c02
Use exact same text in different runners
basnijholt Nov 23, 2022
b5f6f26
Specify when learner is used in auto_goal
basnijholt Nov 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
rev: 5.10.1
hooks:
- id: isort
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def peak(x, a=0.01):


learner = Learner1D(peak, bounds=(-1, 1))
runner = Runner(learner, goal=lambda l: l.loss() < 0.01)
runner = Runner(learner, loss_goal=0.01)
runner.live_info()
runner.live_plot()
```
Expand Down
3 changes: 2 additions & 1 deletion adaptive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from contextlib import suppress

from adaptive import learner, runner, utils
from adaptive._version import __version__
from adaptive.learner import (
AverageLearner,
Expand All @@ -22,6 +21,8 @@
)
from adaptive.runner import AsyncRunner, BlockingRunner, Runner

from adaptive import learner, runner, utils # isort:skip

__all__ = [
"learner",
"runner",
Expand Down
14 changes: 13 additions & 1 deletion adaptive/learner/data_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _to_key(x):
return tuple(x.values) if x.values.size > 1 else x.item()


class DataSaver:
class DataSaver(BaseLearner):
"""Save extra data associated with the values that need to be learned.

Parameters
Expand Down Expand Up @@ -50,6 +50,18 @@ def new(self) -> DataSaver:
"""Return a new `DataSaver` with the same `arg_picker` and `learner`."""
return DataSaver(self.learner.new(), self.arg_picker)

@copy_docstring_from(BaseLearner.ask)
def ask(self, *args, **kwargs):
return self.learner.ask(*args, **kwargs)

@copy_docstring_from(BaseLearner.loss)
def loss(self, *args, **kwargs):
return self.learner.loss(*args, **kwargs)

@copy_docstring_from(BaseLearner.remove_unfinished)
def remove_unfinished(self, *args, **kwargs):
return self.learner.remove_unfinished(*args, **kwargs)

def __getattr__(self, attr: str) -> Any:
return getattr(self.learner, attr)

Expand Down
Loading