Skip to content

Commit

Permalink
Update plot.py - Show plots when not running in a notebook (#669)
Browse files Browse the repository at this point in the history
* Update plot.py - Show plots when not running in a notebook

The code works fine when using it in a notebook but the graph does not show when using other IDEs such as Spyder. The lines are added to make sure that when it is not running on a notebook, the graph will be displayed in a browser.

* Update plot.py - Show plots when not running in a notebook (using try and except blocks)

The code works fine when using it in a notebook but the graph does not show when using other IDEs such as Spyder. These lines are added in try and except blocks to make sure that when it is not running on a notebook, the graph will be displayed in a browser.

* Update plot.py - Show plots when not running in a notebook (using try and except blocks)

The code works fine when using it in a notebook but the graph does not show when using other IDEs such as Spyder. These lines are added in try and except blocks to make sure that when it is not running on a notebook, the graph will be displayed in a browser.

* Update Plot.py

remove the trailing whitespace

* Update plot.py

Remove trailing whitespace.

* Update plot.py 

Updated to show the graph when not running as a notebook. Black autoformatted.

* Updates plot.py with black ran locally.

* Updates plot.py- Show plots when not running in a notebook

* Adds the contribution regarding the PR #669

* Update .github/CHANGELOG.md

uses suggested wordings

Co-authored-by: Theodor <theodor.isacsson@gmail.com>

* suggestions applied

* adds the removed spaces again

* make format after adding spaces back

Co-authored-by: Theodor <theodor@xanadu.ai>
Co-authored-by: Hossein Seifoory <hseifoory@nvidia.com>
Co-authored-by: Theodor <theodor.isacsson@gmail.com>
  • Loading branch information
4 people committed Jan 21, 2022
1 parent d01bbd1 commit 2d6e3ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

<h3>Bug fixes</h3>

* It's now possible to show graphs using the plot apps layer when not run in notebooks.
[(#669)](https://github.com/XanaduAI/strawberryfields/pull/669)

* `program.compile` now raises an error if the device specification contains gate parameters but no
circuit layout. Without a layout, the gate parameters cannot be validated against the device
specification.
Expand All @@ -24,7 +27,7 @@

This release contains contributions from (in alphabetical order):

Theodor Isacsson, Jon Schlipf
Theodor Isacsson, Jon Schlipf, Hossein Seifoory

# Release 0.21.0 (current release)

Expand Down
9 changes: 9 additions & 0 deletions strawberryfields/apps/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,18 @@ def graph(g: nx.Graph, s: Optional[list] = None, plot_size: Tuple = (500, 500)):
"""
try:
import plotly.graph_objects as go
import plotly.io as pio
except ImportError:
raise ImportError(plotly_error)

try:
in_notebook = get_ipython().__class__.__name__ == "ZMQInteractiveShell"
except NameError:
in_notebook = False

if not in_notebook:
pio.renderers.default = "browser"

l = nx.kamada_kawai_layout(g)

g_nodes = go.Scatter(
Expand Down

0 comments on commit 2d6e3ea

Please sign in to comment.