Subspace-search variational quantum eigensolver for excited states

image

In Variational Quantum Eigensolver (VQE), the real parameters $\theta$ for the ansatz states $|\psi \left( \theta \right) \rangle $ are classically optimised with respect to the expectation value of the Hamiltonian in the equation ; it is computed using a lowdepth quantum circuit. As a result of the variational principle, finding the global minimum of $E\left( \theta \right) $ is equivalent to finding the ground state energy of $H$

In this section, our goal is to extend to calculate find excited states from HEA ansatz model, using subspace-search VQE (SSVQE). The SSVQE takes two or more orthogonal states as inputs to a parametrized quantum circuit, and minimizes the expectation value of the energy in the space spanned by those states. In this work, the proposed algorithm can find the $k$-th excited state state that works on an $n$-qubit quantum computer; SSVQE runs as follows:

Algorithm

  1. Construct an ansatz circuit \( U(\bm{\theta}) \) and choose input states \( \left\{ \ket{\varphi_j} \right\}_{j=0}^k \) whic

  2. Minimize

    \[ \mathcal{L}_1(\bm{\theta}) = \sum_{j=0}^k \langle \varphi_{j} | U^\dagger(\bm{\theta}) H U(\bm{\theta}) | \varphi_{j} \rangle. \]

    We denote the optimal \( \bm{\theta} \) by \( \bm{\theta}^* \).

  3. Construct another parametrized quantum circuit \( V(\bm{\phi}) \) that only acts on the space spanned by \( \left\{ \ket{\varphi_j} \right\}_{j=0}^k \).

  4. Choose an arbitrary index \( s \in \{0, \ldots, k\} \), and maximize

    \[ \mathcal{L}_2(\bm{\phi}) = \langle \varphi_{s} | V^\dagger(\bm{\phi}) U^\dagger(\bm{\theta}^*) H U(\bm{\theta}^*) V(\bm{\phi}) | \varphi_{s} \rangle. \]

    We note that, in practice, the input states \( \left\{ \ket{\varphi_j} \right\}_{j=0}^k \) will be chosen from a set of states which are easily preparable, such as the computational basis (in our work, we use the binary representation technique for generating the basis). Additionally, in step 2, we can find the subspace which includes \( \ket{E_k} \) as the highest energy state, using a carefully constructed ansatz $U(\boldsymbol{\theta})$. The unitary \( V(\bm{\phi}) \) is responsible for searching in that subspace. By maximizing \( \mathcal{L}_2(\bm{\phi}) \), we find the \( k \)-th excited state \( \ket{E_k} \).

A particular instance of the “hardware-efficient ansatz” - the entanglement pattern with 6 CX gates and depth = 1 is shown. The parameters $\boldsymbol{\theta}$ are optimized to to minimize the cost function $\mathcal{L}_{1}$ then the ansatz structure will be updated the parameters, called $\boldsymbol{\phi }$ thus to optimize $\mathcal{L}_{2}$

image

 1import numpy as np
 2import scipy.optimize
 3import matplotlib.pyplot as plt
 4from numpy import binary_repr
 5from qat.qpus import get_default_qpu
 6
 7qpu = get_default_qpu()
 8method = "BFGS"
 9model = hamiltonian_sp
