diff --git a/examples/Simple_VHA_with_qoqo.ipynb b/examples/Simple_VHA_with_qoqo.ipynb index b38f4027..83de965b 100644 --- a/examples/Simple_VHA_with_qoqo.ipynb +++ b/examples/Simple_VHA_with_qoqo.ipynb @@ -20,13 +20,13 @@ "source": [ "## Example: VHA for spins using qoqo\n", "\n", - "The goal of a variational algorithm is simple: finding a good approximation of the ground state of a physical system defined by a Hamiltonian H by minimizing the expectation value of H with respect to a set of trial states $| \\psi (\\vec{\\theta} )>$.\n", + "The goal of a variational algorithm is simple: finding a good approximation of the ground state of a physical system defined by a Hamiltonian H by minimizing the expectation value of H with respect to a set of trial states $\\left| \\psi (\\vec{\\theta} ) \\right \\rangle$.\n", "The optimization is carried out by optimizing the classical parameters $\\vec{\\theta}$ defining the trial states. \n", "By definition the ground state is the state with the lowest energy, so this approach will find the ground state if the ground-state is in the set of possible trial states and the classical optimizer is successfull. \n", "\n", "The trial states are prepared by applying a set of unitary transformations to an initial state\n", "$$\n", - "| \\psi (\\vec{\\theta}) > = \\prod_j U_j (\\vec{\\theta}) | \\psi_{\\textrm{init}} >.\n", + "\\left | \\psi (\\vec{\\theta}) \\right \\rangle = \\prod_j U_j (\\vec{\\theta})\\, \\left | \\psi_{\\textrm{init}} \\right \\rangle.\n", "$$\n", "In a VHA the ansatz is to assume that the Hamiltonian can be separated into partial Hamiltonians\n", "$$\n", @@ -34,7 +34,7 @@ "$$\n", "and use the time evolution under these partial Hamiltonians as the ansatz for the unitary transformations\n", "$$\n", - "| \\psi (\\vec{\\theta}) > = \\prod_k^{N} \\prod_{\\alpha} \\exp(-i \\theta_{k,\\alpha} H_{\\alpha}) | \\psi_{\\textrm{init}}>,\n", + "\\left | \\psi (\\vec{\\theta}) \\right \\rangle = \\prod_k^{N} \\prod_{\\alpha} \\exp(-i \\theta_{k,\\alpha} H_{\\alpha})\\, \\left| \\psi_{\\textrm{init}}\\right \\rangle,\n", "$$\n", "where N is the number of iterations of the pseudo time evolution and $(\\theta_{k,\\alpha})$ is the variational pseudo time.\n", "\n", @@ -44,7 +44,7 @@ "$$\n", "where $H_0$ is the magnetic onsite energy\n", "$$\n", - "H_0 = B \\left(\\sigma^z_0 + \\sigma^z_1 + \\sigma^z_0\\right),\n", + "H_0 = B \\left(\\sigma^z_0 + \\sigma^z_1 + \\sigma^z_2\\right),\n", "$$\n", "$H_1$ is the hopping between even and odd sites\n", "$$\n", @@ -125,21 +125,21 @@ "In principle the initial state $\\left|\\psi_{\\textrm{init}}\\right>$ has to be prepared with a full quantum circuit (e.g. http://arxiv.org/abs/1711.05395), since we want to keep the example simple we will use a \"cheated\" initial state instead.\n", "\n", "When using a simulator backend one can use a PRAGMA operation (qoqo.operations.pragma_operations.PragmaSetStateVector(vector)) to \"cheat\" and directly set the state vector on the simulator. \n", - "The n-th entry in the state vector corresponds to the basis state $|b(n,2) b(n,1) b(b,0)>$ where $b(n,k)$ gives the k-th enty of the binary representation of n.\n", + "The n-th entry in the state vector corresponds to the basis state $\\left|b(n,2)\\,b(n,1)\\,b(b,0)\\right \\rangle$ where $b(n,k)$ gives the k-th enty of the binary representation of n.\n", "$$\n", - "0 \\leftrightarrow |000>\n", + "0 \\leftrightarrow \\left|000 \\right\\rangle\n", "$$\n", "$$\n", - "1 \\leftrightarrow |001>\n", + "1 \\leftrightarrow \\left|001 \\right\\rangle\n", "$$\n", "$$\n", - "2 \\leftrightarrow |010>\n", + "2 \\leftrightarrow \\left|010 \\right\\rangle\n", "$$\n", "and so on.\n", "\n", "We choose a starting vector that is 50% in the single excitation subspace and 50% fully occupied \n", "$$\n", - "|\\psi_{\\textrm{init}}> = \\frac{1}{\\sqrt{6}}|001> + \\frac{1}{\\sqrt{6}} |010> + \\frac{1}{\\sqrt{6}} |100> + \\frac{1}{\\sqrt{2}} |111>.\n", + "\\left|\\psi_{\\textrm{init}}\\right \\rangle = \\frac{1}{\\sqrt{6}}\\left|001 \\right\\rangle + \\frac{1}{\\sqrt{6}} \\left|010 \\right\\rangle + \\frac{1}{\\sqrt{6}} \\left|100 \\right\\rangle + \\frac{1}{\\sqrt{2}} \\left|111 \\right\\rangle.\n", "$$\n", "We do not include extra terms to change the number of excitations in the VHA ansatz. Choosing a good initial guess for the number of excitations helps with convergence. For VHA variations that automatically derive the right number of excitations see for example https://doi.org/10.1088/2058-9565/abe568." ] @@ -570,7 +570,7 @@ " sp.kron(sp.kron(sigmax, sigmax), identity)\n", " + sp.kron(sp.kron(identity, sigmax), sigmax))\n", "# total Hamiltonian\n", - "H = H_hopping + H_magnetic\n", + "H = H_magnetic + H_hopping\n", "\n", "# diagonalize the Hamiltonian H, calculate eigenvalues and eigenvectors\n", "print('Step 4: Diagonalization of the classical Hamiltonian.')\n", @@ -581,6 +581,13 @@ "delta = final_result.fun - eigenvalues.real[0]\n", "print('Difference between VHA result and exact result: ', \"%.4f\" % delta, '.')" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -609,4 +616,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file