Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/notebook-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ name: Test notebooks
on:
pull_request:
paths:
- "tutorials/**/*.ipynb"
- "docs/**/*.ipynb"
- "!docs/api/**/*"
workflow_dispatch:
Expand All @@ -28,7 +29,7 @@ jobs:
id: all-changed-files
uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1
with:
files: docs/**/*.ipynb
files: "{tutorials,docs}/**/*.ipynb"
separator: "\n"

- name: Check for notebooks that require Linux
Expand Down
1 change: 1 addition & 0 deletions scripts/nb-tester/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ ipykernel~=6.29.2
qiskit[all]~=1.0
qiskit-aer~=0.14.0.1
qiskit-ibm-runtime~=0.22.0
qiskit-ibm-provider~=0.10.0
squeaky==0.7.0
9 changes: 8 additions & 1 deletion scripts/nb-tester/test-notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@
from qiskit_ibm_runtime import QiskitRuntimeService
from squeaky import clean_notebook

NOTEBOOKS_GLOB = "docs/**/*.ipynb"
NOTEBOOKS_GLOB = "{tutorials,docs}/**/*.ipynb"
NOTEBOOKS_EXCLUDE = [
"docs/api/**",
"**/.ipynb_checkpoints/**",
]
NOTEBOOKS_THAT_SUBMIT_JOBS = [
"docs/start/hello-world.ipynb",
"docs/analyze/saving-and-retrieving.ipynb",
"tutorials/build-repitition-codes/notebook.ipynb",
"tutorials/chsh-inequality/notebook.ipynb",
"tutorials/grovers-algorithm/notebook.ipynb",
"tutorials/quantum-approximate-optimization-algorithm/notebook.ipynb",
"tutorials/repeat-until-success/notebook.ipynb",
"tutorials/submitting-transpiled-circuits/notebook.ipynb",
"tutorials/variational-quantum-eigensolver/notebook.ipynb",
]


Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setenv = PYDEVD_DISABLE_FILE_VALIDATION=1
commands = python scripts/nb-tester/test-notebook.py {posargs}

[testenv:lint]
commands = squeaky --check --no-advice {posargs:docs/}
commands = squeaky --check --no-advice {posargs:docs tutorials}

