Quantum Subspace Expansion AlgorithmQSE

The Quantum Subspace Expansion (QSE) obtains extra correlation and energetics of excited states, on top of the VQE ground state \(|\Psi_{\mathrm{VQE}}\rangle\) by doing a linear excitation expansion as [15]

(16)\[|\Psi_{\mathrm{QSE}} \rangle = \sum_{i > j} c_{ij} |\psi_{ij}\rangle\]

where

(17)\[|\psi_{ij}\rangle = a^\dagger_i a_j |\Psi_{\mathrm{VQE}} \rangle\]

and \(c_{ij}\) are the complex coefficients.

If \(|\Psi_{\mathrm{VQE}}\rangle\) is a correlated state, the basis functions of the subspace generated by applying the excitation operators are not orthogonal in general. The optimal solution for the ground and excited states within this subspace can be found by solving the generalized eigenvalue problem expressed as

(18)\[HC = SCE\]

where \(H\) is the Hamiltonian matrix and \(S\) is the overlap matrix in this subspace. \(E\) is the diagonal matrix of eigenvalues and \(C\) is the matrix of eigenvectors. The matrix elements of \(H\) and S are evaluated by quantum computers as

(19)\[H_{ij,kl} = \langle \psi_{ij} | \hat{H} | \psi_{kl} \rangle\]
(20)\[S_{ij,kl} = \langle \psi_{ij} | \psi_{kl} \rangle\]

And the eigenstates \(C\) and \(E\) are obtained with classical diagonalization.

AlgorithmQSE is a high level interface of InQuanto to run the QSE algorithm for given qubit operator and ansatz with optimal parameters to evaluate the eigenstates. We take the minimal basis hydrogen molecule as an example to calculate the spin-adapted excited states from the VQE state with UCCSD ansatz.

The first step is constructing the molecular Hamiltonian and the Fock state in fermion objects.

from inquanto.express import get_system
hamiltonian, fermion_space, fermion_state = get_system("h2_sto3g.h5")

And then map them into the qubit objects. Here we use the UCCSD ansatz and then address the excited states with QSE, but one can use a cheaper ansatz for the VQE and obtain the extra correlation at the later QSE step, through the linear expansion and matrix diagonalization.

from inquanto.mappings import QubitMappingJordanWigner
from inquanto.ansatzes import FermionSpaceAnsatzUCCSD

jw = QubitMappingJordanWigner()
qubit_hamiltonian = jw.operator_map(hamiltonian)
ansatz = FermionSpaceAnsatzUCCSD(fermion_space, fermion_state, qubit_mapping=jw)

Subsequently, we need to define the subspace in which to solve the generalized eigenvalue equations; namely the set of expansion operators to be applied to our ground state.

expansion_operators = jw.operator_map(
    fermion_space.generate_subspace_singlet_singles()
)

Note that we use singlet single excitation operators \(E_{ij} = \sum_{\sigma}^{\mathrm{spin}}a_{i\sigma}^{\dagger}a_{j\sigma}\) to span the spin-adapted subspace. We then define a new Computable object for the \(H\) and \(S\) matrices in Eq. (18), using the QSEMatricesComputable class. This computable and the values of the parameters of the ansatz are then passed to AlgorithmQSE. In general we first need to perform a VQE calculation to obtain the optimized values of the parameters of the ansatz. In this specific example, we already know them from the previous VQE example (see in AlgorithmVQE), so we provide the values as an array.

from inquanto.computables.composite import QSEMatricesComputable
from inquanto.algorithms import AlgorithmQSE

vqe_parameters = ansatz.state_symbols.construct_from_array(
    [0.0, 0.0, -0.107233493519281]
)

computable = QSEMatricesComputable(
    state=ansatz,
    hermitian_operator=qubit_hamiltonian,
    expansion_operators=expansion_operators,
)

algorithm = AlgorithmQSE(
    computable_qse_matrices=computable,
    parameters=vqe_parameters,
)

The following procedure is basically the same as the examples above, but we use a shot-based protocol. No solver is required, as it is a non-variational method.

from inquanto.protocols import PauliAveraging
from pytket.extensions.qiskit import AerBackend

protocol_expression = PauliAveraging(AerBackend(), shots_per_circuit=2000)

algorithm.build(
    protocol=protocol_expression
)

algorithm.run()
print(algorithm.generate_report())
# TIMER Measure and calculate H and S matrix element BEGINS AT 2024-10-30 18:12:36.743380
# TIMER Measure and calculate H and S matrix element ENDS - DURATION (s):  1.0918247 [0:00:01.091825]
# TIMER Solve HC=CSE BEGINS AT 2024-10-30 18:12:37.835328
# TIMER Solve HC=CSE ENDS - DURATION (s):  0.0007245 [0:00:00.000724]
{'final_value': array([-1.273, -1.108, -0.136,  0.618]), 'final_states': array([[ 0.797 -0.141j, -0.251 -0.481j,  0.025 +0.004j, -0.489 -0.015j],
       [14.26  -0.878j, -3.658 +0.221j,  0.315 +0.024j, -8.61  +0.369j],
       [-0.01  -0.415j,  0.001 +0.067j, -0.706 -0.076j, -0.052 +0.875j],
       [-0.075 -7.j   ,  0.053 +1.797j, -0.039 -1.424j,  0.518+15.378j]])}

The eigenvalues and eigenvectors are stored as final_value and the final_states, respectively. Numerical instabilities in the matrix diagonalization are handled by removing near linear dependencies in the basis.