qml.resource.DoubleFactorization¶

class
DoubleFactorization
(one_electron, two_electron, error=0.0016, rank_r=None, rank_m=None, rank_max=None, tol_factor=1e05, tol_eigval=1e05, br=7, alpha=10, beta=20, chemist_notation=False)[source]¶ Bases:
pennylane.operation.Operation
Estimate the number of nonClifford gates and logical qubits for a quantum phase estimation algorithm in second quantization with a doublefactorized Hamiltonian.
Atomic units are used throughout the class.
 Parameters
one_electron (array[array[float]]) – oneelectron integrals
two_electron (tensor_like) – twoelectron integrals
error (float) – target error in the algorithm
rank_r (int) – rank of the first factorization of the twoelectron integral tensor
rank_m (int) – average rank of the second factorization of the twoelectron integral tensor
tol_factor (float) – threshold error value for discarding the negligible factors
tol_eigval (float) – threshold error value for discarding the negligible factor eigenvalues
br (int) – number of bits for ancilla qubit rotation
alpha (int) – number of bits for the keep register
beta (int) – number of bits for the rotation angles
chemist_notation (bool) – if True, the twoelectron integrals need to be in chemist notation
Example
>>> symbols = ['O', 'H', 'H'] >>> geometry = np.array([[0.00000000, 0.00000000, 0.28377432], >>> [0.00000000, 1.45278171, 1.00662237], >>> [0.00000000, 1.45278171, 1.00662237]], requires_grad = False) >>> mol = qml.qchem.Molecule(symbols, geometry, basis_name='sto3g') >>> core, one, two = qml.qchem.electron_integrals(mol)() >>> algo = DoubleFactorization(one, two) >>> print(algo.lamb, # the 1Norm of the Hamiltonian >>> algo.gates, # estimated number of nonClifford gates >>> algo.qubits # estimated number of logical qubits >>> ) 53.62085493277858 103969925 290
Theory
To estimate the gate and qubit costs for implementing this method, the Hamiltonian needs to be factorized using the
factorize()
function following [PRX Quantum 2, 030305 (2021)]. The objective of the factorization is to find a set of symmetric matrices, \(L^{(r)}\), such that the twoelectron integral tensor in chemist notation, \(V\), can be computed as\[V_{ijkl} = \sum_r^R L_{ij}^{(r)} L_{kl}^{(r) T},\]with the rank \(R \leq n^2\), where \(n\) is the number of molecular orbitals. The matrices \(L^{(r)}\) are diagonalized and for each matrix the eigenvalues that are smaller than a given threshold (and their corresponding eigenvectors) are discarded. The average number of the retained eigenvalues, \(M\), determines the rank of the second factorization step. The 1norm of the Hamiltonian can then be computed using the
norm()
function from the electron integrals and the eigenvalues of the matrices \(L^{(r)}\).The total number of gates and qubits for implementing the quantum phase estimation algorithm for the given Hamiltonian can then be computed using the functions
gate_cost()
andqubit_cost()
with a target error that has the default value of 0.0016 Ha (chemical accuracy). The costs are computed using Eqs. (C39C40) of [PRX Quantum 2, 030305 (2021)].Attributes
Methods
estimation_cost
(lamb, error)Return the number of calls to the unitary needed to achieve the desired error in quantum phase estimation.
gate_cost
(n, lamb, error, rank_r, rank_m, …)Return the total number of Toffoli gates needed to implement the double factorization algorithm.
norm
(one, two, eigvals)Return the 1norm of a molecular Hamiltonian from the one and twoelectron integrals and eigenvalues of the factorized twoelectron integral tensor.
qubit_cost
(n, lamb, error, rank_r, rank_m, …)Return the number of logical qubits needed to implement the double factorization method.
unitary_cost
(n, rank_r, rank_m, rank_max[, …])Return the number of Toffoli gates needed to implement the qubitization unitary operator for the double factorization algorithm.

static
estimation_cost
(lamb, error)[source]¶ Return the number of calls to the unitary needed to achieve the desired error in quantum phase estimation.
The expression for computing the cost is taken from Eq. (45) of [PRX Quantum 2, 030305 (2021)].
 Parameters
lamb (float) – 1norm of a secondquantized Hamiltonian
error (float) – target error in the algorithm
 Returns
number of calls to unitary
 Return type
int
Example
>>> lamb = 72.49779513025341 >>> error = 0.001 >>> estimation_cost(lamb, error) 113880

static
gate_cost
(n, lamb, error, rank_r, rank_m, rank_max, br=7, alpha=10, beta=20)[source]¶ Return the total number of Toffoli gates needed to implement the double factorization algorithm.
The expression for computing the cost is taken from Eqs. (45) and (C39) of [PRX Quantum 2, 030305 (2021)].
 Parameters
n (int) – number of molecular spinorbitals
lamb (float) – 1norm of a secondquantized Hamiltonian
error (float) – target error in the algorithm
rank_r (int) – rank of the first factorization of the twoelectron integral tensor
rank_m (float) – average rank of the second factorization of the twoelectron tensor
rank_max (int) – maximum rank of the second factorization of the twoelectron tensor
br (int) – number of bits for ancilla qubit rotation
alpha (int) – number of bits for the keep register
beta (int) – number of bits for the rotation angles
 Returns
the number of Toffoli gates for the double factorization method
 Return type
int
Example
>>> n = 14 >>> lamb = 52.98761457453095 >>> error = 0.001 >>> rank_r = 26 >>> rank_m = 5.5 >>> rank_max = 7 >>> br = 7 >>> alpha = 10 >>> beta = 20 >>> gate_cost(n, lamb, error, rank_r, rank_m, rank_max, br, alpha, beta) 167048631

static
norm
(one, two, eigvals)[source]¶ Return the 1norm of a molecular Hamiltonian from the one and twoelectron integrals and eigenvalues of the factorized twoelectron integral tensor.
The 1norm of a doublefactorized molecular Hamiltonian is computed using Eqs. (1517) of [Phys. Rev. Research 3, 033055 (2021)]
\[\lambda = T + \frac{1}{4} \sum_r L^{(r)}^2,\]where the Schatten 1norm for a given matrix \(T\) is defined as
\[T = \sum_k \text{eigvals}[T]_k.\]The matrices \(L^{(r)}\) are obtained from factorization of the twoelectron integral tensor \(V\) such that
\[V_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}.\]The matrix \(T\) is constructed from the one and twoelectron integrals as
\[T = h_{ij}  \frac{1}{2} \sum_l V_{illj} + \sum_l V_{llij}.\]Note that the twoelectron integral tensor must be arranged in chemist notation.
 Parameters
