Variational Quantum Eigensolver from Scratch: Finding ground-state energy of Hamiltonian

Pratik Ingle
Analytics Vidhya
Published in
5 min readJan 4, 2021

--

source : google images

Finding Ground-state energy of Hamiltonian

Variational quantum eigensolver:

It works on variational principal which say if we have a Hamiltonian H with eigenstates and associated eigenvalues . Then the following relation holds:

𝐻|𝜓⟩=𝜆|𝜓⟩H|ψ⟩=λ|ψ⟩

where λ is energy value for given state |ψ⟩. for every different |ψ⟩ we can find its energy, but for only one |ψ⟩ there exist λ which is smallest of all, and we call that |ψ⟩ as groung state of the system. and VQE helps us to find groung state of any given system. to make process simpler it decompose Hamiltonians into Pauli-Matrices. Resourse.

Fig 1.Flowchart of VQE.

VQE can be sum up in three parts

  1. Decomposition
  2. Circuit
  • Ansatz
  • Initializing measurement basis

3. Measurement

Part 1 : Decomposition

Decomposing two-qubit Hamiltonians into Pauli-Matrices
Pauli-Matrices form a basis for the real vector space of 2 × 2 Hermitian matrices. This means that any 2 × 2 Hermitian matrix can be written uniquely as a linear combination of Pauli matrices, with all coefficients being real numbers. these Pauli terms (σ1, σx, σy, σz) tells us on which basis we should measure our qubits, and their coefficient tell us by how many factors we should consider their expectation values in the end.

For a two qubit Hamiltonian or 4 × 4 Hermitian matrices

Where,

Given Hermitian matrix H can be written as

Part 2 : Circuit

Once we have the decomposition of Hamiltonian, we can create circuits for each term in decomposition.
Circuit mainly consists of Ansatz, it prepares the state we need to get measurements. we will find the Ansatz by trial and error.
since QC always measures in Z basis, we need to Initializing measurement basis, in our Two-Qubit Hamiltonian H, we have four terms from decomposition (σ1⊗σ1),(σ𝑥⊗σ𝑥),(σ𝑦⊗σ𝑦),σ𝑧⊗σ𝑧) with coefficients 1/2,−1/2,−1/2, 1/2 respectively.

If we Take first term (σ1⊗σ1), it represent identity operation on both first and second qubit, since it’s identity operation so we don’t need any circuit for this, we just need to take it’s coefficient in account in final summation.
Second term (σ𝑥⊗σ𝑥) has σx operation on both qubits, so to do a measurement along X basis, we need to rotate Bloch sphere around Y axis by -π/2 degree for qubits. similarly, for the third term (σ𝑦⊗σ𝑦) we will rotate the Bloch sphere by π/2 degree around X-axis for both qubits to make measurements along Y Basis. measurement along Z-axis does not need any rotation since QC always measures in Z basis. so fourth term (σ𝑧⊗σ𝑧) will only consist of Ansatz. now lets code Ansatz.

Ansatz

looking into ansatz circuit:

fig 1. Ansatz

creating circuits for each terms of Hamiltonian decomposition

Second Terms (σ𝑥⊗σ𝑥) : Circuit 1

Fig 2. Circuit for XX term

Third Term (σ𝑦⊗σ𝑦): Circuit 2

Fig 3. Circuit for YY term

Fourth Terms (σ𝑧⊗σ𝑧): Circuit 3

Fig 4. Circuit for ZZ term

Part 3: Measurements

Now for measurement, we will find expectation values for each circuit. Measurement of each circuit will consist of probabilities of four terms |00>, |01>, |10>, |11>. for single-qubit we consider eigenvalues of measurements, if we found our system in |0> state in measurement then we take it as 1, and if it’s in |1> then we take it as -1, wince those are their eigenvalues. But for two-qubit measurements, if our measurements are |01> means first qubit collapse in 0 state and second in 1 state, then we take multiplication of their eigenvalues 1 x -1 = -1 we can take it as a sign, similarly, we can do for other measurements.

Fig 4. Measurements

we can calculate the expectation value as ∑(𝑠𝑖𝑔𝑛).(𝑃) , where P is the probability of measurement once we have expectation values of each circuit we then add them together with their respective coefficients which we got from the decomposition step to calculate the final eigenvalue. for given H and from it decomposition we can get eigenvalue,

VQE Algorithm

the lowest eigenvalue we got is -1 which belongs to the state

Looking into eigenvalue evolution with parameter

fig 5. Results
fig 6. eigenvalue of parameters

End Note

Ansatz was chosen by trial and error.
some of the ansatz results

fig 7. Eigenvalues of different Ansatzs

Other Ansatzs with multiple parameters such as (U3I)(cx01)(HI) also perform similarly, in this case, it gave results was 0.0016

Resources

Have fun, keep learning..

My Twitter and GitHub

--

--