Skip to content

Commit 03badcd

Browse files
committed
Merge branch 'doc' into 'master'
add documentation Closes #91 See merge request qt/adaptive!120
2 parents 3a69cd9 + eef11f0 commit 03badcd

38 files changed

Lines changed: 730 additions & 270 deletions

README.md

Lines changed: 0 additions & 100 deletions
This file was deleted.

README.rst

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
.. summary-start
2+
3+
.. _logo-adaptive:
4+
5+
|image0| adaptive
6+
=================
7+
8+
|PyPI| |Conda| |Downloads| |pipeline status| |DOI| |Binder| |Join the
9+
chat at https://gitter.im/python-adaptive/adaptive|
10+
11+
**Tools for adaptive parallel sampling of mathematical functions.**
12+
13+
``adaptive`` is an open-source Python library designed to
14+
make adaptive parallel function evaluation simple. With ``adaptive`` you
15+
just supply a function with its bounds, and it will be evaluated at the
16+
“best” points in parameter space. With just a few lines of code you can
17+
evaluate functions on a computing cluster, live-plot the data as it
18+
returns, and fine-tune the adaptive sampling algorithm.
19+
20+
Check out the ``adaptive`` example notebook
21+
`learner.ipynb <https://github.com/python-adaptive/adaptive/blob/master/learner.ipynb>`_ (or run it `live on
22+
Binder <https://mybinder.org/v2/gh/python-adaptive/adaptive/master?filepath=learner.ipynb>`_)
23+
to see examples of how to use ``adaptive``.
24+
25+
.. summary-end
26+
27+
**WARNING: adaptive is still in a beta development stage**
28+
29+
.. implemented-algorithms-start
30+
31+
Implemented algorithms
32+
----------------------
33+
34+
The core concept in ``adaptive`` is that of a *learner*. A *learner*
35+
samples a function at the best places in its parameter space to get
36+
maximum “information” about the function. As it evaluates the function
37+
at more and more points in the parameter space, it gets a better idea of
38+
where the best places are to sample next.
39+
40+
Of course, what qualifies as the “best places” will depend on your
41+
application domain! ``adaptive`` makes some reasonable default choices,
42+
but the details of the adaptive sampling are completely customizable.
43+
44+
The following learners are implemented:
45+
46+
- ``Learner1D``, for 1D functions ``f: ℝ → ℝ^N``,
47+
- ``Learner2D``, for 2D functions ``f: ℝ^2 → ℝ^N``,
48+
- ``LearnerND``, for ND functions ``f: ℝ^N → ℝ^M``,
49+
- ``AverageLearner``, For stochastic functions where you want to
50+
average the result over many evaluations,
51+
- ``IntegratorLearner``, for
52+
when you want to intergrate a 1D function ``f: ℝ → ℝ``,
53+
- ``BalancingLearner``, for when you want to run several learners at once,
54+
selecting the “best” one each time you get more points.
55+
56+
In addition to the learners, ``adaptive`` also provides primitives for
57+
running the sampling across several cores and even several machines,
58+
with built-in support for
59+
`concurrent.futures <https://docs.python.org/3/library/concurrent.futures.html>`_,
60+
`ipyparallel <https://ipyparallel.readthedocs.io/en/latest/>`_ and
61+
`distributed <https://distributed.readthedocs.io/en/latest/>`_.
62+
63+
.. implemented-algorithms-end
64+
65+
Examples
66+
--------
67+
68+
.. raw:: html
69+
70+
<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>
71+
72+
73+
Installation
74+
------------
75+
76+
``adaptive`` works with Python 3.6 and higher on Linux, Windows, or Mac,
77+
and provides optional extensions for working with the Jupyter/IPython
78+
Notebook.
79+
80+
The recommended way to install adaptive is using ``conda``:
81+
82+
.. code:: bash
83+
84+
conda install -c conda-forge adaptive
85+
86+
``adaptive`` is also available on PyPI:
87+
88+
.. code:: bash
89+
90+
pip install adaptive[notebook]
91+
92+
The ``[notebook]`` above will also install the optional dependencies for
93+
running ``adaptive`` inside a Jupyter notebook.
94+
95+
Development
96+
-----------
97+
98+
Clone the repository and run ``setup.py develop`` to add a link to the
99+
cloned repo into your Python path:
100+
101+
.. code:: bash
102+
103+
git clone git@github.com:python-adaptive/adaptive.git
104+
cd adaptive
105+
python3 setup.py develop
106+
107+
We highly recommend using a Conda environment or a virtualenv to manage
108+
the versions of your installed packages while working on ``adaptive``.
109+
110+
In order to not pollute the history with the output of the notebooks,
111+
please setup the git filter by executing
112+
113+
.. code:: bash
114+
115+
python ipynb_filter.py
116+
117+
in the repository.
118+
119+
Credits
120+
-------
121+
122+
We would like to give credits to the following people:
123+
124+
- Pedro Gonnet for his implementation of `CQUAD <https://www.gnu.org/software/gsl/manual/html_node/CQUAD-doubly_002dadaptive-integration.html>`_,
125+
“Algorithm 4” as described in “Increasing the Reliability of Adaptive
126+
Quadrature Using Explicit Interpolants”, P. Gonnet, ACM Transactions on
127+
Mathematical Software, 37 (3), art. no. 26, 2010.
128+
- Pauli Virtanen for his ``AdaptiveTriSampling`` script (no longer
129+
available online since SciPy Central went down) which served as
130+
inspiration for the ``~adaptive.Learner2D``.
131+
132+
For general discussion, we have a `Gitter chat
133+
channel <https://gitter.im/python-adaptive/adaptive>`_. If you find any
134+
bugs or have any feature suggestions please file a GitLab
135+
`issue <https://gitlab.kwant-project.org/qt/adaptive/issues/new?issue>`_
136+
or submit a `merge
137+
request <https://gitlab.kwant-project.org/qt/adaptive/merge_requests>`_.
138+
139+
.. references-start
140+
.. |image0| image:: https://gitlab.kwant-project.org/qt/adaptive/uploads/d20444093920a4a0499e165b5061d952/logo.png
141+
.. |PyPI| image:: https://img.shields.io/pypi/v/adaptive.svg
142+
:target: https://pypi.python.org/pypi/adaptive
143+
.. |Conda| image:: https://anaconda.org/conda-forge/adaptive/badges/installer/conda.svg
144+
:target: https://anaconda.org/conda-forge/adaptive
145+
.. |Downloads| image:: https://anaconda.org/conda-forge/adaptive/badges/downloads.svg
146+
:target: https://anaconda.org/conda-forge/adaptive
147+
.. |pipeline status| image:: https://gitlab.kwant-project.org/qt/adaptive/badges/master/pipeline.svg
148+
:target: https://gitlab.kwant-project.org/qt/adaptive/pipelines
149+
.. |DOI| image:: https://zenodo.org/badge/113714660.svg
150+
:target: https://zenodo.org/badge/latestdoi/113714660
151+
.. |Binder| image:: https://mybinder.org/badge.svg
152+
:target: https://mybinder.org/v2/gh/python-adaptive/adaptive/master?filepath=learner.ipynb
153+
.. |Join the chat at https://gitter.im/python-adaptive/adaptive| image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg
154+
:target: https://gitter.im/python-adaptive/adaptive
155+
.. references-end

