Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of Bloch sphere output #1091

Merged
merged 9 commits into from
Oct 12, 2018
Merged

Better handling of Bloch sphere output #1091

merged 9 commits into from
Oct 12, 2018

Conversation

nonhermitian
Copy link
Contributor

Summary

This fixes an issue where the Bloch sphere could only be output once if called directly. In addition, it cleans up the internals for dealing with user passed fig and axes. Note that none of this is actually directly used in qiskit, but some users are trying.

Details and comments

fig = plt.figure(figsize=(15,7))
ax = fig.add_subplot(1, 2, 1, projection='3d')
B1 = Bloch(fig=fig, axes=ax)
B1.add_vectors([0,0,1])
B1.render('Qubit #1')
ax2 = fig.add_subplot(1, 2, 2, projection='3d')
B2 = Bloch(fig=fig, axes=ax2)
B2.add_vectors([0,1,0])
B2.render()

bloch

@mtreinish
Copy link
Member

@nonhermitian did you mean to include those 2 jupyter notebooks in the PR too, or just the changes to bloch.py?

@nonhermitian
Copy link
Contributor Author

Opps

@nonhermitian
Copy link
Contributor Author

Good find.

@jaygambetta
Copy link
Member

can we call it _bloch

@jaygambetta jaygambetta merged commit fa74362 into Qiskit:master Oct 12, 2018
@jaygambetta jaygambetta moved this from To do to Done in Visualization and Juypter Tools Oct 12, 2018
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* 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
clarebirch added a commit to clarebirch/qiskit-terra that referenced this pull request Aug 15, 2020
Updated operator.py to include to_gate, with error (not warning) if the 'gate' is non-unitary
hodgestar added a commit to hodgestar/qutip that referenced this pull request Jul 22, 2021
Bloch sphere.

Previously .render(...) took fig and axes arguments and overwrote
self.fig and self.axes if the arguments were None. The actual values of
the arguments were completely discarded (!!). In addition, not supplying
a value for fig and axes would overwrite the values passed to the
constructor as Bloch(..., fig=fig, axes=axes).

The new behaviour is as follows:

* If an external figure is passed to the constructor it is retained.

* If no figure is supplied, .render() will create a figure if one
  has not been created yet, or if the figure has been closed, will
  recreate it.

* .render() will always call self.fig.canvas.update() to ensure that
  any existing figure that is already shown will be updated.

Previously it was possible to cause .render() to raise obscure
exceptions by, e.g., calling .render(), closing the figure, calling
.render() again. See, for example,
qutip#1616.

The external figure tracking was backported from Qiskit's copy of
Bloch and was inspired by PR
Qiskit/qiskit#1091.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Development

Successfully merging this pull request may close these issues.

None yet

3 participants