... | ... |
@@ -291,8 +291,11 @@ class BalancingLearner(BaseLearner): |
291 | 291 |
|
292 | 292 |
dm = hv.DynamicMap(plot_function, kdims=list(d.keys())) |
293 | 293 |
dm = dm.redim.values(**d) |
294 |
+ dm.cache_size = 1 |
|
294 | 295 |
|
295 | 296 |
if dynamic: |
297 |
+ # XXX: change when https://github.com/pyviz/holoviews/issues/3637 |
|
298 |
+ # is fixed. |
|
296 | 299 |
return dm.map(lambda obj: obj.opts(framewise=True), hv.Element) |
297 | 300 |
else: |
298 | 301 |
# XXX: change when https://github.com/ioam/holoviews/issues/3085 |
... | ... |
@@ -590,12 +590,11 @@ class Learner1D(BaseLearner): |
590 | 590 |
Plot of the evaluated data. |
591 | 591 |
""" |
592 | 592 |
hv = ensure_holoviews() |
593 |
- if not self.data: |
|
594 |
- p = hv.Scatter([]) * hv.Path([]) |
|
595 |
- elif not self.vdim > 1: |
|
596 |
- p = hv.Scatter(self.data) * hv.Path([]) |
|
593 |
+ |
|
594 |
+ xs, ys = zip(*sorted(self.data.items())) if self.data else ([], []) |
|
595 |
+ if self.vdim == 1: |
|
596 |
+ p = hv.Path([]) * hv.Scatter((xs, ys)) |
|
597 | 597 |
else: |
598 |
- xs, ys = zip(*sorted(self.data.items())) |
|
599 | 598 |
p = hv.Path((xs, ys)) * hv.Scatter([]) |
600 | 599 |
|
601 | 600 |
# Plot with 5% empty margins such that the boundary points are visible |
... | ... |
@@ -96,7 +96,7 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None, normalize=T |
96 | 96 |
|
97 | 97 |
Parameters |
98 | 98 |
---------- |
99 |
- runner : `Runner` |
|
99 |
+ runner : `~adaptive.Runner` |
|
100 | 100 |
plotter : function |
101 | 101 |
A function that takes the learner as a argument and returns a |
102 | 102 |
holoviews object. By default ``learner.plot()`` will be called. |
... | ... |
@@ -136,6 +136,7 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None, normalize=T |
136 | 136 |
|
137 | 137 |
streams = [hv.streams.Stream.define("Next")()] |
138 | 138 |
dm = hv.DynamicMap(plot_generator(), streams=streams) |
139 |
+ dm.cache_size = 1 |
|
139 | 140 |
|
140 | 141 |
if normalize: |
141 | 142 |
# XXX: change when https://github.com/pyviz/holoviews/issues/3637 |
... | ... |
@@ -558,12 +558,12 @@ class AsyncRunner(BaseRunner): |
558 | 558 |
""" |
559 | 559 |
self.task.cancel() |
560 | 560 |
|
561 |
- def live_plot(self, *, plotter=None, update_interval=2, name=None): |
|
561 |
+ def live_plot(self, *, plotter=None, update_interval=2, name=None, normalize=True): |
|
562 | 562 |
"""Live plotting of the learner's data. |
563 | 563 |
|
564 | 564 |
Parameters |
565 | 565 |
---------- |
566 |
- runner : `Runner` |
|
566 |
+ runner : `~adaptive.Runner` |
|
567 | 567 |
plotter : function |
568 | 568 |
A function that takes the learner as a argument and returns a |
569 | 569 |
holoviews object. By default ``learner.plot()`` will be called. |
... | ... |
@@ -573,6 +573,8 @@ class AsyncRunner(BaseRunner): |
573 | 573 |
Name for the `live_plot` task in `adaptive.active_plotting_tasks`. |
574 | 574 |
By default the name is None and if another task with the same name |
575 | 575 |
already exists that other `live_plot` is canceled. |
576 |
+ normalize : bool |
|
577 |
+ Normalize (scale to fit) the frame upon each update. |
|
576 | 578 |
|
577 | 579 |
Returns |
578 | 580 |
------- |
... | ... |
@@ -7,6 +7,8 @@ import pickle |
7 | 7 |
from contextlib import contextmanager |
8 | 8 |
from itertools import product |
9 | 9 |
|
10 |
+from atomicwrites import AtomicWriter |
|
11 |
+ |
|
10 | 12 |
|
11 | 13 |
def named_product(**items): |
12 | 14 |
names = items.keys() |
... | ... |
@@ -44,9 +46,13 @@ def save(fname, data, compress=True): |
44 | 46 |
dirname = os.path.dirname(fname) |
45 | 47 |
if dirname: |
46 | 48 |
os.makedirs(dirname, exist_ok=True) |
47 |
- _open = gzip.open if compress else open |
|
48 |
- with _open(fname, "wb") as f: |
|
49 |
- pickle.dump(data, f, protocol=pickle.HIGHEST_PROTOCOL) |
|
49 |
+ |
|
50 |
+ blob = pickle.dumps(data, protocol=pickle.HIGHEST_PROTOCOL) |
|
51 |
+ if compress: |
|
52 |
+ blob = gzip.compress(blob) |
|
53 |
+ |
|
54 |
+ with AtomicWriter(fname, "wb", overwrite=True).open() as f: |
|
55 |
+ f.write(blob) |
|
50 | 56 |
|
51 | 57 |
|
52 | 58 |
def load(fname, compress=True): |
... | ... |
@@ -13,6 +13,7 @@ dependencies: |
13 | 13 |
- plotly=3.9.0 |
14 | 14 |
- ipywidgets=7.4.2 |
15 | 15 |
# - jupyter_sphinx=0.2.1 |
16 |
+ - atomicwrites=1.3.0 |
|
16 | 17 |
- pip: |
17 | 18 |
- git+https://github.com/jbweston/jupyter-sphinx.git@feature/disable-stderr # XXX: removed when merged in |
18 | 19 |
- sphinx_fontawesome==0.0.6 |
... | ... |
@@ -24,7 +24,12 @@ def get_version_and_cmdclass(package_name): |
24 | 24 |
version, cmdclass = get_version_and_cmdclass("adaptive") |
25 | 25 |
|
26 | 26 |
|
27 |
-install_requires = ["scipy", "sortedcollections >= 1.1", "sortedcontainers >= 2.0"] |
|
27 |
+install_requires = [ |
|
28 |
+ "scipy", |
|
29 |
+ "sortedcollections >= 1.1", |
|
30 |
+ "sortedcontainers >= 2.0", |
|
31 |
+ "atomicwrites", |
|
32 |
+] |
|
28 | 33 |
|
29 | 34 |
extras_require = { |
30 | 35 |
"notebook": [ |