10vals = 15
11
12eigenvec_input_tar = calculate_eigen_vectors(model, vals)
13eigenvec_input = [eigenvec_input_tar[2],eigenvec_input_tar[8], eigenvec_input_tar[13]] 
14
15
16energy_lists = {f"energy_circ_{i}": {method: []} for i in range(len(circuits_store))}
17fidelity_lists = {f"fidelity_circ_{i}": {method: []} for i in range(len(circuits_store))}
18
19def opt_funct(circuits, model, qpu, nqbits, energy_lists, fidelity_lists, weight, eigenvec_input):
20    def input_funct(x):
21        total_energy = 0
22        for i, circ in enumerate(circuits):
23            bound_circ = circ.bind_variables({k: v for k, v in zip(sorted(circ.get_variables()), x)})
24            result = qpu.submit(bound_circ.to_job(observable=model))
25            energy = result.value
26            energy_lists[f"energy_circ_{i}"][method].append(energy)
27
28            # Calculate fidelity
29            fidelity = fun_fidelity(bound_circ, eigenvec_input[i], nqbits)
30            fidelity_lists[f"fidelity_circ_{i}"][method].append(fidelity)
31            #print(fidelity)
32
33            total_energy += weight[i] * energy
34        return total_energy
35
36    def callback(x):
37        for i, circ in enumerate(circuits):
38            bound_circ = circ.bind_variables({k: v for k, v in zip(sorted(circ.get_variables()), x)})
39            result = qpu.submit(bound_circ.to_job(observable=model))
40            energy = result.value
41            energy_lists[f"energy_circ_{i}"][method].append(energy)
42
43            # Calculate fidelity
44            fidelity = fun_fidelity(bound_circ, eigenvec_input[i], nqbits)
45            fidelity_lists[f"fidelity_circ_{i}"][method].append(fidelity)
46
47    return input_funct, callback
48
49
50input_funct, callback = opt_funct(circuits_store, model, qpu, nqbits, energy_lists, fidelity_lists, weight, eigenvec_input)
51options = {"disp": True, "maxiter": 5000, "gtol": 1e-7}
52Optimizer = scipy.optimize.minimize(input_funct, x0=init_theta_list, method=method, callback=callback, options=options)
53
54# Plot energy
55plt.rcParams["font.size"] = 18
56all_energy_lists = []
57
58for i in range(len(circuits_store)):
59    energy_list = energy_lists[f"energy_circ_{i}"][method]
60    all_energy_lists.append(energy_list)
61    plt.plot(range(len(energy_list)), energy_list, label=f"Energy for k={binary_repr(k_lst[i]).zfill(4)}")
62
63    # Print the final energy for each k
64    final_energy = energy_list[-1]
65    print(f"Final energy for k={binary_repr(k_lst[i]).zfill(4)}: {final_energy}")
66
67plt.xlabel("Iterations")
68plt.ylabel("Energy")
69plt.title("Energy Evolution")
70plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0, fontsize=18)
71plt.show()
72
73
74
75
76# Plot fidelity
77plt.figure()
78all_fidelity_lists = []
79
80for i in range(len(circuits_store)):
81    fidelity_list = fidelity_lists[f"fidelity_circ_{i}"][method]
82    all_fidelity_lists.append(fidelity_list)
83    plt.plot(range(len(fidelity_list)), fidelity_list, label=f"Fidelity for k={binary_repr(k_lst[i]).zfill(4)}")
84
85    # Print the final fidelity for each k
86    final_fidelity = fidelity_list[-1]
87    print(f"Final fidelity for k={binary_repr(k_lst[i]).zfill(4)}: {final_fidelity}")
88
89plt.xlabel("Iterations")
90plt.ylabel("Fidelity")
91plt.title("Fidelity Evolution")
92plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0, fontsize=18)
93plt.show()

We implement the SSVQE on the molecular Hamiltonians such as H$_2$ molecule ( with a fixed distance between two hydrogen atoms $r=0.85 $ at the STO-3G minimal basis set. We choose our own weight (W) for the minimization; We obtain accurate energies with height fidelity rate $\left[ 0,978\longrightarrow 0,998 \right] $. Meaning that the algorithms assures assures the orthogonality of the states at the input of the ansatz circuit

image

The energy levels of the Hamiltonian of H$_2$ in the STO-3g basis set: four qubits. The fidelity is close to one. It is the Overlap $\langle\Psi_j(\vec{\theta}) |\Psi_{k}\rangle$ between the computed VQE state at each optimization step $j$ and the theoretical ground (or excited) state $|\Psi_{k}\rangle$ of Hamiltonian $H$, where $|\Psi_{k}\rangle$ is obtained through diagonalization.

References

Nakanishi, Ken M., Kosuke Mitarai, and Keisuke Fujii. "Subspace-search variational quantum eigensolver for excited states." Physical Review Research 1.3 (2019): 033062.

About the Author

Author's Photo
Huy Binh TRAN
Master 2 Quantum Devices at Institute Paris Polytechnic, France
LinkedIn