[testenv:fix]
commands = squeaky {posargs:docs/}
commands = squeaky {posargs:docs tutorials}
22 changes: 11 additions & 11 deletions tutorials/build-repitition-codes/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"\n",
"## Background\n",
"\n",
"To enable real-time quantum error correction (QEC), we require the capability to dynamically control quantum program flow during execution so that quantum gates may be conditioned on measurement results. In this tutorial, we will run the bit-flip code, which is a very simple form of QEC. We will demonstrate a dynamic quantum circuit that can protect an encoded qubit from a single bit-flip error, and then evaluate the performance of the bit-flip code. \n",
"To enable real-time quantum error correction (QEC), we require the capability to dynamically control quantum program flow during execution so that quantum gates may be conditioned on measurement results. In this tutorial, we will run the bit-flip code, which is a very simple form of QEC. We will demonstrate a dynamic quantum circuit that can protect an encoded qubit from a single bit-flip error, and then evaluate the performance of the bit-flip code.\n",
"\n",
"We can exploit additional ancilla qubits and entanglement to measure what are known as *stabilizers* that do not transform our encoded quantum information, while still informing us of some classes of errors that may have occurred. A quantum stabilizer code encodes $k$ logical qubits into $n$ physical qubits. Stabilizer codes critically focus on correcting a discrete error set with support from the Pauli group $\\Pi^n$. Assume the set of possible errors are $ \\epsilon \\subset \\Pi^n$. For example, in a bit-flip code with three qubits encoding the quantum state, we will have $\\epsilon = \\{IIX, IXI, XII\\}$. We can measure the stabilizers and observing their eigenvalues to dete"
]
Expand Down Expand Up @@ -115,14 +115,14 @@
"\n",
"def measure_syndrome_bit(circuit, qreg_data, qreg_measure, creg_measure):\n",
" \"\"\"\n",
" Measure the syndrome by measuring the parity. \n",
" Measure the syndrome by measuring the parity.\n",
" We reset our ancilla qubits after measuring the stabilizer\n",
" so we can reuse them for repeated stabilizer measurements. \n",
" Because we have already observed the state of the qubit, \n",
" we can write the conditional reset protocol directly to \n",
" avoid another round of qubit measurement if we used \n",
" so we can reuse them for repeated stabilizer measurements.\n",
" Because we have already observed the state of the qubit,\n",
" we can write the conditional reset protocol directly to\n",
" avoid another round of qubit measurement if we used\n",
" the `reset` instruction.\n",
" \"\"\" \n",
" \"\"\"\n",
" circuit.cx(qreg_data[0], qreg_measure[0])\n",
" circuit.cx(qreg_data[1], qreg_measure[0])\n",
" circuit.cx(qreg_data[0], qreg_measure[1])\n",
Expand Down Expand Up @@ -179,10 +179,10 @@
" circuit = initialize_qubits(circuit)\n",
" circuit = encode_bit_flip(circuit, state_data, ancillas_data)\n",
" circuit = measure_syndrome_bit(circuit, qreg_data, qreg_measure, creg_syndrome)\n",
" \n",
"\n",
" if apply_correction:\n",
" circuit = apply_correction_bit(circuit, qreg_data, creg_syndrome)\n",
" \n",
"\n",
" circuit = apply_final_readout(circuit, qreg_data, creg_data)\n",
" return circuit\n",
"\n",
Expand Down Expand Up @@ -423,7 +423,7 @@
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -437,7 +437,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3"
},
"vscode": {
"interpreter": {
Expand Down
14 changes: 7 additions & 7 deletions tutorials/chsh-inequality/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"id": "fb089249",
"metadata": {},
"source": [
"In this tutorial, you will run an experiment on a quantum computer to demonstrate the violation of the CHSH inequality with the Estimator primitive. \n",
"In this tutorial, you will run an experiment on a quantum computer to demonstrate the violation of the CHSH inequality with the Estimator primitive.\n",
"\n",
"The CHSH inequality, named after the authors Clauser, Horne, Shimony, and Holt, is used to experimentally prove Bell's theorem (1969). This theorem asserts that local hidden variable theories cannot account for some consequences of entanglement in quantum mechanics. The violation of the CHSH inequality is used to show that quantum mechanics is incompatible with local hidden-variable theories. This is an important experiment for understanding the foundation of quantum mechanics. \n",
"The CHSH inequality, named after the authors Clauser, Horne, Shimony, and Holt, is used to experimentally prove Bell's theorem (1969). This theorem asserts that local hidden variable theories cannot account for some consequences of entanglement in quantum mechanics. The violation of the CHSH inequality is used to show that quantum mechanics is incompatible with local hidden-variable theories. This is an important experiment for understanding the foundation of quantum mechanics.\n",
"\n",
"The 2022 Nobel Prize for Physics was awarded to Alain Aspect, John Clauser and Anton Zeilinger in part for their pioneering work in quantum information science, and in particular, for their experiments with entangled photons demonstrating violation of Bell’s inequalities."
]
Expand Down Expand Up @@ -152,7 +152,7 @@
"id": "1ab329f2",
"metadata": {},
"source": [
"### Create a parameterized CHSH circuit \n",
"### Create a parameterized CHSH circuit\n",
"\n",
"First, we write the circuit with the parameter $\\theta$, which we call `theta`. The [`Estimator` primitive](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.EstimatorV2) can enormously simplify circuit building and output analysis by directly providing expectation values of observables. Many problems of interest, especially for near-term applications on noisy systems, can be formulated in terms of expectation values. `Estimator` (V2) primitive can automatically change measurement basis based on the supplied observable."
]
Expand Down Expand Up @@ -218,7 +218,7 @@
"id": "6e559aed",
"metadata": {},
"source": [
"### Observables \n",
"### Observables\n",
"\n",
"Now we need observables from which to compute the expectation values. In our case we are looking at orthogonal bases for each qubit, letting the parameterized $Y-$ rotation for the first qubit sweep the measurement basis nearly continuously with respect to the second qubit basis. We will therefore choose the observables $ZZ$, $ZX$, $XZ$, and $XX$."
]
Expand Down Expand Up @@ -336,7 +336,7 @@
"id": "2d8ad9e1",
"metadata": {},
"source": [
"We can create a [Qiskit Runtime `Estimator`](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.EstimatorV2) primitive to compute our expectation values. The `EstimatorV2.run()` method takes an iterable of `primitive unified blocs (PUBs)`. Each PUB is an iterable in the format `(circuit, observables, parameter_values: Optional, precision: Optional)`. "
"We can create a [Qiskit Runtime `Estimator`](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.EstimatorV2) primitive to compute our expectation values. The `EstimatorV2.run()` method takes an iterable of `primitive unified blocs (PUBs)`. Each PUB is an iterable in the format `(circuit, observables, parameter_values: Optional, precision: Optional)`."
]
},
{
Expand Down Expand Up @@ -487,7 +487,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -501,7 +501,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3"
},
"vscode": {
"interpreter": {
Expand Down
31 changes: 26 additions & 5 deletions tutorials/explore-composer/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "b27d7770-0fd4-4173-9b52-99a0898634db",
"metadata": {},
"source": [
"## What is it?\n",
Expand All @@ -27,6 +28,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "477a3b86-e25f-4966-ae9f-0831482d202f",
"metadata": {},
"source": [
"## Tour of the interface\n",
Expand Down Expand Up @@ -65,12 +67,13 @@
"\n",
"11. **Visualizations** - Visualizations characterize your circuit as you build it. They use a single-shot statevector simulator, which is different from the system specified in the Setup and run settings. Note that the visualizations ignore any measurement operations you add. Sign in and click **Setup and run** to get results from the specified backend instead.\n",
"\n",
" To learn about the visualizations, see [Visualizations](#visualizations).\n"
" To learn about the visualizations, see [Visualizations](#visualizations)."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "e9207850-523d-410b-9df4-27cd6b320e3e",
"metadata": {},
"source": [
"## Build, edit, and inspect quantum circuits\n",
Expand Down Expand Up @@ -191,6 +194,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "d106f427-c7f6-4c7e-9f5f-b7dfcca515cb",
"metadata": {},
"source": [
"### 3. Build your circuit with OpenQASM code\n",
Expand Down Expand Up @@ -230,6 +234,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "8b6551de-ad4e-4b95-bb8a-56b43575764e",
"metadata": {},
"source": [
"#### Create a custom operation in OpenQASM\n",
Expand Down Expand Up @@ -284,6 +289,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "d4ed95f2-15ad-4e9a-add3-57e227270a5d",
"metadata": {},
"source": [
"## Run circuits and view results\n",
Expand Down Expand Up @@ -321,6 +327,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "b37d5709-a82a-4453-9cba-6d3cd2b475aa",
"metadata": {},
"source": [
"## Visualizations\n",
Expand Down Expand Up @@ -441,12 +448,13 @@
"\n",
"The statevector at the terminus of the above circuit. The color wheel maps phase angle to color. The output state is expressed as a list of complex numbers.\n",
"\n",
"The circuit puts the two qubits into the state $|\\psi\\rangle = (|00\\rangle + |01\\rangle+ |10\\rangle-|11\\rangle) / 2$. The computational basis states are $|00\\rangle$, $|10\\rangle$, $|01\\rangle$, and $|11\\rangle$. The magnitudes of the amplitudes are $1/2$, and the quantum phases with respect to the ground state are $0$ for $|01\\rangle$ and $|10\\rangle$, and $\\pi$ for $|11\\rangle$.\n"
"The circuit puts the two qubits into the state $|\\psi\\rangle = (|00\\rangle + |01\\rangle+ |10\\rangle-|11\\rangle) / 2$. The computational basis states are $|00\\rangle$, $|10\\rangle$, $|01\\rangle$, and $|11\\rangle$. The magnitudes of the amplitudes are $1/2$, and the quantum phases with respect to the ground state are $0$ for $|01\\rangle$ and $|10\\rangle$, and $\\pi$ for $|11\\rangle$."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "9c47c5d8-7447-4cc3-b5bb-09cd2f1689bc",
"metadata": {},
"source": [
"## Composer operations glossary\n",
Expand Down Expand Up @@ -744,10 +752,23 @@
}
],
"metadata": {
"language_info": {
"name": "python"
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"orig_nbformat": 4
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3"
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
6 changes: 3 additions & 3 deletions tutorials/grovers-algorithm/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"## Background\n",
"\n",
"Amplitude amplification is a general purpose quantum algorithm, or subroutine, that can be used to obtain a quadratic speedup over a handful of classical algorithms. [Grover’s algorithm](https://arxiv.org/abs/quant-ph/9605043) was the first to demonstrate this speedup on unstructured search problems. Formulating a Grover's search problem requires an oracle function that marks one or more computational basis states as the states we are interested in finding, and an amplification circuit that increases the amplitude of marked states, consequently suppressing the remaining states. \n",
"Amplitude amplification is a general purpose quantum algorithm, or subroutine, that can be used to obtain a quadratic speedup over a handful of classical algorithms. [Grover’s algorithm](https://arxiv.org/abs/quant-ph/9605043) was the first to demonstrate this speedup on unstructured search problems. Formulating a Grover's search problem requires an oracle function that marks one or more computational basis states as the states we are interested in finding, and an amplification circuit that increases the amplitude of marked states, consequently suppressing the remaining states.\n",
"\n",
"Here, we demonstrate how to construct Grover oracles and use the `GroverOperator` from the Qiskit circuit library to easily set up a Grover's search instance. The runtime `Sampler` primitive allows seamless execution of Grover circuits."
]
Expand Down Expand Up @@ -419,7 +419,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -433,7 +433,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"id": "da92068c",
"metadata": {},
"source": [
"The previous image illustrates the ansatz in basic gates for clarity. However, it can be expressed in multiple levels of decomposition by changing the `reps` argument or by drawing the circuit without the `decompose` method. For example, the following representation directly shows the QAOA structure with the default `reps` value, which is `reps=1`. "
"The previous image illustrates the ansatz in basic gates for clarity. However, it can be expressed in multiple levels of decomposition by changing the `reps` argument or by drawing the circuit without the `decompose` method. For example, the following representation directly shows the QAOA structure with the default `reps` value, which is `reps=1`."
]
},
{
Expand Down Expand Up @@ -366,7 +366,7 @@
"source": [
"Any classical optimizer can be used to minimize the cost function. On a real quantum system, an optimizer designed for non-smooth cost function landscapes usually does better. Here we use the [COBYLA routine from SciPy through the minimize function](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html).\n",
"\n",
"Because we are iteratively executing many calls to Runtime, we use a [`Session`](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.Session) to execute all calls within a single block. Moreover, for QAOA, the solution is encoded in the output distribution of the ansatz circuit bound with the optimal parameters from the minimization. Therefore, we will need a [`Sampler`](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.SamplerV2) primitive as well, and will instantiate it with the same [`Session`](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.Session).\n"
"Because we are iteratively executing many calls to Runtime, we use a [`Session`](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.Session) to execute all calls within a single block. Moreover, for QAOA, the solution is encoded in the output distribution of the ansatz circuit bound with the optimal parameters from the minimization. Therefore, we will need a [`Sampler`](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.SamplerV2) primitive as well, and will instantiate it with the same [`Session`](https://docs.quantum-computing.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.Session)."
]
},
{
Expand Down Expand Up @@ -658,7 +658,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -672,7 +672,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions tutorials/repeat-until-success/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"source": [
"# Repeat until success\n",
"\n",
"## Background \n",
"## Background\n",
"\n",
"This tutorial demonstrates the current capabilities of IBM dynamic-circuit backends to use mid-circuit measurements to produce a circuit that repeatedly attempts its setup until a syndrome measurement reveals that it has been successful. \n",
"This tutorial demonstrates the current capabilities of IBM dynamic-circuit backends to use mid-circuit measurements to produce a circuit that repeatedly attempts its setup until a syndrome measurement reveals that it has been successful.\n",
"\n",
"We will build an abstract circuit that uses the non-parametrized gate set $\\{H,\\,X,\\,S,\\,\\text{Toffoli}\\}$ to construct a heralded $R_X(\\theta)$ gate on a target qubit, where $\\theta$ satisfies $\\cos\\theta = \\frac35$. Each iteration of the circuit only has a finite chance of success, but successes are heralded, so we will use our dynamic-circuit capabilities to repeat the setup until it succeeds."
]
Expand Down Expand Up @@ -402,13 +402,13 @@
" state.\"\"\"\n",
" successes = collections.defaultdict(int)\n",
" failures = collections.defaultdict(int)\n",
" \n",
"\n",
" for key, value in counts.items():\n",
" if key.endswith(\"00\"):\n",
" successes[key[0]] += value\n",
" else:\n",
" failures[key[0]] += value\n",
" \n",
"\n",
" return successes, failures"
]
},
Expand Down Expand Up @@ -511,7 +511,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -525,7 +525,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3"
},
"vscode": {
"interpreter": {
Expand Down
Loading