one (array[array[float]]) – oneelectron integrals
two (array[array[float]]) – twoelectron integrals
eigvals (array[float]) – eigenvalues of the matrices obtained from factorizing the twoelectron integral tensor
 Returns
1norm of the Hamiltonian
 Return type
array[float]
Example
>>> symbols = ['H', 'H', 'O'] >>> geometry = np.array([[0.00000000, 0.00000000, 0.28377432], >>> [0.00000000, 1.45278171, 1.00662237], >>> [0.00000000, 1.45278171, 1.00662237]], requires_grad=False) >>> mol = qml.qchem.Molecule(symbols, geometry, basis_name='sto3g') >>> core, one, two = qml.qchem.electron_integrals(mol)() >>> two = np.swapaxes(two, 1, 3) # convert to the chemists notation >>> _, eigvals, _ = qml.qchem.factorize(two, 1e5) >>> print(norm(one, two, eigvals)) 52.98762043980203

static
qubit_cost
(n, lamb, error, rank_r, rank_m, rank_max, br=7, alpha=10, beta=20)[source]¶ Return the number of logical qubits needed to implement the double factorization method.
The expression for computing the cost is taken from Eq. (C40) of [PRX Quantum 2, 030305 (2021)].
 Parameters
n (int) – number of molecular spinorbitals
lamb (float) – 1norm of a secondquantized Hamiltonian
error (float) – target error in the algorithm
rank_r (int) – rank of the first factorization of the twoelectron integral tensor
rank_m (float) – average rank of the second factorization of the twoelectron tensor
rank_max (int) – maximum rank of the second factorization of the twoelectron tensor
br (int) – number of bits for ancilla qubit rotation
alpha (int) – number of bits for the keep register
beta (int) – number of bits for the rotation angles
 Returns
number of logical qubits for the double factorization method
 Return type
int
Example
>>> n = 14 >>> lamb = 52.98761457453095 >>> error = 0.001 >>> rank_r = 26 >>> rank_m = 5.5 >>> rank_max = 7 >>> br = 7 >>> alpha = 10 >>> beta = 20 >>> qubit_cost(n, lamb, error, rank_r, rank_m, rank_max, br, alpha, beta) 292

static
unitary_cost
(n, rank_r, rank_m, rank_max, br=7, alpha=10, beta=20)[source]¶ Return the number of Toffoli gates needed to implement the qubitization unitary operator for the double factorization algorithm.
The expression for computing the cost is taken from Eq. (C39) of [PRX Quantum 2, 030305 (2021)].
 Parameters
n (int) – number of molecular spinorbitals
rank_r (int) – rank of the first factorization of the twoelectron integral tensor
rank_m (float) – average rank of the second factorization of the twoelectron tensor
rank_max (int) – maximum rank of the second factorization of the twoelectron tensor
br (int) – number of bits for ancilla qubit rotation
alpha (int) – number of bits for the keep register
beta (int) – number of bits for the rotation angles
 Returns
number of Toffoli gates to implement the qubitization unitary
 Return type
int
Example
>>> n = 14 >>> rank_r = 26 >>> rank_m = 5.5 >>> rank_max = 7 >>> br = 7 >>> alpha = 10 >>> beta = 20 >>> unitary_cost(n, rank_r, rank_m, rank_max, br, alpha, beta) 2007