From 37f39ca4536107720428fc6ef45af891ff593987 Mon Sep 17 00:00:00 2001 From: Rene Zander Date: Fri, 22 Nov 2024 15:05:24 +0100 Subject: [PATCH] Updated example for ground state energy with QPE --- .../Examples/GroundStateEnergyQPE.rst | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/documentation/source/reference/Examples/GroundStateEnergyQPE.rst b/documentation/source/reference/Examples/GroundStateEnergyQPE.rst index c22c7752..4887d562 100644 --- a/documentation/source/reference/Examples/GroundStateEnergyQPE.rst +++ b/documentation/source/reference/Examples/GroundStateEnergyQPE.rst @@ -5,10 +5,24 @@ Ground State Energy with QPE .. currentmodule:: qrisp + +For a given Hamiltonian $H$ and an eigenstate $\ket{\lambda_j}$ (e.g., the ground state $\ket{\lambda_0}$), the goal is to find the eigenvalue $E_j$ such that + +$$e^{iH}\\ket{\\lambda_j} = e^{iE_j}\\ket{\\lambda_j}$$ + +This is achieved by applying quantum phase estimation to the unitary $U=e^{iH}$ with the initial state $\ket{\lambda_j}$. +With the equation $e^{iE_j}=e^{2\pi i\theta_j}$, the energy $E_j$ can be calculated from the resulting phase $\theta_j\in [0,1)$. +In practice, the exact eigenstate $\lambda_j$ is unknown, and one uses an approximation $\ket{\psi_0}$ which can be expressed in the eigenbasis of the Hamiltonian as + +$$\\ket{\\psi_0}=\\sum_j a_j\\ket{\\lambda_j}$$ + +If the approximation $\ket{\psi_0}$ is sufficently close to the eigenstate $\ket{\lambda_j}$, the correct phase, and hence the eigenvalue $E_j$, is obtained with high probability. + + Example Hydrogen ================ -We caluclate the ground state energy of the Hydrogen molecule with :ref:`Quantum Phase Estimation `. +We caluclate the ground state energy of the electronic Hamiltonian for the Hydrogen molecule with :ref:`Quantum Phase Estimation `. Utilizing symmetries, one can find a reduced two qubit Hamiltonian for the Hydrogen molecule. Frist, we define the Hamiltonian, and compute the ground state energy classically. @@ -16,16 +30,16 @@ ground state energy classically. :: from qrisp import QuantumVariable, x, QPE - from qrisp.operators.pauli.pauli import X,Y,Z + from qrisp.operators import X,Y,Z import numpy as np # Hydrogen (reduced 2 qubit Hamiltonian) H = -1.05237325 + 0.39793742*Z(0) -0.39793742*Z(1) -0.0112801*Z(0)*Z(1) + 0.1809312*X(0)*X(1) E0 = H.ground_state_energy() + print(E0) # Yields: -1.85727502928823 -In the following, we utilize the ``trotterization`` method of the :ref:`QubitOperator` to obtain a function **U** that applies **Hamiltonian Simulation** -via Trotterization. If we start in a state that is close to the ground state and apply :ref:`QPE`, we get an estimate of the ground state energy. +The $\ket{10}$ state provides a good approximation of the ground state: :: @@ -33,15 +47,16 @@ via Trotterization. If we start in a state that is close to the ground state and qv = QuantumVariable(2) x(qv[0]) E1 = H.get_measurement(qv) - E1 + print(E1) # Yields: -1.83858104676077 - -We calculate the ground state energy with quantum phase estimation. As the results of the phase estimation are modulo :math:`2\pi`, we subtract :math:`2\pi`. +In the following, we utilize the :meth:`trotterization ` method of the :ref:`QubitOperator` to obtain a function **U** that applies **Hamiltonian Simulation** +via Trotterization. If we start in a state that is close to the ground state and apply :ref:`QPE`, we get an estimate of the ground state energy. +As the results of the phase estimation are modulo :math:`2\pi` and the searched for eigenvalue is between $-2\pi$ and 0, we subtract :math:`2\pi`. :: - U = H.trotterization() + U = H.trotterization(forward_evolution=False) qpe_res = QPE(qv,U,precision=10,kwargs={"steps":3},iter_spec=True) @@ -50,5 +65,5 @@ We calculate the ground state energy with quantum phase estimation. As the resul phi = list(sorted_results.items())[0][0] E_qpe = 2*np.pi*(phi-1) # Results are modulo 2*pi, therefore subtract 2*pi - E_qpe + print(E_qpe) # Yields: -1.8591847149174 \ No newline at end of file