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-09-23 17:04:29.191267
# TIMER Measure and calculate H and S matrix element ENDS - DURATION (s):  1.1152475 [0:00:01.115247]
# TIMER Solve HC=CSE BEGINS AT 2024-09-23 17:04:30.306636
# TIMER Solve HC=CSE ENDS - DURATION (s):  0.0009795 [0:00:00.000980]
{'final_value': array([-1.119, -0.432, -0.134]), 'final_states': array([[-0.498 -0.006j, -0.107 -0.001j, -0.009 +0.005j],
       [ 0.082 +0.012j, -2.106 -0.379j, -0.136 -0.023j],
       [-0.023 +0.015j, -0.355 -0.487j,  0.33  -0.647j],
       [ 0.176 +0.325j, -6.286-11.674j, -0.432 -0.74j ]])}

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.