Skip to content

Commit c602a86

Browse files
committed
Merge remote-tracking branch 'origin/stable-0.8'
2 parents 033004c + c821c49 commit c602a86

File tree

8 files changed

+30
-12
lines changed

8 files changed

+30
-12
lines changed

adaptive/learner/balancing_learner.py

+3
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ def plot_function(*args):
291291

292292
dm = hv.DynamicMap(plot_function, kdims=list(d.keys()))
293293
dm = dm.redim.values(**d)
294+
dm.cache_size = 1
294295

295296
if dynamic:
297+
# XXX: change when https://github.com/pyviz/holoviews/issues/3637
298+
# is fixed.
296299
return dm.map(lambda obj: obj.opts(framewise=True), hv.Element)
297300
else:
298301
# XXX: change when https://github.com/ioam/holoviews/issues/3085

adaptive/learner/learner1D.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,11 @@ def plot(self):
590590
Plot of the evaluated data.
591591
"""
592592
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))
597597
else:
598-
xs, ys = zip(*sorted(self.data.items()))
599598
p = hv.Path((xs, ys)) * hv.Scatter([])
600599

601600
# Plot with 5% empty margins such that the boundary points are visible

adaptive/notebook_integration.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None, normalize=T
9696
9797
Parameters
9898
----------
99-
runner : `Runner`
99+
runner : `~adaptive.Runner`
100100
plotter : function
101101
A function that takes the learner as a argument and returns a
102102
holoviews object. By default ``learner.plot()`` will be called.
@@ -136,6 +136,7 @@ def plot_generator():
136136

137137
streams = [hv.streams.Stream.define("Next")()]
138138
dm = hv.DynamicMap(plot_generator(), streams=streams)
139+
dm.cache_size = 1
139140

140141
if normalize:
141142
# XXX: change when https://github.com/pyviz/holoviews/issues/3637

adaptive/runner.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,12 @@ def cancel(self):
558558
"""
559559
self.task.cancel()
560560

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):
562562
"""Live plotting of the learner's data.
563563
564564
Parameters
565565
----------
566-
runner : `Runner`
566+
runner : `~adaptive.Runner`
567567
plotter : function
568568
A function that takes the learner as a argument and returns a
569569
holoviews object. By default ``learner.plot()`` will be called.
@@ -573,6 +573,8 @@ def live_plot(self, *, plotter=None, update_interval=2, name=None):
573573
Name for the `live_plot` task in `adaptive.active_plotting_tasks`.
574574
By default the name is None and if another task with the same name
575575
already exists that other `live_plot` is canceled.
576+
normalize : bool
577+
Normalize (scale to fit) the frame upon each update.
576578
577579
Returns
578580
-------

adaptive/utils.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from contextlib import contextmanager
88
from itertools import product
99

10+
from atomicwrites import AtomicWriter
11+
1012

1113
def named_product(**items):
1214
names = items.keys()
@@ -44,9 +46,13 @@ def save(fname, data, compress=True):
4446
dirname = os.path.dirname(fname)
4547
if dirname:
4648
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)
5056

5157

5258
def load(fname, compress=True):

docs/environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
- plotly=3.9.0
1414
- ipywidgets=7.4.2
1515
# - jupyter_sphinx=0.2.1
16+
- atomicwrites=1.3.0
1617
- pip:
1718
- git+https://github.com/jbweston/jupyter-sphinx.git@feature/disable-stderr # XXX: removed when merged in
1819
- sphinx_fontawesome==0.0.6

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dependencies:
1616
- ipywidgets
1717
- scikit-optimize
1818
- plotly
19+
- atomicwrites

setup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ def get_version_and_cmdclass(package_name):
2424
version, cmdclass = get_version_and_cmdclass("adaptive")
2525

2626

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+
]
2833

2934
extras_require = {
3035
"notebook": [

0 commit comments

Comments
 (0)