Skip to content

Commit

Permalink
another small round of addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderivrii committed Nov 4, 2024
1 parent 61731b9 commit 36e3450
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions qiskit/circuit/library/fourier_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

"""Fourier checking circuit."""

from typing import List

from collections.abc import Sequence
import math

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.exceptions import CircuitError
from qiskit.utils.deprecation import deprecate_func
Expand Down Expand Up @@ -58,7 +58,7 @@ class FourierChecking(QuantumCircuit):
additional_msg="Use qiskit.circuit.library.fourier_checking instead.",
pending=True,
)
def __init__(self, f: List[int], g: List[int]) -> None:
def __init__(self, f: Sequence[int], g: Sequence[int]) -> None:
"""Create Fourier checking circuit.
Args:
Expand Down Expand Up @@ -100,7 +100,7 @@ def __init__(self, f: List[int], g: List[int]) -> None:
self.compose(circuit.to_gate(), qubits=self.qubits, inplace=True)


def fourier_checking(f: List[int], g: List[int]) -> QuantumCircuit:
def fourier_checking(f: Sequence[int], g: Sequence[int]) -> QuantumCircuit:
"""Fourier checking circuit.
The circuit for the Fourier checking algorithm, introduced in [1],
Expand Down
29 changes: 14 additions & 15 deletions test/python/circuit/library/test_phase_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,25 @@ def test_phase_estimation_function(self):

self.assertPhaseEstimationIsCorrect(pec, eigenstate, phase_as_binary)

def test_phase_estimation_function_swaps_removed(self):
def test_phase_estimation_function_swaps_get_removed(self):
"""Test that transpiling the circuit correctly removes swaps and permutations."""
with self.subTest("U=S, psi=|1>"):
unitary = QuantumCircuit(1)
unitary.s(0)
unitary = QuantumCircuit(1)
unitary.s(0)

eigenstate = QuantumCircuit(1)
eigenstate.x(0)
eigenstate = QuantumCircuit(1)
eigenstate.x(0)

pec = phase_estimation(4, unitary)
pec = phase_estimation(4, unitary)

# transpilation (or more precisely HighLevelSynthesis + ElidePermutations) should
# remove all swap gates (possibly added when synthesizing the QFTGate in the circuit)
# and the final permutation gate
transpiled = transpile(pec)
transpiled_ops = transpiled.count_ops()
# transpilation (or more precisely HighLevelSynthesis + ElidePermutations) should
# remove all swap gates (possibly added when synthesizing the QFTGate in the circuit)
# and the final permutation gate
transpiled = transpile(pec)
transpiled_ops = transpiled.count_ops()

self.assertNotIn("permutation", transpiled_ops)
self.assertNotIn("swap", transpiled_ops)
self.assertNotIn("cx", transpiled_ops)
self.assertNotIn("permutation", transpiled_ops)
self.assertNotIn("swap", transpiled_ops)
self.assertNotIn("cx", transpiled_ops)


if __name__ == "__main__":
Expand Down

0 comments on commit 36e3450

Please sign in to comment.