Sparse#
SELECT and PREPARE for the second quantized sparse chemistry Hamiltonian.
Starting from the traditional second quantized chemistry Hamiltonian
from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register
from qualtran import QBit, QInt, QUInt, QAny
from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma
from typing import *
import numpy as np
import sympy
import cirq
PrepareSparse
#
Prepare oracle for the sparse chemistry Hamiltonian
Prepare the state:
Parameters#
num_spin_orb
: The number of spin orbitals.num_non_zero
: The number of non-zero matrix elements.num_bits_state_prep
: the number of bits of precision for state preparation. This will control the size of the keep register.num_bits_rot_aa
: The number of bits of precision for the single-qubit rotation for amplitude amplification during the uniform state preparation. Default 8.is_adjoint
: Whether we are apply PREPARE or PREPARE^daglog_block_size
: qroam (log) block size.
Registers#
d
: the register indexing non-zero matrix elements.pqrs
: the register to store the spatial orbital index.sigma
: the register prepared for alias sampling.alpha
: spin for (pq) indicies.beta
: spin for (rs) indicies.rot_aa
: the qubit rotated for amplitude amplification.swap_pq
: a |+> state to restore the symmetries of the p and q indices.swap_rs
: a |+> state to restore the symmetries of the r and s indices.swap_pqrs
: a |+> state to restore the symmetries of between (pq) and (rs).theta
: sign qubit.alt_pqrs
: the register to store the alternate values for the spatial orbital indices.theta
: A two qubit register for the sign bit and it’s alternate value.keep
: The register containing the keep values for alias sampling.less_than
: A single qubit for the result of the inequality test during alias sampling.flag_1b
: a single qubit register indicating whether to apply only the one-body SELECT.alt_flag_1b
: alternate value for flag_1b
Refererences: Even More Efficient Quantum Computations of Chemistry Through Tensor hypercontraction Eq. A11.
from qualtran.bloqs.chemistry.sparse import PrepareSparse
Example Instances#
from qualtran.bloqs.chemistry.sparse.prepare_test import build_random_test_integrals
num_spin_orb = 6
tpq, eris = build_random_test_integrals(num_spin_orb // 2)
prep_sparse = PrepareSparse.from_hamiltonian_coeffs(
num_spin_orb, tpq, eris, num_bits_state_prep=4, log_block_size=1
)
Graphical Signature#
from qualtran.drawing import show_bloqs
show_bloqs([prep_sparse],
['`prep_sparse`'])
Call Graph#
from qualtran.resource_counting.generalizers import ignore_split_join
prep_sparse_g, prep_sparse_sigma = prep_sparse.call_graph(max_depth=1, generalizer=ignore_split_join)
show_call_graph(prep_sparse_g)
show_counts_sigma(prep_sparse_sigma)
Counts totals:
CSwap
: 1CSwap
: 8H
: 3H⨂4
: 1LessThanEqual
: 1PrepareUniformSuperposition
: 1QROAMClean
: 1
SelectSparse
#
SELECT oracle for the sparse Hamiltonian.
Implements the two applications of Fig. 13.
Parameters#
num_spin_orb
: The number of spin orbitals. Typically called N.control_val
: The control value. If None, then the bloq is not controlled.
Registers#
flag_1b
: a single qubit to flag whether the one-body Hamiltonian is to be applied or not during SELECT.swap_pq
: a |+> state to restore the symmetries of the p and q indices.swap_rs
: a |+> state to restore the symmetries of the r and s indices.swap_pqrs
: a |+> state to restore the symmetries of between (pq) and (rs).theta
: sign qubit.pqrs
: the register to store the spatial orbital index.alpha
: spin for (pq) indicies.beta
: spin for (rs) indicies.
Refererences: Even More Efficient Quantum Computations of Chemistry Through Tensor hypercontraction Fig 13.
from qualtran.bloqs.chemistry.sparse import SelectSparse
Example Instances#
num_spin_orb = 4
sel_sparse = SelectSparse(num_spin_orb)
Graphical Signature#
from qualtran.drawing import show_bloqs
show_bloqs([sel_sparse],
['`sel_sparse`'])
Call Graph#
from qualtran.resource_counting.generalizers import ignore_split_join
sel_sparse_g, sel_sparse_sigma = sel_sparse.call_graph(max_depth=1, generalizer=ignore_split_join)
show_call_graph(sel_sparse_g)
show_counts_sigma(sel_sparse_sigma)
Counts totals:
S
: 1SelectedMajoranaFermion(X)
: 1SelectedMajoranaFermion(X)
: 1SelectedMajoranaFermion(Y)
: 1SelectedMajoranaFermion(Y)
: 1