Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Quantum Tinkerer
adaptive
Commits
b563e096
Commit
b563e096
authored
6 years ago
by
Bas Nijholt
Browse files
Options
Downloads
Patches
Plain Diff
improve 'notebook_extension' and add 'plotly' as a dependency
parent
5e3edf47
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
adaptive/notebook_integration.py
+43
-13
43 additions, 13 deletions
adaptive/notebook_integration.py
docs/environment.yml
+1
-0
1 addition, 0 deletions
docs/environment.yml
environment.yml
+1
-0
1 addition, 0 deletions
environment.yml
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
46 additions
and
13 deletions
adaptive/notebook_integration.py
+
43
−
13
View file @
b563e096
...
...
@@ -7,28 +7,42 @@ import warnings
_async_enabled
=
False
_plotting_enabled
=
False
_holoviews_enabled
=
False
_ipywidgets_enabled
=
False
_plotly_enabled
=
False
def
notebook_extension
():
"""
Enable ipywidgets, holoviews, and asyncio notebook integration.
"""
if
not
in_ipynb
():
raise
RuntimeError
(
'"
adaptive.notebook_extension()
"
may only be run
'
'
from a Jupyter notebook.
'
)
global
_plotting_enabled
_plotting_enabled
=
False
global
_async_enabled
,
_holoviews_enabled
,
_ipywidgets_enabled
# Load holoviews
try
:
if
not
_holoviews_enabled
:
import
holoviews
holoviews
.
notebook_extension
(
'
bokeh
'
,
logo
=
False
)
_holoviews_enabled
=
True
except
ModuleNotFoundError
:
warnings
.
warn
(
"
holoviews is not installed; plotting
"
"
is disabled.
"
,
RuntimeWarning
)
# Load ipywidgets
try
:
import
ipywidgets
import
holoviews
holoviews
.
notebook_extension
(
'
bokeh
'
,
logo
=
False
)
_plotting_enabled
=
True
if
not
_ipywidgets_enabled
:
import
ipywidgets
_ipywidgets_enabled
=
True
except
ModuleNotFoundError
:
warnings
.
warn
(
"
holoviews and (or)
ipywidgets
are
not installed;
plotting
"
warnings
.
warn
(
"
ipywidgets
is
not installed;
live_info
"
"
is disabled.
"
,
RuntimeWarning
)
global
_async_enabled
get_ipython
().
magic
(
'
gui asyncio
'
)
_async_enabled
=
True
# Enable asyncio integration
if
not
_async_enabled
:
get_ipython
().
magic
(
'
gui asyncio
'
)
_async_enabled
=
True
def
ensure_holoviews
():
...
...
@@ -38,6 +52,22 @@ def ensure_holoviews():
raise
RuntimeError
(
'
holoviews is not installed; plotting is disabled.
'
)
def
ensure_plotly
():
global
_plotly_enabled
try
:
import
plotly
if
not
_plotly_enabled
:
import
plotly.graph_objs
import
plotly.figure_factory
import
plotly.offline
# This injects javascript and should happen only once
plotly
.
offline
.
init_notebook_mode
()
_plotly_enabled
=
True
return
plotly
except
ModuleNotFoundError
:
raise
RuntimeError
(
'
plotly is not installed; plotting is disabled.
'
)
def
in_ipynb
():
try
:
# If we are running in IPython, then `get_ipython()` is always a global
...
...
@@ -72,7 +102,7 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None):
dm : `holoviews.core.DynamicMap`
The plot that automatically updates every `update_interval`.
"""
if
not
_
plotting
_enabled
:
if
not
_
holoviews
_enabled
:
raise
RuntimeError
(
"
Live plotting is not enabled; did you run
"
"'
adaptive.notebook_extension()
'
?
"
)
...
...
@@ -126,7 +156,7 @@ def live_info(runner, *, update_interval=0.5):
Returns an interactive ipywidget that can be
visualized in a Jupyter notebook.
"""
if
not
_
plotting
_enabled
:
if
not
_
holoviews
_enabled
:
raise
RuntimeError
(
"
Live plotting is not enabled; did you run
"
"'
adaptive.notebook_extension()
'
?
"
)
...
...
This diff is collapsed.
Click to expand it.
docs/environment.yml
+
1
−
0
View file @
b563e096
...
...
@@ -10,6 +10,7 @@ dependencies:
-
scipy
-
holoviews
-
bokeh
-
plotly
-
ipyparallel
-
distributed
-
ipykernel>=4.8*
...
...
This diff is collapsed.
Click to expand it.
environment.yml
+
1
−
0
View file @
b563e096
...
...
@@ -14,3 +14,4 @@ dependencies:
-
jupyter_client>=5.2.2
-
ipywidgets
-
scikit-optimize
-
plotly
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
b563e096
...
...
@@ -38,6 +38,7 @@ extras_require = {
'
ipywidgets
'
,
'
bokeh
'
,
'
matplotlib
'
,
'
plotly
'
,
],
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment