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

Update docs to use the matplotlib plot directive instead of jupyter execute #363

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.extlinks',
'jupyter_sphinx',
'sphinx_autodoc_typehints',
'reno.sphinxext',
'sphinx.ext.intersphinx',
'nbsphinx',
'sphinxcontrib.bibtex',
"qiskit_sphinx_theme",
"matplotlib.sphinxext.plot_directive",
]
templates_path = ["_templates"]

Expand All @@ -61,6 +61,10 @@

html_context = {"version_list": ["0.4"]}

html_theme_options = {
"sidebar_qiskit_ecosystem_member": True,
}

# autodoc/autosummary options
autosummary_generate = True
autosummary_generate_overwrite = False
Expand Down
25 changes: 17 additions & 8 deletions docs/tutorials/Lindblad_dynamics_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ syntax of ``Pauli`` classes to indicate a qubit number, as below.
Below, we first set the number of qubits :math:`N` to be simulated, and then prepare and store the
single-qubit Pauli operators that will be used in the rest of this tutorial.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

import numpy as np
from qiskit.quantum_info import Operator, Pauli
Expand Down Expand Up @@ -100,7 +102,9 @@ two-qubit terms. Since there are no time-dependent terms, and we do not plan to
derivatives of parameters, we do not use the :class:`Signal` class in this tutorial. See the other
tutorials for various generalizations of this approach supported with ``qiskit-dynamics``.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

from qiskit_dynamics import Solver, Signal

Expand Down Expand Up @@ -140,7 +144,9 @@ tutorials for various generalizations of this approach supported with ``qiskit-d
We now define the initial state for the simulation, the time span to simulate for, and the
intermediate times for which the solution is requested.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

from qiskit.quantum_info import DensityMatrix

Expand Down Expand Up @@ -175,7 +181,9 @@ invariant as well. Hence the mean Bloch vector should be equal to any qubit’s
observing that this equality holds is a simple and useful verification of the numerical solution
that will be added in the next section.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

n_times = len(sol.y)
x_data = np.zeros((N, n_times))
Expand Down Expand Up @@ -218,11 +226,12 @@ tilt along :math:`+x`, while for :math:`J=3` it will significantly shorten (the
a mixed state), becoming tilted along :math:`-y`. This complex dependence of the Bloch vector on the
parameters can be systematically analyzed - we encourage you to try it!

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

from qiskit.visualization import plot_bloch_vector
import matplotlib.pyplot as plt
%matplotlib inline

fontsize = 16

Expand All @@ -235,8 +244,8 @@ parameters can be systematically analyzed - we encourage you to try it!
ax.set_xlabel('$t$', fontsize = fontsize)
ax.set_title('Mean Bloch vector vs. $t$', fontsize = fontsize)

display(plot_bloch_vector([x_mean[-1], y_mean[-1], z_mean[-1]],
f'Mean Bloch vector at $t = {t_eval[-1]}$'))
plot_bloch_vector([x_mean[-1], y_mean[-1], z_mean[-1]],
f'Mean Bloch vector at $t = {t_eval[-1]}$')

if N > 1 and ((abs(x_mean[-1]) > 1e-5 and abs(x_data[0, -1] / x_mean[-1] - 1) > 1e-5 or
(abs(z_mean[-1]) > 1e-5 and abs(z_data[1, -1] / z_mean[-1] - 1) > 1e-5))):
Expand Down
21 changes: 14 additions & 7 deletions docs/tutorials/Rabi_oscillations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ then setup the :class:`.Solver` class instance that stores and manipulates the m
using matrices and :class:`.Signal` instances. For the time-independent :math:`z` term we set the
signal to a constant, while for the trasverse driving term we setup a harmonic signal.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

import numpy as np
from qiskit.quantum_info import Operator
Expand All @@ -62,7 +64,9 @@ signal to a constant, while for the trasverse driving term we setup a harmonic s
We now define the initial state for the simulation, the time span to simulate for, and the
intermediate times for which the solution is requested, and solve the evolution.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

from qiskit.quantum_info.states import Statevector
from qiskit.quantum_info import DensityMatrix
Expand Down Expand Up @@ -96,11 +100,12 @@ increases and decreases). This mechanism of Rabi oscillations is the basis for t
gates used to manipulate quantum devices - in particular this is a realization of the :math:`X`
gate.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

from qiskit.visualization import plot_bloch_vector
import matplotlib.pyplot as plt
%matplotlib inline

fontsize = 16

Expand All @@ -125,8 +130,8 @@ gate.
ax.set_title('Bloch vector vs. $t$', fontsize = fontsize)
plt.show()

display(plot_bloch_vector([x_data[-1], y_data[-1], z_data[-1]],
f'Bloch vector at $t = {t_eval[-1]}$'))
plot_bloch_vector([x_data[-1], y_data[-1], z_data[-1]],
f'Bloch vector at $t = {t_eval[-1]}$')

plot_qubit_dynamics(sol, t_eval, X, Y, Z)

Expand Down Expand Up @@ -161,7 +166,9 @@ since in ``qiskit`` and in ``qiskit-dynamics`` the syntax of many functions is i
state vectors and density matrices. The shrinking of the qubit’s state within the Bloch sphere due
to the incoherent evolution can be clearly seen in the plots below.

.. jupyter-execute::
.. plot::
:context: close-figs
:include-source:

Gamma_1 = .8
Gamma_2 = .2
Expand Down
Loading
Loading