Skip to content

Commit

Permalink
Better handling of Bloch sphere output (#1091)
Browse files Browse the repository at this point in the history
* Fix parallezation in transpile.compile

* Revert "Fix parallezation in transpile.compile"

This reverts commit 98e78d0.

* better handling of bloch sphere output

* remove

* remove

* move to _bloch

* fix call to make_sphere
  • Loading branch information
nonhermitian authored and jaygambetta committed Oct 12, 2018
1 parent 975b376 commit fa74362
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ def __init__(self, fig=None, axes=None, view=None, figsize=None,
background=False):

# Figure and axes
self._ext_fig = False
if fig is not None:
self._ext_fig = True
self.fig = fig
self._ext_axes = False
if axes is not None:
self._ext_axes = True
self.axes = axes
# Background axes, default = False
self.background = background
Expand Down Expand Up @@ -368,9 +374,9 @@ def make_sphere(self):
"""
Plots Bloch sphere and data sets.
"""
self.render(self.fig, self.axes)
self.render()

def render(self, fig=None, axes=None, title=''):
def render(self, title=''):
"""
Render the Bloch sphere and its data sets in on given figure and axes.
"""
Expand All @@ -380,10 +386,10 @@ def render(self, fig=None, axes=None, title=''):
self._rendered = True

# Figure instance for Bloch sphere plot
if not fig:
if not self._ext_fig:
self.fig = plt.figure(figsize=self.figsize)

if not axes:
if not self._ext_axes:
self.axes = Axes3D(self.fig, azim=self.view[0], elev=self.view[1])

if self.background:
Expand Down Expand Up @@ -580,7 +586,7 @@ def show(self, title=''):
"""
Display Bloch sphere and corresponding data sets.
"""
self.render(self.fig, self.axes, title=title)
self.render(title=title)
if self.fig:
plt.show(self.fig)

Expand All @@ -597,7 +603,7 @@ def save(self, name=None, output='png', dirc=None):
Directory for output images. Defaults to current working directory.
"""

self.render(self.fig, self.axes)
self.render()
if dirc:
if not os.path.isdir(os.getcwd() + "/" + str(dirc)):
os.makedirs(os.getcwd() + "/" + str(dirc))
Expand Down
2 changes: 1 addition & 1 deletion qiskit/tools/visualization/_state_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np
from qiskit.tools.qi.pauli import pauli_group, pauli_singles
from qiskit.tools.visualization import VisualizationError
from qiskit.tools.visualization.bloch import Bloch
from qiskit.tools.visualization._bloch import Bloch


class Arrow3D(FancyArrowPatch):
Expand Down

0 comments on commit fa74362

Please sign in to comment.