{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SUMMARY notebook\n", "\n", "This notebook scans the directory in which it lives to find all jupyter notebooks (other than itself) in that directory. It then prints for every notebook it finds (1) a hyperlink to the notebook, and (2) the first cell (which is always markdown) of the notebook. This way you can read a nice, automatically generated summary of all the notebooks without having to open all of them. If you find a notebook that you want to explore further, you can simply click on its link to open it." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "\n", "\n", "
\n", "\n", "Bell_and_CHSH_inequalities.ipynb [local link] [github link] 1/27\n", "\n", "# Bell and CHSH inequalities\n", "$\\newcommand{\\bra}[1]{\\left\\langle{#1}\\right|}$\n", "$\\newcommand{\\ket}[1]{\\left|{#1}\\right\\rangle}$\n", "\n", "The purpose of this notebook is to simulate the CHSH experiment\n", "described in the IBM Quantum Experience tutorial in the section\n", "entitled \n", "\n", ">Multiple Qubits, Gates, and Entangled States/Entanglement and Bell Tests\n", "\n", "
\n", "\n", "Fedortchenko-paper.ipynb [local link] [github link] 2/27\n", "\n", "## Teleportation experiment from paper by Fedortchenko\n", "\n", "This notebook uses Qubiter to illustrate a pedagogical Teleportation \n", "experiment performed by S. Fedortchencko on IBM Quantum Experience, \n", "and described by him in the paper\n", "\n", ">https://arxiv.org/abs/1607.02398\n", "\n", "$$\\newcommand{\\bra}[1]{\\left\\langle{#1}\\right|}$$\n", "$$\\newcommand{\\ket}[1]{\\left|{#1}\\right\\rangle}$$\n", "\n", "
\n", "\n", "MeanHamilMinimizer_native_scipy.ipynb [local link] [github link] 3/27\n", "\n", "# MeanHamilMinimizer native scipy \n", "\n", "The purpose of this notebook is to describe a naive but pedagogical,\n", "first baby step, in the implementation\n", "of what is called in Qubiter the Mean Hamiltonian Minimization problem.\n", "\n", "The qc history of this problem started with quantum chemists planning to\n", "use on a qc the phase estimation algo invented by Kitaev? (an algo that\n", "is also implemented in Qubiter) to estimate the energy levels (\n", "eigenvalues) of simple molecules, initially H2. Then a bunch of people\n", "realized, heck, rather than trying to estimate the eigenvalues of a\n", "Hamiltonian by estimating the phase changes it causes, we can estimate\n", "those eigenvalues more efficiently by estimating the mean value of that\n", "Hamiltonian as measured empirically on a qc. Basically, just the\n", "Rayleigh-Ritz method, one of the oldest tricks in the book. One of the\n", "first papers to propose this mean idea is\n", "https://arxiv.org/abs/1304.3061 Their algo is commonly referred to by\n", "the ungainly name VQE (Variational Quantum Eigensolver) VQE was\n", "originally applied to do quantum chemistry with a qc. But now Rigetti\n", "and others have renamed it hybrid quantum-classical quantum computing\n", "and pointed out that it's an algo that has wide applicability, not just\n", "to quantum chemistry.\n", "\n", "The idea behind hybrid quantum-classical is very simple. One has a\n", "classical box CBox and a quantum box QBox. The gates of QBox depend on N\n", "gate parameters. QBox sends info to CBox. CBox sends back to QBox N new\n", "gate parameters that will lower some cost function. This feedback\n", "process between CBox and QBox continues until the cost is minimized. The\n", "cost function is the mean value of a Hamiltonian which is estimated\n", "empirically from data obtained from the qc which resides inside the QBox.\n", "\n", "To minimize a function of N continuous parameters, one can use some\n", "methods like simulated annealing and Powell that do not require\n", "calculating derivatives, or one can use methods that do use derivatives.\n", "Another possible separation is between methods that don't care which\n", "local minimum they find, as long as they find one of them, and those\n", "methods that try to find the best local minimum of them all, the so\n", "called global minimum. Yet another separation is between methods that\n", "allow constraints and those that don't.\n", "\n", "Among the methods that do use derivatives, the so called gradient based\n", "methods only use the 1st derivative, whereas other methods use both\n", "first (Jacobian) and second (Hessian) derivatives. The performance of\n", "those that use both 1st and 2nd derivatives degrades quickly as N grows.\n", "Besides, calculating 2nd derivatives is very expensive. Hence, methods\n", "that use the 2nd derivatives are practically useless in the neural\n", "network field where N is usually very large. In that field, gradient\n", "based methods rule.\n", "\n", "A method that uses no derivatives is Powell. A gradient based method\n", "that is designed to have a fast convergence rate is the Conjugate\n", "Gradient (CG) method. Another gradient based method is back-propagation\n", "(BP). BP can be implemented as distributed computing much more easily\n", "than other gradient based methods so it is favored by the most popular\n", "computer programs for doing distributed AI, such as PyTorch and\n", "Tensorflow.\n", "\n", "Qubiter can perform minimization using various minlibs (minimization \n", "software libraries) such as 'scipy', 'autograd', 'pytorch', 'tflow'. It \n", "can also use various devices (aka simulators or backends), either \n", "virtual or real, to do the minimization. \n", "\n", "Non-scipy minlibs implement backprop.\n", "\n", "The 'scipy' minlib is a wrapper for the scipy function\n", "`scipy.optimize.minimize`. This scipy umbrella method implements many\n", "minimization methods, including Powell and CG.\n", "\n", "https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html\n", "\n", "By a native device, we mean one that uses Qubiter native simulators like\n", "SEO_simulator.\n", "\n", "\n", "So, without further ado, here is an example of the use of \n", "class `MeanHamilMinimizer` with a scipy minlib and native device.\n", "\n", "
\n", "\n", "MeanHamilMinimizer_native_with_autograd.ipynb [local link] [github link] 4/27\n", "\n", "# MeanHamilMinimizer, native with Autograd\n", "* Feedback loop between Qubiter and Qubiter\n", "* minimization via autograd\n", "\n", "
\n", "\n", "MeanHamilMinimizer_native_with_tf.ipynb [local link] [github link] 5/27\n", "\n", "# MeanHamilMinimizer, native with Tensorflow\n", "\n", " * Feedback loop between Qubiter and Qubiter\n", " * minimization via tensorflow\n", "\n", "\n", "
\n", "\n", "MeanHamilMinimizer_native_without_autograd.ipynb [local link] [github link] 6/27\n", "\n", "# MeanHamilMinimizer, native without Autograd\n", "\n", "This notebook is a counterpart to the notebook `MeanHamilMinimizer_native_with_autograd`.\n", "The first problem in both notebooks is identical and done all natively, but here it is done with scipy instead of autograd.\n", "\n", "* Feedback loop between Qubiter and Qubiter\n", "* minimization via scipy\n", "\n", "
\n", "\n", "MeanHamilMinimizer_rigetti_autograd.ipynb [local link] [github link] 7/27\n", "\n", "# MeanHamilMinimizer_rigetti_autograd\n", "\n", "* Feedback loop between Qubiter and Rigetti QVM\n", "* minimization via autograd\n", "\n", ">This notebook calls Rigetti's method QVMConnection() which only works if you first:\n", "* install the Rigetti Forest SDK available at https://www.rigetti.com/forest\n", "* open a second terminal (besides the one that runs this notebook) and type \"qvm -S\" in it\n", "* open a third terminal and type \"quilc -S\" in it\n", "\n", "
\n", "\n", "MeanHamilMinimizer_rigetti_scipy.ipynb [local link] [github link] 8/27\n", "\n", "# MeanHamilMinimizer_rigetti_scipy\n", "* Feedback loop between Qubiter and Rigetti QVM\n", "* minimization via scipy.optimize.minimize\n", "\n", ">This notebook calls Rigetti's method QVMConnection() which only works if you first:\n", "* install the Rigetti Forest SDK available at https://www.rigetti.com/forest\n", "* open a second terminal (besides the one that runs this notebook) and type \"qvm -S\" in it\n", "* open a third terminal and type \"quilc -S\" in it\n", "\n", "
\n", "\n", "Say_Hello_World_With_Qubiter.ipynb [local link] [github link] 9/27\n", "\n", "## Say \"Hello World\" With Qubiter\n", "The purpose of this notebook is to illustrate how to use Qubiter to simulate ( i.e., \n", "predict the outcome of) a simple quantum circuit with a few basic gates\n", "\n", "> Below, we won't always give the precise definition of each gate. You can find the\n", "precise analytical/numerical definition of all gates implemented by Qubiter in the document entitled `qubiter_rosetta_stone.pdf` included with the Qubiter distribution.\n", "\n", "
\n", "\n", "Stairs_circuit_and_its_gradients_in_native.ipynb [local link] [github link] 10/27\n", "\n", "# Stairs Circuit and its gradients evaluated using native simulators\n", "\n", "A \"quantum cost function\" is the mean value of a\n", "Hermitian operator, wherein that mean value is calculated empirically from\n", "the data yielded by a physical quantum computer. (In this notebook, however, we fake that data\n", "with a Qubiter simulator. Just warming up. Brrmm! Brrmm! Everything is setup\n", "so that calls to a real physical qc such as Rigetti's qc can be easily substituted for the \n", "calls to the Qubiter simulator)\n", "\n", "A Stairs circuit is a quantum circuit that in its full generality can \n", "parametrize a completely general quantum state vector. \n", "\n", "In this notebook, we consider a special quantum cost function in which\n", "a Stairs circuit provides the state vector with which the mean values are calculated.\n", "I like to say that the Stairs circuit is the kernel of the quantum cost function. Our ultimate intention is to\n", "minimize this cost function using gradient descent. But to do that, we must first calculate\n", "the derivatives (gradients) of the cost function. That is what we will do in this notebook: calculate all the derivatives of a quantum cost function whose kernel is a Stairs circuit.\n", "\n", " In particular,\n", "this notebook runs through their paces 4 Qubiter classes that increasingly build on each other\n", "\n", "* `StairsCkt_writer`, writes English and Picture files for a Stairs quantum circuit\n", "* `StairsDeriv_writer`, writes English and Picture files for several quantum circuits that are needed to evaluate the derivatives of a Stairs circuit\n", "* `StairsDeriv_native`, evaluates the 4 derivatives of a single gate of a Stairs circuit. It uses native Qubiter simulators to do this. Qubiter also has an analogous class `StairsDeriv_rigetti` that uses Rigetti simulators or their real physical qc. We will demo that class in a future notebook.\n", "* `StairsAllDeriv_native`, evaluates all the derivatives, for all the gates of a Stairs circuit. It uses native Qubiter simulators to do this. Qubiter also has an analogous class `StairsAllDeriv_rigetti` that uses Rigetti simulators or their real physical qc. We will demo that class in a future notebook.\n", "\n", "For an explanation of the theory behind the software that is being demo-ed in this notebook, see the following\n", "pdf included with the Qubiter distribution.\n", "\n", ">Title:\n", "Calculation of the Gradient of a Quantum Cost Function using \"Threading\".\n", "Application of these \"threaded gradients\" to a\n", "Quantum Neural Net\n", "inspired by\n", "Quantum Bayesian Networks, \n", "\n", "> https://github.com/artiste-qb-net/qubiter/blob/master/adv_applications/threaded_grad.pdf\n", "\n", "
\n", "\n", "Stairs_ckt_its_gradients_in_rigetti.ipynb [local link] [github link] 11/27\n", "\n", "# Stairs Circuit, its gradients evaluated using Rigetti QVM\n", "\n", "Before reading this Jupyter notebook, \n", "we recommend that you first read the earlier notebook \n", "named \n", "\n", ">`Stairs_circuit_and_its_gradients_in_native.ipynb`\n", "\n", "located in the same folder in the Qubiter repo as this notebook.\n", "In that earlier notebook, we use the Qubiter (i.e., native) simulator\n", "to evaluate the gradients of a special quantum cost function. In this notebook,\n", "we evaluate the same gradients, but, instead of the native simulator, \n", "we use the Rigetti QVM (quantum virtual machine), which is a bit more\n", "complicated than using the native simulator.\n", "\n", "Qubiter supports, as a single gate, a general U(2) operation with any number of controls,\n", "of either the T (full circle) or F (empty circle) kind. \n", "Such gates are fundamental to the Stairs circuit that we are considering.\n", "For now at least, Rigetti doesn't\n", "support such gates in a single step, so we have figured out a work-around until they do.\n", "Programmers are masters at figuring out work-arounds.\n", "\n", "What we do is use Qubiter's class `CGateExpander` to expand all\n", "multi-controlled U(2) gates into simple CNOTs and\n", "single qubit rotation gates. This is a very basic set of gates that\n", " Rigetti's real and virtual machines can handle.\n", "(Also, \n", "right before the expansion, we substitute each placeholder\n", "variable (aka parameter) by its float value.)\n", "But `CGateExpander` takes as input a quantum circuit written in Qubiter's language and \n", "returns a new,\n", "expanded, quantum circuit also written in Qubiter's language.\n", "So further processing is required.\n", "We then use Qubiter's class `Qubiter_to_RigettiPyQuil`\n", "to translate the expanded quantum circuit from Qubiter's to Rigetti's language.\n", "Once we have translated all the quantum circuits\n", "to Rigetti's language, we are home free. From there on,\n", "we just follow very similar steps to \n", "those performed in the earlier, all-native notebook. \n", "\n", "This notebook demos 2 Qubiter classes:\n", "\n", "* `StairsDeriv_rigetti`, evaluates the 4 derivatives of a single gate of a Stairs circuit. It uses Rigetti simulators or their real physical qc to do this. \n", "* `StairsAllDeriv_rigetti`, evaluates all the derivatives, for all the gates of a Stairs circuit. It uses Rigetti simulators or their real physical qc to do this.\n", "\n", ">This notebook calls Rigetti's method QVMConnection() which only works if you first:\n", "* install the Rigetti Forest SDK available at https://www.rigetti.com/forest\n", "* open a second terminal (besides the one that runs this notebook) and type \"qvm -S\" in it\n", "* open a third terminal and type \"quilc -S\" in it\n", "\n", "
\n", "\n", "Teleportation-showcasing-IF_M-blocks.ipynb [local link] [github link] 12/27\n", "\n", "## Teleportation example showcasing IF_M blocks\n", "This notebook uses Qubiter to illustrate quantum Teleportation \n", "of the pure state of one qubit (at 0) to another qubit (at 2) with the help of an ancilla qubit (at 1).\n", "\n", "The purpose of this notebook is not to teach about the \"theory\" behind quantum Teleportation.\n", "For that, the reader can go to numerous sources on the internet (Wikipedia, course notes, etc.)\n", "The purpose is to showcase some of the features of Qubiter, especially IF_M blocks (and also PRINT statements and calculations and plotting of various density matrices associated with any quantum circuit).\n", "\n", "For a full inventory of Qubiter English file commands, see \n", "Qubiter's Rosetta Stone pdf\n", "\n", "IBM has posted at https://github.com/QISKit/qiskit-tutorial, a jupyter notebook similar to this one, analysing the same quantum circuit for quantum Teleportation from one qubit to another. Their notebook uses IBM's qasm language instead of Qubiter's language so you might profit from comparing their notebook to this one to decide which qc language you prefer. Qubiter includes subroutines that can translate its language to IBM qasm that can then be run on IBM qc hardware.\n", "\n", "\n", "
\n", "\n", "Teleportation-showcasing-IF_M-blocks_CN.ipynb [local link] [github link] 13/27\n", "\n", "## 量子传输和测量模块的展示\n", "\n", "在此我们用Qubiter编译/模拟器来展示如何通过一个中间量子比特(比特1)的协助,将一个量子比特(比特0)的纯态传输到另一个量子比特(比特2)。\n", "\n", "本文并不旨在讨论或展示量子传输背后的理论。对此感兴趣的读者可以很方便地在网上(维基或者课件)找到对于量子传输的简单推导。以量子传输为例,我们重点展示Qubiter的一些功能,例如测量模块(IF_M blocks)、打印输出,以及量子线路中各种密度矩阵的计算和画图功能。\n", "\n", "QUbiter也支持自动生成量子线路的语言文件。感兴趣的读者可以在此找到 Qubiter语言文件的详解。\n", "\n", "\n", "在IBM公司一系列量子计算的展示文档中,也有文档分析了量子态传送的量子传输过程及其量子线路。这些文档是用IBM推出的 qasm 语言组织的,读者可以对qasm语言和Qubiter语言结构进行比较并选用自己喜欢的程序。另外,除了量子编译和量子仿真之外,Qubiter提供了将自身语言转换为IBM qasm语言的子程序,这样通过Qubiter编译后的量子线路可以直接在IBM的量子计算硬件上运行。对其他(例如Rigetti)编译语言和硬件的支持也正在进行中。\n", "\n", "\n", "
\n", "\n", "Translating_from_Qubiter_to_Xanadu_PennyLane.ipynb [local link] [github link] 14/27\n", "\n", "# Translating from Qubiter to Xanadu PennyLane\n", "\n", "The purpose of this notebook is to illustrate how to translate a Qubiter English file for\n", "a quantum circuit, into a Xanadu Pennylane \"qnode\"\n", "\n", "Next, we will create 2 Qubiter English files and then translate them to Pennylanese \n", "\n", "
\n", "\n", "autograd_experiments.ipynb [local link] [github link] 15/27\n", "\n", "# Autograd experiments\n", "\n", "**References**\n", "* https://github.com/HIPS/autograd/blob/master/docs/tutorial.md\n", "* https://github.com/HIPS/autograd/blob/master/docs/updateguide.md\n", "\n", "abbreviations:\n", "* ax= axis\n", "* dwrt= derivative with respect to\n", "\n", "
\n", "\n", "examples_of_placeholder_usage.ipynb [local link] [github link] 16/27\n", "\n", "# Examples of usage of Gate Angle Placeholder\n", "\n", "The word \"Placeholder\" is used in Qubiter (we are in good company, Tensorflow uses this word in the same way) to mean a variable for which we delay/postpone assigning a numerical value (evaluating it) until a later time. In the case of Qubiter, it is useful to define gates with placeholders standing for angles. One can postpone evaluating those placeholders until one is ready to call the circuit simulator, and then pass the values of the placeholders as an argument to the simulator’s constructor. Placeholders of this type can be useful, for example, with quantum neural nets (QNNs). In some QNN algorithms, the circuit gate structure is fixed but the angles of the gates are varied many times, gradually, trying to lower a cost function each time.\n", "\n", "> In Qubiter, legal variable names must be of form `#3` or `-#3` or `#3*.5` or\n", "`-#3*.5` where 3 can be replaced by any non-negative int, and .5 can\n", "be replaced by anything that can be an argument of float() without\n", "throwing an exception. In this example, the 3 that follows the hash\n", "character is called the variable number\n", "\n", ">NEW! (functional placeholder variables)\n", "Now legal variable names can ALSO be of the form `my_fun#1#2` or\n", "`-my_fun#1#2`, where\n", "* the 1 and 2 can be replaced by any non-negative integers and there\n", "might be any number > 0 of hash variables. Thus, there need not\n", "always be precisely 2 hash variables as in the example.\n", "* `my_fun` can be replaced by the name of any function with one or\n", "more input floats (2 inputs in the example), as long as the first\n", "character of the function's name is a lower case letter.\n", "\n", ">The strings `my_fun#1#2` or `-my_fun#1#2` indicate than one wants to\n", "use for the angle being replaced, the values of `my_fun(#1, #2)` or\n", "`-my_fun(#1, #2)`, respectively, where the inputs #1 and #2 are\n", "floats standing for radians and the output is also a float standing\n", "for radians.\n", "\n", "\n", "\n", "
\n", "\n", "forbidden_cnot_expansions.ipynb [local link] [github link] 17/27\n", "\n", "# Forbidden-CNot Expansions\n", "\n", "Most chips are not fully connected (not all pairs of qubits are\n", "physically connected). Furthermore, even if two qubits are connected,\n", "one of them may be forbidden as a target of a CNOT between\n", "the 2 qubits. The Qubiter file `ForbiddenCNotExpander.py`\n", "contains an \"expander\" class of the same name that is \n", "designed to circumvent this chip limitation.\n", "\n", "The class reads an English file and outputs a new English file and\n", "corresponding Picture file. The new English file differs from the initial\n", "English file in that each forbbiden CNOT is expanded into a sequence of Hadamards\n", "and allowed, elementary CNOTs.\n", "\n", "This notebook shows 2 examples of the usage of this class.\n", "\n", "\n", "
\n", "\n", "gate-expansions.ipynb [local link] [github link] 18/27\n", "\n", "# Gate Expansions\n", "\n", "This notebook is intended to illustrate various gate expansions.\n", "Qubiter allows one to write on a single line in an English file \n", "many types of U(2) matrices with 0, 1, or more controls attached to it. However, there are well known identities for expanding such gates into\n", "a sequence of (1) single qubit rotations and (2) CNOTs with a single control.\n", "This is useful because most quantum computers (for example, IBM Quantum Experience)\n", "can only perform (1) and (2). Expansions into (1) and (2)\n", "can be performed automatically by Qubiter. Here is how.\n", "\n", "The expansions used by Qubiter \n", "were all discovered long ago. They can all be\n", "found in the following 1995 quantum computing paper:\n", "\n", "https://arxiv.org/abs/quant-ph/9503016\n", "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "ghz_state.ipynb [local link] [github link] 19/27\n", "\n", "# GHZ state\n", "$\\newcommand{\\bra}[1]{\\left\\langle{#1}\\right|}$\n", "$\\newcommand{\\ket}[1]{\\left|{#1}\\right\\rangle}$\n", "\n", "The purpose of this notebook is to simulate the GHZ experiment\n", "described in the IBM Quantum Experience tutorial in the section\n", "entitled \n", "\n", ">Multiple Qubits, Gates, and Entangled States/GHZ states\n", " \n", "If you understand our \"Bell_and_CHSH_inequalities\" notebook,\n", "this notebook uses very similar math.\n", "\n", "It uses the following results whose proofs use techniques already covered \n", "in our \"Bell_and_CHSH_inequalities\" notebook\n", "\n", "$\\bra{ b_X} = \\bra{ b_Z} H$\n", "\n", "$\\bra{ b_Y} = \\bra{ b_Z} H S^\\dagger$\n", "\n", "for $b=0, 1$.\n", "\n", "$\\bra{\\psi} \\sigma_A(0) \\sigma_B(1) \\sigma_C(2)\\ket{\\psi} = \\sum_{b_0 + b_1 + b_2 = 0, 2} Prob(b_0, b_1, b_2) - \\sum_{b_0 + b_1 + b_2 = 1, 3} Prob(b_0, b_1, b_2)$\n", "\n", "
\n", "\n", "loops_at_english_file_level_using_loop_files.ipynb [local link] [github link] 20/27\n", "\n", "# Loops at English File level using Loop Files\n", "\n", "Before reading this notebook, we recommend that you first learn how to use placeholders in Qubiter,\n", "because placeholders and loops at the English file level are both used heavily in this notebook. They both go naturally together. Placeholder usage is illustrated in the notebook called `examples_of_placeholder_usage.ipynb` located in the same folder as this one.\n", "\n", "You can have loops at either the Python library level or the machine language level (i.e., English file). Both accomplish the same purpose. This notebook is only important to you if you want to use loops in an English file. The following talk explains some of the motivation and pros and cons of doing this. \n", "\n", "http://www.ar-tiste.com/jan2019QubiterPlaceholderAndLoops.pdf\n", " \n", "\n", "
\n", "\n", "phase_est_examples.ipynb [local link] [github link] 21/27\n", "\n", "# Quantum Phase Estimation Examples\n", "\n", "This notebook gives some examples of how to use Qubiter to write and simulate a quantum\n", "circuit that does quantum phase estimation (qPE).\n", "\n", "Even though qPE was invented by Kitaev, it can be understood \n", "(See IBM Quantum Experience Tutorial for the details) as\n", "a quantum computer version of a much earlier model, namely, \n", "the von Neumann Pointer-System model for a quantum\n", "mechanical measurement.\n", "\n", "\n", "In the case of quantum computers, \n", "the Pointer in von Neumann's model is represented by several \"pointer qubits\"\n", "and the System by several \"system qubits\".\n", "The matrix U whose eigenvalues we wish to find\n", "acts on the System qubits.\n", "\n", "In Qubiter, we call the \"pointer qubits\" the \"probes\", and the qbits that U acts on the \"atom qbits\". We call U the \"atom matrix\".\n", "$\\newcommand{\\bra}[1]{\\left\\langle{#1}\\right|}$\n", "$\\newcommand{\\ket}[1]{\\left|{#1}\\right\\rangle}$\n", "\n", "
\n", "\n", "phase_est_iterative.ipynb [local link] [github link] 22/27\n", "\n", "# Quantum Phase Estimation, Iterative\n", "$\\newcommand{\\bra}[1]{\\left\\langle{#1}\\right|}$\n", "$\\newcommand{\\ket}[1]{\\left|{#1}\\right\\rangle}$\n", "\n", "To economize in qubits, the References below advocate\n", "using the so called iterative Quantum Phase Estimation (iterative qPE).\n", "Whereas the usual qPE uses multiple pointer qubits and gives the\n", "answer in one shot (passage through a single circuit), the iterative \n", "qPE uses only a single pointer qubit but requires\n", "passage through multiple circuits, with the parameters\n", "of each circuit depending on the final pointer measurement of the previous circuit.\n", "This works because the kickback phases which each power of U\n", "sends to the pointers in the nomal qPE are cummulative: the k'th\n", "pointer gets a\n", "kickback phase which includes the \n", "kickback phases accrued by all previous pointer qubits.\n", "\n", "In this example, we use \n", "\n", "$U = e^{i*rads*\\sigma_Z}$\n", "\n", "for some Real number $rads$ \n", "and we use initial state $\\ket{0}$, so $e^{i*rads}$ is the \n", "eigenvalue we seek.\n", "\n", "Here are some of the equations used in the code below\n", " \n", "``` \n", "for k in range(num_reps):\n", "\n", " | H \n", " | exp(i*alpha(k)*sigz)\n", " U^(2^k)-----@ \n", " | H \n", " | measure n(k) here\n", "```\n", "\n", "$\\alpha(0) = n(0) =0$\n", "\n", "$\\alpha(k+1) = 2\\alpha(k) + \\frac{\\pi}{2} n(k)$\n", "\n", "$\\alpha(k) = \\pi 2^{k-2}\\sum_{b=0}^{k-1} \\frac{n(b)}{2^{b}}$\n", "\n", "$rads = \\frac{\\alpha(num\\_reps-1)}{2^{num\\_reps-2}}$\n", "\n", "\n", "References\n", "----------\n", "\n", "1. https://arxiv.org/abs/1512.06860 by Google team\n", "\n", "2. https://arxiv.org/abs/1605.03590 by Microsoft team\n", "\n", "\n", "\n", "
\n", "\n", "quantum_CSD_compiler_intro.ipynb [local link] [github link] 23/27\n", "\n", "# Quantum CSD Compiling Intro\n", "\n", "The purpose of this notebook is to give a quick introduction to Qubiter's \n", "CSD quantum compiler capabilities. \n", "\n", "By a quantum complier, we mean\n", "a computer program that takes as input an arbitrary unitary matrix $U$ of dimension $N=2^n$\n", "and returns a SEO (sequence of elementary operations, in this case CNOTs and single qubit\n", "rotations) that equals $U$. There are various kinds of quantum \n", "compilers. Suppose $U$ is of the form $U=e^{-itH}$, where $t$ is time and $H$ is\n", "the Hamiltonian operator. If $H$ has a form which is known a priori, a situation\n", "that is common in Physics and Chemistry, then a popular way of expanding $U$\n", "is by using the Trotter-Suzuki approximation. If the form of $H$ is not\n", "known a priori as is common in Artificial Intelligence, then\n", "we recommend using the CS (Cosine-Sine) decomposition of Linear Algebra.\n", "Both methods are already implemented in Qubiter, but this notebook is about\n", "the CSD.\n", "\n", "Doing CSD quantum compiling with Qubiter requires using the classes in the quantum_CSD_compiler\n", "folder, which will only work properly if you install, besides all the Qubiter\n", "Python files and a Python distro that includes numpy and scipy (for example, Anaconda),\n", "some binary libraries prepared by Artiste-q.net which include\n", "a Python wrapper for a LAPACK subroutine\n", "called cuncsd.f that performs CSDs. How to install those binary libraries\n", "is explained elsewhere in this site. Henceforth, we will assume \n", "all the necessary files have been installed on your computer if you want to redo the calculations.\n", "\n", "The quantum_CSD_compiler folder includes a pdf called csd-intro.pdf that gives\n", "an introduction to the CSD. \n", "\n", "Some external references:\n", "\n", "\n", "1. R.R. Tucci, A Rudimentary Quantum Compiler(2cnd Ed.)\n", " https://arxiv.org/abs/quant-ph/9902062\n", "\n", "2. Qubiter 1.11, a C++ program whose first version was released together\n", " with Ref.1 above. Qubiter 1.11 is included in the\n", " quantum_CSD_compiler/LEGACY folder of this newer, pythonic version of Qubiter\n", " \n", "3. R.R. Tucci, Quantum Fast Fourier Transform Viewed as a Special Case of Recursive Application of Cosine-Sine Decomposition, https://arxiv.org/abs/quant-ph/0411097\n", "\n", "\n", "\n", "
\n", "\n", "quantum_CSD_compiler_intro_CN.ipynb [local link] [github link] 24/27\n", "\n", "# 量子编译简介\n", "\n", "本文档介绍 *Qubiter* 所用的正余弦分解(CSD, Cosine-Sine decomposition)量子编译器及其性能。\n", "\n", "量子编译器指以任意 $N=2^n$ 维的幺正矩阵 $U$ 作为输入,能够输出等价于矩阵 $U$ 的基本操作序列(比如 CNOT 受控反门和单量子比特旋转门)的计算机程序,可以有很多种。通常幺正矩阵 $U$ 的形式为 $U=e^{-itH}$,其中 $t$ 和 $H$ 分别代表时间和哈密顿算符。在物理学和量子化学领域中,$H$ 的具体形式往往可以先验已知,通常的做法是用 Trotter-Suzuki 近似对 $U$ 进行展开。而在人工智能等领域,哈密顿量 $H$ 的具体形式一般不能先验已知,这时候则推荐使用线性代数中正余弦分解(CSD)来处理矩阵。这两种不同的编译方式都可以使用 *Qubiter* 实现,此文档着重介绍正余弦分解编译方法。\n", "\n", "使用 *Qubiter* 进行 CSD 量子编译需要调用 'quantum_CSD_compiler' 文件夹中的类文件。这些类的使用除了需要 *Qubiter* 的 Python 文件包和安装了 numpy、scipy 库的 Python 环境(例如 Anaconda )外,还需要[安装由 Artiste-qb.net 提供的二进制库](https://github.com/artiste-qb-net/Python-CS-Decomposition#installation)。此库包括了 Python 封装的进行正余弦分解的 LAPACK 子程序 'cuncsd.f'。复述本文档中的计算需要安装所有必要的文件和库。\n", "\n", "在 'quantum_CSD_compiler' 文件夹中的 ['csd-intro.pdf'](https://github.com/artiste-qb-net/qubiter/blob/master/quantum_CSD_compiler/csd-intro.pdf) 文件提供了 CSD(正余弦分解)的介绍。其他参考文献有:\n", "\n", "1. [R.R. Tucci,《初级量子编译》(第二版)](https://arxiv.org/abs/quant-ph/9902062)\n", "\n", "2. Qubiter 1.11: 基于 C++ 的原始 *Qubiter* 版本。最初一版 *Qubiter 1.11* 和文献1同步发布。在新的 *Qubiter* 版本(基于 Python)的 'quantum_CSD_compiler/LEGACY' 文件夹中包含了 *Qubiter 1.11* 原始程序。\n", "\n", "3. R.R. Tucci,[《量子快速傅立叶变换 - 正余弦分解递归应用举例》](https://arxiv.org/abs/quant-ph/0411097)\n", "\n", "\n", "
\n", "\n", "translating-qubiter-english-file-to-AnyQasm.ipynb [local link] [github link] 25/27\n", "\n", "# Translating Qubiter English file to AnyQasm file\n", "\n", "aqasm= a quantum assembly language, a low level quantum language, containing a small but universal set of quantum gates such as CNOTs and single qubit rotations.\n", "\n", "Note that in the `device_specific` folder, Qubiter contains an abstract class called `Qubiter_to_AnyQasm`. This abstract class is the parent to 3 other classes in the same folder called `Qubiter_to_IBMqasm`, `Qubiter_to_GoogleCirq` and `Qubiter_to_RigettiPyQuil`. In this notebook, we will give examples of usage of these 3 child classes.\n", "These 3 child classes translate Qubiter \"English files\" to \"target\" quantum languages IBM qasm, Google Cirq and Rigetti PyQuil,\n", "respectively. These target quantum languages were chosen because they are very popular and their companies currently offer quantum computing devices on the cloud. \n", "The parent class `Qubiter_to_AnyQasm` does most of the hard work, so it will be easy in future to add child classes to Qubiter for other target quantum languages.\n", "\n", "\n", "For all 3 target quantum languages, you can write a Jupyter notebook that translates a Qubiter English file into a bridge file in the target quantum language, \n", "and then automatically transmits that bridge file to the target company's cloud service, and gets a response back from that cloud service. That way you can run a q circuit on the target company's hardware directly from a Jupyter notebook on your computer.\n", "\n", "
\n", "\n", "unusual_gates_like_generalized_swap.ipynb [local link] [github link] 26/27\n", "\n", "# Unusual Gates like $X(0)^{1.2n(1)}$ or sqrt(iSWAP)\n", "\n", "The purpose of this notebook is to illustrate 2 new members\n", "in the set of gates that Qubiter recognizes. The 2 gates are\n", "\n", "1. an arbitrary matrix U2 in U(2), parametrized as \n", "$U2 = \\exp(i[ \\theta_0 + \\theta_1\\sigma_X + \\theta_2\\sigma_Y + \\theta_3\\sigma_Z])$ \n", "for real $\\theta_j$, where $\\sigma_X, \\sigma_Y, \\sigma_Z$ are the Pauli matrices.\n", "2. a generalization of SWAP(0, 1) which I call SWAY(0, 1). SWAY includes SWAP, sqrt(SWAP), iSWAP, sqrt(iSWAP) etc. I discuss SWAY more precisely below.\n", "\n", "The Qubiter simulator can now handle both of these gates with any number of controls of type T or F\n", "\n", "\n", "
\n", "\n", "widget_adjustable_parametric_circuit.ipynb [local link] [github link] 27/27\n", "\n", "# Simulation of Widget-Adjustable Parametric Circuit\n", "\n", "Suppose you are interested in printing out the state vector\n", "of a quantum circuit at various times (points) in its evolution, as well\n", "as at the end of the circuit. Qubiter can do that.\n", "\n", "Furthermore, suppose that the circuit is a parametric one, and you want to\n", "vary its parameters using sliders on a gui (graphical user interface).\n", "Qubiter can do that too, via a jupyter notebook with widgets.\n", "This notebook is one such notebook. \n", "\n", "\n", "A jupyter\n", "notebook with widgets gives you\n", "the best of both worlds, the gui world and the notebooks world.\n", "\n", "Gui's excel at reducing the possibility of user errors, increasing the ease of use for the user,\n", "and reducing the amount of understanding of the code \n", "that is demanded from the user in order for him or her to use \n", "the code correctly.\n", "\n", "Notebooks excel at providing a robust, flexible, ready made, familiar method of documenting\n", "and saving your work for multiple use cases. They are also great for \n", "explaining your work to others with great detail and precision." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Version: 2\n", "import os\n", "import json\n", "from IPython.display import display, Markdown\n", "\n", "# the name of this file\n", "this_fname = 'SUMMARY.ipynb'\n", "fname_to_md = {}\n", "for fname in sorted([x for x in os.listdir('./')]):\n", " if fname[-6:] == '.ipynb' and fname != this_fname:\n", " # print('------------', fname)\n", " with open(fname, 'r', encoding=\"utf-8\") as f:\n", " fdata = json.load(f)\n", " fname_to_md[fname] = ''.join(fdata['cells'][0]['source'])\n", "# print(fname_to_md)\n", "pre_sep = '\\n\\n
\\n\\n'\n", "full_md = ''\n", "k = 1\n", "num_nb = len(fname_to_md)\n", "project_name =\"qubiter\"\n", "who =\"artiste-qb-net\"\n", "where = \"qubiter/jupyter_notebooks\"\n", "for fname, md in fname_to_md.items():\n", " sep = pre_sep\n", " local_link = f' [local link] '\n", " github_link = f' [github link] '\n", " sep += fname + local_link + github_link + str(k) + '/' + str(num_nb) + '\\n\\n'\n", " full_md += sep + md\n", " k += 1\n", "display(Markdown(full_md))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9" } }, "nbformat": 4, "nbformat_minor": 4 }