Skip to content

Commit a87319c

Browse files
committed
Merge remote-tracking branch 'origin/master' into mypy
2 parents 100f289 + e091a12 commit a87319c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+822
-280
lines changed

.github/workflows/automerge.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: automerge
2+
on:
3+
pull_request:
4+
types:
5+
- labeled
6+
- unlabeled
7+
- synchronize
8+
- opened
9+
- edited
10+
- ready_for_review
11+
- reopened
12+
- unlocked
13+
pull_request_review:
14+
types:
15+
- submitted
16+
check_suite:
17+
types:
18+
- completed
19+
status: {}
20+
jobs:
21+
automerge:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: automerge
25+
uses: "pascalgn/automerge-action@f81beb99aef41bb55ad072857d43073fba833a98"
26+
env:
27+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ ENV/
9595
benchmarks/html/
9696
benchmarks/results/
9797
.asv
98+
99+
# vscode configuration
100+
.vscode/

.pre-commit-config.yaml

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.4.0
4-
hooks:
5-
- id: trailing-whitespace
6-
- id: end-of-file-fixer
7-
- id: check-docstring-first
8-
- id: check-yaml
9-
- id: debug-statements
10-
- id: check-ast
11-
- repo: https://github.com/ambv/black
12-
rev: 19.10b0
13-
hooks:
14-
- id: black
15-
language_version: python3.7
16-
- repo: https://github.com/asottile/pyupgrade
17-
rev: v1.25.2
18-
hooks:
19-
- id: pyupgrade
20-
args: ['--py36-plus']
21-
- repo: https://github.com/asottile/seed-isort-config
22-
rev: v1.9.3
23-
hooks:
24-
- id: seed-isort-config
25-
- repo: https://github.com/pre-commit/mirrors-isort
26-
rev: v4.3.21
27-
hooks:
28-
- id: isort
29-
- repo: https://gitlab.com/pycqa/flake8
30-
rev: 3.7.9
31-
hooks:
32-
- id: flake8
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.3.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-docstring-first
8+
- id: check-yaml
9+
- id: debug-statements
10+
- id: check-ast
11+
- repo: https://github.com/ambv/black
12+
rev: 20.8b1
13+
hooks:
14+
- id: black
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v2.7.3
17+
hooks:
18+
- id: pyupgrade
19+
args: ['--py36-plus']
20+
- repo: https://github.com/timothycrosley/isort
21+
rev: 5.6.4
22+
hooks:
23+
- id: isort
24+
- repo: https://gitlab.com/pycqa/flake8
25+
rev: 3.8.4
26+
hooks:
27+
- id: flake8

.zenodo.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"creators": [
3+
{
4+
"affiliation": "Microsoft, Station Q",
5+
"name": "Nijholt, Bas",
6+
"orcid": "0000-0003-0383-4986"
7+
},
8+
{
9+
"affiliation": "Microsoft, Station Q",
10+
"name": "Weston, Joseph",
11+
"orcid": "0000-0002-7014-7134"
12+
},
13+
{
14+
"affiliation": "Kavli Institute of Nanoscience, Delft University of Technology",
15+
"name": "Hoofwijk, Jorn"
16+
},
17+
{
18+
"affiliation": "Kavli Institute of Nanoscience, Delft University of Technology",
19+
"name": "Akhmerov, Anton",
20+
"orcid": "0000-0001-8031-1340"
21+
}
22+
],
23+
"keywords": [
24+
"adaptive-learning",
25+
"machine-learning",
26+
"python",
27+
"live-plots",
28+
"parallel-computing",
29+
"adaptive-sampling",
30+
"parallel",
31+
"adaptive active-learning"
32+
],
33+
"license": "BSD-3-Clause",
34+
"upload_type": "software"
35+
}

AUTHORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ Other contributors to Adaptive include:
1111
+ Andrey E. Antipov
1212
+ [Christoph Groth](<http://inac.cea.fr/Pisp/christoph.groth/>)
1313
+ Jorn Hoofwijk
14+
+ Philippe Solodov (@philippeitis)
1415
+ Victor Negîrneac (@caenrigen)
16+
+ Thomas A Caswell (@tacaswell)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2017-2019, Adaptive authors
3+
Copyright (c) 2017-2020, Adaptive authors
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,30 @@ In addition to the learners, ``adaptive`` also provides primitives for
5555
running the sampling across several cores and even several machines,
5656
with built-in support for
5757
`concurrent.futures <https://docs.python.org/3/library/concurrent.futures.html>`_,
58+
`mpi4py <https://mpi4py.readthedocs.io/en/stable/mpi4py.futures.html>`_,
59+
`loky <https://loky.readthedocs.io/en/stable/>`_,
5860
`ipyparallel <https://ipyparallel.readthedocs.io/en/latest/>`_ and
5961
`distributed <https://distributed.readthedocs.io/en/latest/>`_.
6062

6163
Examples
6264
--------
6365

66+
Adaptively learning a 1D function (the `gif` below) and live-plotting the process in a Jupyter notebook is as easy as
67+
68+
.. code:: python
69+
70+
from adaptive import notebook_extension, Runner, Learner1D
71+
notebook_extension()
72+
73+
def peak(x, a=0.01):
74+
return x + a**2 / (a**2 + x**2)
75+
76+
learner = Learner1D(peak, bounds=(-1, 1))
77+
runner = Runner(learner, goal=lambda l: l.loss() < 0.01)
78+
runner.live_info()
79+
runner.live_plot()
80+
81+
6482
.. raw:: html
6583

6684
<img src="https://user-images.githubusercontent.com/6897215/38739170-6ac7c014-3f34-11e8-9e8f-93b3a3a3d61b.gif" width='20%'> </img> <img src="https://user-images.githubusercontent.com/6897215/35219611-ac8b2122-ff73-11e7-9332-adffab64a8ce.gif" width='40%'> </img> <img src="https://user-images.githubusercontent.com/6897215/47256441-d6d53700-d480-11e8-8224-d1cc49dbdcf5.gif" width='20%'> </img>
@@ -89,6 +107,13 @@ The recommended way to install adaptive is using ``conda``:
89107
The ``[notebook]`` above will also install the optional dependencies for
90108
running ``adaptive`` inside a Jupyter notebook.
91109

110+
To use Adaptive in Jupyterlab, you need to install the following labextensions.
111+
112+
.. code:: bash
113+
114+
jupyter labextension install @jupyter-widgets/jupyterlab-manager
115+
jupyter labextension install @pyviz/jupyterlab_pyviz
116+
92117
Development
93118
-----------
94119

adaptive/_version.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44
import subprocess
55
from collections import namedtuple
6-
from distutils.command.build_py import build_py as build_py_orig
76
from typing import Dict
87

8+
from setuptools.command.build_py import build_py as build_py_orig
99
from setuptools.command.sdist import sdist as sdist_orig
1010

1111
Version = namedtuple("Version", ("release", "dev", "labels"))
@@ -16,6 +16,13 @@
1616
package_root = os.path.dirname(os.path.realpath(__file__))
1717
package_name = os.path.basename(package_root)
1818
distr_root = os.path.dirname(package_root)
19+
# If the package is inside a "src" directory the
20+
# distribution root is 1 level up.
21+
if os.path.split(distr_root)[1] == "src":
22+
_package_root_inside_src = True
23+
distr_root = os.path.dirname(distr_root)
24+
else:
25+
_package_root_inside_src = False
1926

2027
STATIC_VERSION_FILE = "_static_version.py"
2128

@@ -190,7 +197,11 @@ def run(self):
190197
class _sdist(sdist_orig):
191198
def make_release_tree(self, base_dir, files):
192199
super().make_release_tree(base_dir, files)
193-
_write_version(os.path.join(base_dir, package_name, STATIC_VERSION_FILE))
200+
if _package_root_inside_src:
201+
p = os.path.join("src", package_name)
202+
else:
203+
p = package_name
204+
_write_version(os.path.join(base_dir, p, STATIC_VERSION_FILE))
194205

195206

196207
cmdclass = dict(sdist=_sdist, build_py=_build_py)

adaptive/learner/average_learner.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class AverageLearner(BaseLearner):
2020
Desired absolute tolerance.
2121
rtol : float
2222
Desired relative tolerance.
23+
min_npoints : int
24+
Minimum number of points to sample.
2325
2426
Attributes
2527
----------
@@ -36,6 +38,7 @@ def __init__(
3638
function: Callable,
3739
atol: Optional[float] = None,
3840
rtol: Optional[float] = None,
41+
min_npoints: int = 2,
3942
) -> None:
4043
if atol is None and rtol is None:
4144
raise Exception("At least one of `atol` and `rtol` should be set.")
@@ -50,6 +53,8 @@ def __init__(
5053
self.atol = atol
5154
self.rtol = rtol
5255
self.npoints = 0
56+
# Cannot estimate standard deviation with fewer than 2 points.
57+
self.min_npoints = max(min_npoints, 2)
5358
self.sum_f = 0
5459
self.sum_f_sq = 0
5560

@@ -98,7 +103,7 @@ def std(self) -> float:
98103
"""The corrected sample standard deviation of the values
99104
in `data`."""
100105
n = self.npoints
101-
if n < 2:
106+
if n < self.min_npoints:
102107
return np.inf
103108
numerator = self.sum_f_sq - n * self.mean ** 2
104109
if numerator < 0:
@@ -112,7 +117,7 @@ def loss(self, real: bool = True, *, n=None) -> float:
112117
n = self.npoints if real else self.n_requested
113118
else:
114119
n = n
115-
if n < 2:
120+
if n < self.min_npoints:
116121
return np.inf
117122
standard_error = self.std / sqrt(n)
118123
return max(
@@ -143,10 +148,24 @@ def plot(self):
143148
return hv.Histogram([[], []])
144149
num_bins = int(max(5, sqrt(self.npoints)))
145150
vals = hv.Points(vals)
146-
return hv.operation.histogram(vals, num_bins=num_bins, dimension=1)
151+
return hv.operation.histogram(vals, num_bins=num_bins, dimension="y")
147152

148153
def _get_data(self) -> Tuple[Dict[int, float], int, float, float]:
149154
return (self.data, self.npoints, self.sum_f, self.sum_f_sq)
150155

151156
def _set_data(self, data: Tuple[Dict[int, float], int, float, float]) -> None:
152157
self.data, self.npoints, self.sum_f, self.sum_f_sq = data
158+
159+
def __getstate__(self):
160+
return (
161+
self.function,
162+
self.atol,
163+
self.rtol,
164+
self.min_npoints,
165+
self._get_data(),
166+
)
167+
168+
def __setstate__(self, state):
169+
function, atol, rtol, min_npoints, data = state
170+
self.__init__(function, atol, rtol, min_npoints)
171+
self._set_data(data)

adaptive/learner/balancing_learner.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,14 @@ def _get_data(self):
455455
def _set_data(self, data):
456456
for l, _data in zip(self.learners, data):
457457
l._set_data(_data)
458+
459+
def __getstate__(self):
460+
return (
461+
self.learners,
462+
self._cdims_default,
463+
self.strategy,
464+
)
465+
466+
def __setstate__(self, state):
467+
learners, cdims, strategy = state
468+
self.__init__(learners, cdims=cdims, strategy=strategy)

0 commit comments

Comments
 (0)