adaptive/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
from . import runner
99
from . import utils
1010

11-
from .learner import (Learner1D, Learner2D, LearnerND, AverageLearner,
12-
BalancingLearner, make_datasaver, DataSaver,
13-
IntegratorLearner)
11+
from .learner import (BaseLearner, Learner1D, Learner2D, LearnerND,
12+
AverageLearner, BalancingLearner, make_datasaver,
13+
DataSaver, IntegratorLearner)
1414

1515
with suppress(ImportError):
1616
# Only available if 'scikit-optimize' is installed
1717
from .learner import SKOptLearner
1818

19-
from .runner import Runner, BlockingRunner
19+
from .runner import Runner, AsyncRunner, BlockingRunner
2020

2121
from ._version import __version__
2222
del _version

adaptive/learner/average_learner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class AverageLearner(BaseLearner):
1717
Parameters
1818
----------
1919
atol : float
20-
Desired absolute tolerance
20+
Desired absolute tolerance.
2121
rtol : float
22-
Desired relative tolerance
22+
Desired relative tolerance.
2323
2424
Attributes
2525
----------

adaptive/learner/balancing_learner.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,32 @@ class BalancingLearner(BaseLearner):
2121
2222
Parameters
2323
----------
24-
learners : sequence of BaseLearner
24+
learners : sequence of `BaseLearner`
2525
The learners from which to choose. These must all have the same type.
2626
cdims : sequence of dicts, or (keys, iterable of values), optional
2727
Constant dimensions; the parameters that label the learners. Used
2828
in `plot`.
2929
Example inputs that all give identical results:
30+
3031
- sequence of dicts:
32+
3133
>>> cdims = [{'A': True, 'B': 0},
3234
... {'A': True, 'B': 1},
3335
... {'A': False, 'B': 0},
3436
... {'A': False, 'B': 1}]`
37+
3538
- tuple with (keys, iterable of values):
39+
3640
>>> cdims = (['A', 'B'], itertools.product([True, False], [0, 1]))
3741
>>> cdims = (['A', 'B'], [(True, 0), (True, 1),
3842
... (False, 0), (False, 1)])
43+
3944
strategy : 'loss_improvements' (default), 'loss', or 'npoints'
40-
The points that the 'BalancingLearner' choses can be either based on:
45+
The points that the `BalancingLearner` choses can be either based on:
4146
the best 'loss_improvements', the smallest total 'loss' of the
4247
child learners, or the number of points per learner, using 'npoints'.
4348
One can dynamically change the strategy while the simulation is
44-
running by changing the 'learner.strategy' attribute.
49+
running by changing the ``learner.strategy`` attribute.
4550
4651
Notes
4752
-----
@@ -50,7 +55,7 @@ class BalancingLearner(BaseLearner):
5055
compared*. For the moment we enforce this restriction by requiring that
5156
all learners are the same type but (depending on the internals of the
5257
learner) it may be that the loss cannot be compared *even between learners
53-
of the same type*. In this case the BalancingLearner will behave in an
58+
of the same type*. In this case the `BalancingLearner` will behave in an
5459
undefined way.
5560
"""
5661

@@ -183,28 +188,34 @@ def plot(self, cdims=None, plotter=None, dynamic=True):
183188
cdims : sequence of dicts, or (keys, iterable of values), optional
184189
Constant dimensions; the parameters that label the learners.
185190
Example inputs that all give identical results:
191+
186192
- sequence of dicts:
193+
187194
>>> cdims = [{'A': True, 'B': 0},
188195
... {'A': True, 'B': 1},
189196
... {'A': False, 'B': 0},
190197
... {'A': False, 'B': 1}]`
198+
191199
- tuple with (keys, iterable of values):
200+
192201
>>> cdims = (['A', 'B'], itertools.product([True, False], [0, 1]))
193202
>>> cdims = (['A', 'B'], [(True, 0), (True, 1),
194203
... (False, 0), (False, 1)])
204+
195205
plotter : callable, optional
196206
A function that takes the learner as a argument and returns a
197-
holoviews object. By default learner.plot() will be called.
207+
holoviews object. By default ``learner.plot()`` will be called.
198208
dynamic : bool, default True
199-
Return a holoviews.DynamicMap if True, else a holoviews.HoloMap.
200-
The DynamicMap is rendered as the sliders change and can therefore
201-
not be exported to html. The HoloMap does not have this problem.
209+
Return a `holoviews.core.DynamicMap` if True, else a
210+
`holoviews.core.HoloMap`. The `~holoviews.core.DynamicMap` is
211+
rendered as the sliders change and can therefore not be exported
212+
to html. The `~holoviews.core.HoloMap` does not have this problem.
202213
203214
Returns
204215
-------
205-
dm : holoviews.DynamicMap object (default) or holoviews.HoloMap object
206-
A DynamicMap (dynamic=True) or HoloMap (dynamic=False) with
207-
sliders that are defined by 'cdims'.
216+
dm : `holoviews.core.DynamicMap` (default) or `holoviews.core.HoloMap`
217+
A `DynamicMap` (dynamic=True) or `HoloMap` (dynamic=False) with
218+
sliders that are defined by `cdims`.
208219
"""
209220
hv = ensure_holoviews()
210221
cdims = cdims or self._cdims_default
@@ -248,13 +259,13 @@ def remove_unfinished(self):
248259
def from_product(cls, f, learner_type, learner_kwargs, combos):
249260
"""Create a `BalancingLearner` with learners of all combinations of
250261
named variables’ values. The `cdims` will be set correctly, so calling
251-
`learner.plot` will be a `holoviews.HoloMap` with the correct labels.
262+
`learner.plot` will be a `holoviews.core.HoloMap` with the correct labels.
252263
253264
Parameters
254265
----------
255266
f : callable
256267
Function to learn, must take arguments provided in in `combos`.
257-
learner_type : BaseLearner
268+
learner_type : `BaseLearner`
258269
The learner that should wrap the function. For example `Learner1D`.
259270
learner_kwargs : dict
260271
Keyword argument for the `learner_type`. For example `dict(bounds=[0, 1])`.

0 commit comments

Comments
 (0)