Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/openfermion/transforms/opconversions/bksf.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def bravyi_kitaev_fast_interaction_op(iop: InteractionOperator) -> QubitOperator
qubit_operator += transformed_term
continue
elif p != r and q < p:
# TODO: remove pragma if reachable continue
continue # pragma: no cover
continue

# Handle the two-body terms.
transformed_term = _two_body(edge_matrix_indices, p, q, r, s)
Expand Down Expand Up @@ -169,8 +168,7 @@ def bravyi_kitaev_fast_edge_matrix(

# Skip zero terms.
if (not coefficient2) or (p == q) or (r == s):
# TODO: remove pragma if this is a reachable continue
continue # pragma: no cover
continue

# Identify and skip one of the complex conjugates.
if [p, q, r, s] != [s, r, q, p]:
Expand Down
25 changes: 25 additions & 0 deletions src/openfermion/transforms/opconversions/bksf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from openfermion.linalg import eigenspectrum, get_sparse_operator
from openfermion.ops.operators import FermionOperator, QubitOperator
from openfermion.ops.representations import InteractionOperator
from openfermion.transforms import bravyi_kitaev_fast_interaction_op
from openfermion.transforms.opconversions import bksf, get_fermion_operator, normal_ordered
from openfermion.transforms.opconversions.jordan_wigner import jordan_wigner, jordan_wigner_one_body
from openfermion.utils import count_qubits
Expand Down Expand Up @@ -258,3 +259,27 @@ def test_bravyi_kitaev_fast_number_excitation_operator(self):
evensector_n += 1
self.assertEqual(evensector_H, 2 ** (n_qubits - 1))
self.assertEqual(evensector_n, 2 ** (n_qubits - 1))

def test_bravyi_kitaev_fast_interaction_op_coverage(self):
n_qubits = 4
constant = 0.0
one_body_tensor = numpy.zeros((n_qubits, n_qubits))
two_body_tensor = numpy.zeros((n_qubits, n_qubits, n_qubits, n_qubits))

# Set up a Hermitian term with p != r and q < p
# For p = 2, q = 1, r = 3, s = 0: p != r (2 != 3) and q < p (1 < 2)
two_body_tensor[2, 1, 3, 0] = 1.0
two_body_tensor[1, 2, 3, 0] = -1.0
two_body_tensor[2, 1, 0, 3] = -1.0
two_body_tensor[1, 2, 0, 3] = 1.0

# Hermitian conjugate terms
two_body_tensor[3, 0, 2, 1] = 1.0
two_body_tensor[3, 0, 1, 2] = -1.0
two_body_tensor[0, 3, 2, 1] = -1.0
two_body_tensor[0, 3, 1, 2] = 1.0

iop = InteractionOperator(constant, one_body_tensor, two_body_tensor)
qubit_op = bravyi_kitaev_fast_interaction_op(iop)

self.assertIsNotNone(qubit_op)
Loading