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

Add tutorials #44

Merged
merged 98 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
19f5d4f
Add a tutorial for new `Grover` (Qiskit/qiskit-tutorials#1047)
a-matsuo Oct 21, 2020
d54476a
Algorithm and machine learning tutorials (Qiskit/qiskit-tutorials#1087)
woodsp-ibm Nov 30, 2020
89d5abd
Fix typo (Qiskit/qiskit-tutorials#1095)
schulta Dec 6, 2020
1f8ef92
Fixed some typos on 04_vqe_advanced.ipynb
Dec 15, 2020
eee8a35
Fixed a typo on 04_vqe_advanced.ipynb
Dec 16, 2020
8e84294
algorithms: fix typo on grover jupyter notebook
ljmf00 Dec 29, 2020
fb5bca9
Merge pull request Qiskit/qiskit-tutorials#1096 from schulta/patch-1
SooluThomas Jan 12, 2021
3d179bf
Merge branch 'master' into patch-2
SooluThomas Jan 12, 2021
4f7104a
Merge pull request Qiskit/qiskit-tutorials#1103 from dongsin-kim/patch-2
SooluThomas Jan 12, 2021
4fb55cd
Merge branch 'master' into patch-1
SooluThomas Jan 12, 2021
c12ba84
Merge pull request Qiskit/qiskit-tutorials#1100 from dongsin-kim/patch-1
SooluThomas Jan 12, 2021
bd3a515
Merge branch 'master' into patch-1
SooluThomas Jan 12, 2021
04964e2
Merge pull request Qiskit/qiskit-tutorials#1106 from ljmf00/patch-1
SooluThomas Jan 12, 2021
94227a3
Delete 01_algorithms_introduction.ipynb
divshacker Jan 15, 2021
0cd6626
Fixed Some Broken Links in this tutorial
divshacker Jan 15, 2021
cfff5d0
Merge pull request Qiskit/qiskit-tutorials#1111 from divshacker/master
SooluThomas Jan 15, 2021
90e27db
Delete 03_vqe_simulation_with_noise.ipynb
divshacker Jan 15, 2021
09b8ad1
Fix some Old Links in this tutorials
divshacker Jan 15, 2021
99c9a23
Merge pull request Qiskit/qiskit-tutorials#1112 from divshacker/master
SooluThomas Jan 15, 2021
3afd88e
Deleting file uploading new one
divshacker Jan 22, 2021
98827d1
Uploaded the file with a added extra link.
divshacker Jan 22, 2021
bfd1f98
Corrected Link
divshacker Jan 22, 2021
562563a
Merge pull request Qiskit/qiskit-tutorials#1117 from divshacker/master
SooluThomas Jan 27, 2021
c59d4f3
Fix math mode, toc, and spelling of several sections (Qiskit/qiskit-t…
t-imamichi Apr 7, 2021
46ebb7f
Fix spelling in several simulator tutorials and math mode of opflow a…
t-imamichi May 6, 2021
f863ea9
Remove Aqua references from notebooks (Qiskit/qiskit-tutorials#1162)
manoelmarques Jun 8, 2021
a64cc97
Fix Typo Qiski -> Qiskit (Qiskit/qiskit-tutorials#1198)
q-inho Jun 24, 2021
f7dad22
Ipe tutorial (Qiskit/qiskit-tutorials#1207)
HwajungKang Jun 28, 2021
c005885
Fixed few typos in 09_IQPE.ipynb (Qiskit/qiskit-tutorials#1219)
q-inho Jul 7, 2021
d68de3b
Update 09_IQPE.ipynb (Qiskit/qiskit-tutorials#1227)
Vanimiaou Jul 8, 2021
3b0ebde
Update 09_IQPE.ipynb (Qiskit/qiskit-tutorials#1226)
Vanimiaou Jul 8, 2021
eb13b81
Fixed typo (Qiskit/qiskit-tutorials#1208)
epelaaez Jul 9, 2021
4b66550
replace execute with transpile + backend.run (Qiskit/qiskit-tutorials…
ajavadia Aug 4, 2021
b87a8a8
Updated to use decompose() to unwrap circuit for matplotlib printing.
jwoehr Jan 9, 2022
b76541d
One circuit should not have had a decompose() added, corrected now.
jwoehr Jan 9, 2022
f08bb36
Merge pull request Qiskit/qiskit-tutorials#1259 from jwoehr/grover_bl…
1ucian0 Jan 21, 2022
b503d93
Update 06_grover.ipynb (Qiskit/qiskit-tutorials#1273)
clausia Mar 2, 2022
01707dc
fix spell error (Qiskit/qiskit-tutorials#1274)
NG-Glen Mar 3, 2022
3721971
Updating verbiage to fix Qiskit/qiskit-tutorials#1256
padraignix Apr 15, 2022
2ea9ddf
Typo in IQPE.ipynb - control qubits (Qiskit/qiskit-tutorials#1298)
padraignix May 2, 2022
d7f2f71
Merge branch 'master' into patch-issue-1256
padraignix May 2, 2022
e8c0bc9
Put backticks around code in 01_algorithms_introduction.ipynb
garrison May 3, 2022
273c980
Remove Ignis from tutorials (Qiskit/qiskit-tutorials#1309)
mtreinish May 4, 2022
d23baf3
Merge branch 'master' into patch-issue-1256
padraignix May 5, 2022
5875700
Merge pull request Qiskit/qiskit-tutorials#1304 from padraignix/patch…
HuangJunye May 12, 2022
3d638d2
Merge branch 'master' into backticks-algorithms
HuangJunye May 12, 2022
d3847b1
Merge pull request Qiskit/qiskit-tutorials#1307 from garrison/backtic…
HuangJunye May 13, 2022
7104982
Update 09_IQPE.ipynb (Qiskit/qiskit-tutorials#1282)
NG-Glen May 13, 2022
4e66950
Fix spelling mistakes (Qiskit/qiskit-tutorials#1281)
NG-Glen May 13, 2022
23dec23
Fix for Issue 1261 (Qiskit/qiskit-tutorials#1328)
padraignix May 30, 2022
cc8b7dc
Update Grover tutorials to use Sampler (Qiskit/qiskit-tutorials#1377)
a-matsuo Dec 7, 2022
9ccd7a1
Update VQE tutorials 02-04 (Qiskit/qiskit-tutorials#1376)
ElePT Dec 7, 2022
6b90388
Update the ``01_algorithms_..`` tutorial to using primitives (Qiskit/…
Cryoris Dec 7, 2022
65d5108
Update QAOA tutorial for primitives (Qiskit/qiskit-tutorials#1372)
declanmillar Dec 9, 2022
66d4407
Add new VQD tutorial (using primitives) (Qiskit/qiskit-tutorials#1378)
ElePT Dec 9, 2022
7cdadab
Update iterative phase estimation tutorial to primitives (Qiskit/qisk…
Cryoris Dec 9, 2022
33c0529
Fix removed method from networkx
manoelmarques Jan 8, 2023
baf957f
Merge pull request Qiskit/qiskit-tutorials#1388 from manoelmarques/ne…
manoelmarques Jan 8, 2023
4e8a182
fix links (Qiskit/qiskit-tutorials#1384)
ElePT Jan 9, 2023
3b897bd
qiskit.providers.aer is qiskit_aer in Aer 0.11 (Qiskit/qiskit-tutoria…
1ucian0 Jan 10, 2023
5632c7b
Deleted 08_factorizers.ipynb. (Qiskit/qiskit-tutorials#1368)
Mar 24, 2023
8a5f904
Fix catch in grover tutorial for tera 0.24.0 compatibility (Qiskit/qi…
mtreinish May 4, 2023
01bb79d
Add ``PVQD`` tutorial (Qiskit/qiskit-tutorials#1382)
Cryoris May 19, 2023
3c950e3
Error on Sphinx warnings (Qiskit/qiskit-tutorials#1469)
Eric-Arellano Jun 6, 2023
7b67d75
Add a Variational Quantum Time Evolution Tutorial (fixes Qiskit/qiski…
wenxh0718 Jun 16, 2023
577e5d2
Tutorial on the gradients framework (fixes Qiskit/qiskit-tutorials#13…
maxwell04-wq Jun 19, 2023
01bd3cf
Improving 04_vqd.ipynb (Qiskit/qiskit-tutorials#1471)
TannerTorrey3 Jul 11, 2023
1c9e011
Clarification of scope of optimal_num_iterations. (Qiskit/qiskit-tuto…
JGeipel Jul 11, 2023
c59be65
Improves IPE Algorithm tutorial (Qiskit/qiskit-tutorials#1484)
divshacker Jul 11, 2023
adf9c90
Fix too many `index.rst` problem (Qiskit/qiskit-tutorials#1315) (Qisk…
Jul 11, 2023
6a62745
Fix VQE tutorial to point to Aer docs (Qiskit/qiskit-tutorials#1490)
Eric-Arellano Jul 17, 2023
e7658a6
Improves Grover's Algorithm tutorials (Qiskit/qiskit-tutorials#1483)
divshacker Jul 26, 2023
3906fcf
Improves Monitoring VQE convergence (Qiskit/qiskit-tutorials#1446)
divshacker Jul 26, 2023
9efaace
Improves 03_vqe_simulation_with_noise (Qiskit/qiskit-tutorials#1467)
divshacker Jul 26, 2023
a63a553
Improves An introduction to algorithms (Qiskit/qiskit-tutorials#1445)
divshacker Jul 26, 2023
c0a386c
Convert 'binary' image to LaTeX (Qiskit/qiskit-tutorials#1491)
jakelishman Aug 8, 2023
934b961
Migrate tutorials from qiskit-tutorials
ElePT Aug 17, 2023
865e09c
Quick update of content
ElePT Aug 17, 2023
835a958
Add aer to requirements-dev.txt
ElePT Aug 17, 2023
815b553
Add networkx to requirements-dev.txt
ElePT Aug 17, 2023
aba45b9
Fix spelling
ElePT Aug 17, 2023
4aace2b
Recover grover try
ElePT Aug 17, 2023
2771033
pin sphinx
ElePT Aug 17, 2023
3398dd3
Delete IQPE
ElePT Aug 17, 2023
fb64035
Apply review comments
ElePT Aug 17, 2023
32b7497
Use short urls
ElePT Aug 17, 2023
7a2bea9
Apply comments from code review
ElePT Aug 18, 2023
11e939d
Update tweedledum reqs
ElePT Aug 18, 2023
cbeb4c4
Add thumbnails to metadata
ElePT Aug 18, 2023
a403b5b
Add try-except
ElePT Aug 18, 2023
f74fd8d
Fix gradients tag
ElePT Aug 18, 2023
5ce0c18
Default thumbnail
ElePT Aug 18, 2023
4d13510
Update docs/tutorials/02_vqe_advanced_options.ipynb
ElePT Aug 21, 2023
7050e96
Update docs/tutorials/02_vqe_advanced_options.ipynb
ElePT Aug 21, 2023
8f90b40
Update docs/tutorials/05_qaoa.ipynb
ElePT Aug 21, 2023
6847c25
Update docs/tutorials/10_pvqd.ipynb
ElePT Aug 21, 2023
da2eb7e
Apply suggestions
ElePT Aug 21, 2023
326282c
Merge branch 'main' into add-tutorials
ElePT Aug 21, 2023
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
10 changes: 10 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bfgs
bielza
bitstring
bitstrings
bloch
boltzmann
bool
boyer
Expand Down Expand Up @@ -101,6 +102,7 @@ fmin
formatter
fourier
frac
frobenius
f'spsa
ftol
fujii
Expand All @@ -112,18 +114,21 @@ gaussian
generalised
getter
getters
gilliam
giuseppe
globals
gogolin
goldfarb
goldstone
gonciulea
gqt
grinko
grover
gsls
gtol
gutmann
hadamard
hadamards
hadfield
hamiltonian
hamiltonians
Expand Down Expand Up @@ -170,6 +175,7 @@ lin
linalg
loglik
loglikelihood
lov
lr
lsb
lse
Expand Down Expand Up @@ -200,6 +206,7 @@ nakanishi
nan
nannicini
nathan
nd
ndarray
negoro
nelder
Expand Down Expand Up @@ -286,6 +293,7 @@ runarsson
rz
sanjiv
sashank
satisfiability
satyen
schrödinger
schroediger
Expand Down Expand Up @@ -334,6 +342,7 @@ toctree
todo
tol
trainability
transpilation
transpile
transpiled
trotterization
Expand All @@ -349,6 +358,7 @@ vec
vectorized
vicentini
ville
voilà
vqd
vqe
wavefunction
Expand Down
127 changes: 57 additions & 70 deletions docs/tutorials/01_algorithms_introduction.ipynb

Large diffs are not rendered by default.

535 changes: 535 additions & 0 deletions docs/tutorials/02_vqe_advanced_options.ipynb

Large diffs are not rendered by default.

452 changes: 452 additions & 0 deletions docs/tutorials/03_vqe_simulation_with_noise.ipynb

Large diffs are not rendered by default.

351 changes: 351 additions & 0 deletions docs/tutorials/04_vqd.ipynb

Large diffs are not rendered by default.

392 changes: 392 additions & 0 deletions docs/tutorials/05_qaoa.ipynb

Large diffs are not rendered by default.

726 changes: 726 additions & 0 deletions docs/tutorials/06_grover.ipynb

Large diffs are not rendered by default.

250 changes: 250 additions & 0 deletions docs/tutorials/07_grover_examples.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Grover's algorithm examples\n",
"\n",
"This notebook has examples demonstrating how to use the Qiskit Algorithms [Grover](https://qiskit.org/ecosystem/algorithms/stubs/qiskit_algorithms.Grover.html) search algorithm, with different oracles."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finding solutions to 3-SAT problems\n",
"\n",
"Let's look at an example 3-Satisfiability (3-SAT) problem and walk-through how we can use Quantum Search to find its satisfying solutions. 3-SAT problems are usually expressed in [Conjunctive Normal Forms (CNF)](https://en.wikipedia.org/wiki/Conjunctive_normal_form) and written in the [DIMACS-CNF](http://www.satcompetition.org/2009/format-benchmarks2009.html) format. For example:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"input_3sat_instance = '''\n",
"c example DIMACS-CNF 3-SAT\n",
"p cnf 3 5\n",
"-1 -2 -3 0\n",
"1 -2 3 0\n",
"1 2 -3 0\n",
"1 -2 -3 0\n",
"-1 2 3 0\n",
"'''"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The CNF of this 3-SAT instance contains 3 variables and 5 clauses:\n",
"\n",
"$(\\neg v_1 \\vee \\neg v_2 \\vee \\neg v_3) \\wedge (v_1 \\vee \\neg v_2 \\vee v_3) \\wedge (v_1 \\vee v_2 \\vee \\neg v_3) \\wedge (v_1 \\vee \\neg v_2 \\vee \\neg v_3) \\wedge (\\neg v_1 \\vee v_2 \\vee v_3)$\n",
"\n",
"It can be verified that this 3-SAT problem instance has three satisfying solutions:\n",
"\n",
"$(v_1, v_2, v_3) = (T, F, T)$ or $(F, F, F)$ or $(T, T, F)$\n",
"\n",
"Or, expressed using the DIMACS notation:\n",
"\n",
"`1 -2 3`, or `-1 -2 -3`, or `1 2 -3`.\n",
"\n",
"With this example problem input, we then create the corresponding `oracle` for our `Grover` search. In particular, we use the `PhaseOracle` component, which supports parsing DIMACS-CNF format strings and constructing the corresponding oracle circuit."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\"The 'tweedledum' library is required to use 'BooleanExpression'. You can install it with 'pip install tweedledum'.\"\n"
ElePT marked this conversation as resolved.
Show resolved Hide resolved
]
}
],
"source": [
"import os\n",
"import tempfile\n",
"from qiskit.exceptions import MissingOptionalLibraryError\n",
"from qiskit.circuit.library.phase_oracle import PhaseOracle\n",
"\n",
"\n",
"fp = tempfile.NamedTemporaryFile(mode='w+t', delete=False)\n",
"fp.write(input_3sat_instance)\n",
"file_name = fp.name\n",
"fp.close()\n",
"oracle = None\n",
"try:\n",
" oracle = PhaseOracle.from_dimacs_file(file_name)\n",
"except ImportError as ex:\n",
" print(ex)\n",
"finally:\n",
" os.remove(file_name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `oracle` can now be used to create an Grover instance:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from qiskit_algorithms import AmplificationProblem\n",
"\n",
"problem = None\n",
"if oracle is not None:\n",
" problem = AmplificationProblem(oracle, is_good_state=oracle.evaluate_bitstring)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can then configure the backend and run the Grover instance to get the result:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from qiskit_algorithms import Grover\n",
"from qiskit.primitives import Sampler\n",
"\n",
"grover = Grover(sampler=Sampler())\n",
"result = None\n",
"if problem is not None:\n",
" result = grover.amplify(problem)\n",
" print(result.assignment)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As seen above, a satisfying solution to the specified 3-SAT problem is obtained. And it is indeed one of the three satisfying solutions.\n",
"\n",
"Since we used the `Sampler`, the complete measurement result is also returned, as shown in the plot below, where it can be seen that the binary strings `000`, `011`, and `101` (note the bit order in each string), corresponding to the three satisfying solutions all have high probabilities associated with them."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from qiskit.tools.visualization import plot_histogram\n",
"\n",
"if result is not None:\n",
" display(plot_histogram(result.circuit_results[0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Boolean Logical Expressions\n",
"\n",
"Qiskit's `Grover` can also be used to perform Quantum Search on an `Oracle` constructed from other means, in addition to DIMACS. For example, the `PhaseOracle` can actually be configured using arbitrary Boolean logical expressions, as demonstrated below."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\"The 'tweedledum' library is required to use 'PhaseOracle'. You can install it with 'pip install tweedledum'.\"\n"
]
}
],
"source": [
"expression = '(w ^ x) & ~(y ^ z) & (x & y & z)'\n",
"try:\n",
" oracle = PhaseOracle(expression)\n",
" problem = AmplificationProblem(oracle, is_good_state=oracle.evaluate_bitstring)\n",
" grover = Grover(sampler=Sampler())\n",
" result = grover.amplify(problem)\n",
" display(plot_histogram(result.circuit_results[0]))\n",
"except MissingOptionalLibraryError as ex:\n",
" print(ex)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the example above, the input Boolean logical expression `'(w ^ x) & ~(y ^ z) & (x & y & z)'` should be quite self-explanatory, where `^`, `~`, and `&` represent the Boolean logical XOR, NOT, and AND operators, respectively. It should be quite easy to figure out the satisfying solution by examining its parts: `w ^ x` calls for `w` and `x` taking different values; `~(y ^ z)` requires `y` and `z` be the same; `x & y & z` dictates all three to be `True`. Putting these together, we get the satisfying solution `(w, x, y, z) = (False, True, True, True)`, which our `Grover`'s result agrees with."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "<IPython.core.display.HTML object>",
"text/html": "<h3>Version Information</h3><table><tr><th>Software</th><th>Version</th></tr><tr><td><code>qiskit</code></td><td>0.44.0</td></tr><tr><td><code>qiskit-terra</code></td><td>0.25.0</td></tr><tr><td><code>qiskit_algorithms</code></td><td>0.2.0</td></tr><tr><th colspan='2'>System information</th></tr><tr><td>Python version</td><td>3.9.17</td></tr><tr><td>Python compiler</td><td>Clang 14.0.6 </td></tr><tr><td>Python build</td><td>main, Jul 5 2023 16:17:03</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>8</td></tr><tr><td>Memory (Gb)</td><td>64.0</td></tr><tr><td colspan='2'>Thu Aug 17 18:14:03 2023 CEST</td></tr></table>"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "<IPython.core.display.HTML object>",
"text/html": "<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2023.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import qiskit.tools.jupyter\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.10.2"
},
"vscode": {
"interpreter": {
"hash": "4213929014e7aa4f7c83ab6e8b511ecef456337e6cdcd5a9f1a6614ced2a54b2"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading