Diese Seite wurde noch nicht übersetzt. Sie sehen die englische Originalversion.
SQD for energy estimation of a chemistry Hamiltonian
In this lesson, we will apply SQD to estimate the ground state energy of a molecule.
In particular, we will discuss the following topics using the -step Qiskit pattern approach:
- Step 1: Map problem to quantum circuits and operators
- Setup the molecular Hamiltonian for .
- Explain the chemistry-inspired and hardware-friendly local unitary cluster Jastrow (LUCJ) [1]
- Step 2: Optimize for target hardware
- Optimize gate counts and layout of the ansatz for hardware execution
- Step 3: Execute on target hardware
- Run the optimized circuit on a real QPU to generate samples of the subspace.
- Step 4: Post-process results
- Introduce the self-consistent configuration recovery loop [2]
- Post-process the full set of bitstring samples, using prior knowledge of particle number and the average orbital occupancy calculated on the most recent iteration.
- Probabilistically create batches of subsamples from recovered bitstrings.
- Project and diagonalize the molecular Hamiltonian over each sampled subspace.
- Save the minimum ground state energy found across all batches and update the avg orbital occupancy.
- Introduce the self-consistent configuration recovery loop [2]
We will use several software packages throughout the lesson.
PySCFto define the molecule and setup the Hamiltonian.ffsimpackage to construct the LUCJ ansatz.Qiskitfor transpiling the ansatz for hardware execution.Qiskit IBM Runtimeto execute the circuit on a QPU and collect samples.Qiskit addon SQDconfiguration recovery and ground state energy estimation using subspace projection and matrix diagonalization.
1. Map problem to quantum circuits and operators
Molecular Hamiltonian
A molecular Hamiltonian takes the generic form:
/ are the fermionic creation/annihilation operators associated to the -th basis set element and the spin . and are the one- and two-body electronic integrals. Using pySCF, we will define the molecule and compute the one- and two-body integrals of the Hamiltonian for basis set 6-31g.
# Added by doQumentation — required packages for this notebook
!pip install -q ffsim matplotlib numpy pyscf qiskit qiskit-addon-sqd qiskit-ibm-runtime
import warnings
import pyscf
import pyscf.cc
import pyscf.mcscf
warnings.filterwarnings("ignore")
# Specify molecule properties
open_shell = False
spin_sq = 0
# Build N2 molecule
mol = pyscf.gto.Mole()
mol.build(
atom=[["N", (0, 0, 0)], ["N", (1.0, 0, 0)]], # Two N atoms 1 angstrom apart
basis="6-31g",
symmetry="Dooh",
)
# Define active space
n_frozen = 2
active_space = range(n_frozen, mol.nao_nr())
# Get molecular integrals
scf = pyscf.scf.RHF(mol).run()
num_orbitals = len(active_space)
n_electrons = int(sum(scf.mo_occ[active_space]))
num_elec_a = (n_electrons + mol.spin) // 2
num_elec_b = (n_electrons - mol.spin) // 2
cas = pyscf.mcscf.CASCI(scf, num_orbitals, (num_elec_a, num_elec_b))
mo = cas.sort_mo(active_space, base=0)
hcore, nuclear_repulsion_energy = cas.get_h1cas(mo) # hcore: one-body integrals
eri = pyscf.ao2mo.restore(1, cas.get_h2cas(mo), num_orbitals) # eri: two-body integrals
# Compute exact energy for comparison
exact_energy = cas.run().e_tot
converged SCF energy = -108.835236570774
CASCI E = -109.046671778080 E(CI) = -32.8155692383188 S^2 = 0.0000000
In this lesson, we will use Jordan-Wigner (JW) transformation to map a fermionic wavefunction to a qubit wavefunction so that it can be prepared using a quantum circuit. The JW transformation maps the Fock space of fermions in M spatial orbitals onto the Hilbert space of 2M qubits, that is, a spatial orbital is split into two spin orbitals, one associated with a spin up () electron and another with spin down (). A spin orbital can be occupied or unoccupied. Usually, when we refer to number of orbitals, we will be using number of spatial orbitals. The number of spin orbitals will be double. In quantum circuits, we will represent each spin orbital with one qubit. Thus, a set of qubits will represent spin-up or -orbitals, and another set will represent spin-down or -orbitals. For example, molecule for 6-31g basis set has spatial orbitals (that is, + = spin orbitals). Thus, we will need a -qubit quantum circuit (we may need extra ancilla qubits as discussed later). The qubits are measured in computational basis to generate bitstrings, which represent electronic configurations or (Slater) determinants. Throughout this lesson, we will use the terms bitstrings, configurations, and determinants interchangeably. The bitstrings tell us electron occupancy in spin orbitals: a in a bit position means the corresponding spin orbital is occupied, while a means the spin orbital is empty. As electronic structure problems are particle preserving, only a fixed number of spin orbitals must be occupied. The molecule has spin-up () and spin-down () electrons. Thus, any bitstring representing the and orbitals must have five each for molecule.
1.1 Quantum circuit for sample generation: The LUCJ ansatz
In this lesson, we will use the local unitary coupled cluster Jastrow (LUCJ) \[1\] ansatz for quantum state preparation and subsequent sampling. First, we will explain different building blocks of the full UCJ ansatz and the approximations made in the local version of it. Next, by using ffsim package, we will construct the LUCJ ansatz and optimize it using Qiskit transpiler for hardware execution.
The UCJ ansatz has the following form (for a product of layers or repetitions of the UCJ operator.)
where, is a reference state, typically taken as the Hartree-Fock (HF) state. As the Hartree-Fock state is defined as having the lowest numbered orbitals occupied, the HF state preparation will involve applying X gates to set qubits corresponding to occupied orbitals to one. For example, the HF state preparation block for 4 spatial orbitals and 2 up- and 2 down-spin may look like the following:
A single repetition of the UCJ operator consists of a diagonal Coulomb evolution () sandwiched by orbital rotations ( and ).
Orbital rotation blocks work on a single spin species ( (up-spin)/ (down-spin)). For each electron species, orbital rotation consists of a layer of single-qubit gates followed by a sequence of 2-qubit Given's rotation gates ( gates).
The 2-qubit gates act on adjacent spin-orbitals (nearest neighbor qubits), and therefore, are implementable on IBM® QPUs without the need for SWAP gates.
The , also known as the diagonal Coulomb operator, consists of three blocks. Two of them work on same spin sectors ( and ), and one works between two spin sectors ().
All the blocks in consists of number-number gates [1]. A gate can be further broken down into a gate followed by two single-qubit gates acting on two separate qubits.
Same-spin components ( and ) have gates between all possible pairs of qubits. However, as superconducting QPUs have restrictive connectivity, qubits must be swapped to realize gates between non-adjacent qubits.
For example, consider the following (or ) block for spatial orbitals. For a linear qubit connectivity, the last three gates are not directly implementable as they work between non-adjacent qubits (for example, Q0 and Q2 are not directly connected). Therefore, we need SWAP gates to make them adjacent (following figure shows an example with SWAP gates).
Next, the implements gates between same indexed orbitals from different spin sectors (for example, between and ). Similarly, if the qubits are not physically adjacent on a QPU, these gates will also require SWAPs.
From the above discussion, the UCJ ansatz faces some hurdles for HW execution as it needs SWAP gates due to non-adjacent qubit interactions. The local variant of the UCJ ansatz, LUCJ, addresses this challenge by removing some from the diagonal Coulomb operator.
In the same electron species blocks, and ), we only keep the gates compatible with nearest-neighbor connectivity and remove gates between non-adjacent qubits in the LUCJ version. Following figure shows the LUCJ block after removal of non-adjacent gates.
Next, the LUCJ version of the block that works between different electron species can take different shape based on the device topology.
Here, also, the LUCJ version gets rid of non-compatible gates. The figure below shows variants of the block for different qubit topology including grid, hexagonal, heavy-hex, and linear.
- Square: we can have gates between all and orbitals without any SWAPs, and therefore, do not need to remove any gates.
- Heavy-hex: The - interactions are kept between every -th indexed (such as the 0th, 4th, and 8th) spin orbitals and are ancilla mediated, that is, we need ancilla qubits between the linear chains representing and orbitals. This arrangement needs a limited number of SWAPs.
- Hexagonal: Every other orbital, such as 0th, 2nd, and 4th indexed orbitals, becomes nearest neighbors when and