forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding QFT gate to natively reason about Quantum Fourier Transforms (Q…
…iskit#11463) * initial commit * release notes * fixing synthesis plugin options * finalize merge conflicts * fixing default option values for qft plugins' * additional tests for qft plugins * renaming QftGate to QFTGate * Also renaming Qft to QFT in synthesis method names * appplying Jake's suggestion from code review * inlining _basic_definition into _define * docstring improvements * more docstring improvements * renaming do_swaps to reverse_qubits in the new code * typos * adding synth_qft_full to __init__ * round of suggestions from code review * another round of code review suggestions * fixes * also adding QFTGate plugins to the docs
- Loading branch information
1 parent
6ed78ff
commit f37e8ee
Showing
15 changed files
with
510 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
|
||
"""The basis change circuits.""" | ||
|
||
from .qft import QFT | ||
from .qft import QFT, QFTGate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2024. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
""" | ||
Circuit synthesis for a QFT circuit. | ||
""" | ||
|
||
from __future__ import annotations | ||
import numpy as np | ||
from qiskit.circuit.quantumcircuit import QuantumCircuit | ||
|
||
|
||
def synth_qft_full( | ||
num_qubits: int, | ||
do_swaps: bool = True, | ||
approximation_degree: int = 0, | ||
insert_barriers: bool = False, | ||
inverse: bool = False, | ||
name: str | None = None, | ||
) -> QuantumCircuit: | ||
"""Construct a circuit for the Quantum Fourier Transform using all-to-all connectivity. | ||
.. note:: | ||
With the default value of ``do_swaps = True``, this synthesis algorithm creates a | ||
circuit that faithfully implements the QFT operation. This circuit contains a sequence | ||
of swap gates at the end, corresponding to reversing the order of its output qubits. | ||
In some applications this reversal permutation can be avoided. Setting ``do_swaps = False`` | ||
creates a circuit without this reversal permutation, at the expense that this circuit | ||
implements the "QFT-with-reversal" instead of QFT. Alternatively, the | ||
:class:`~.ElidePermutations` transpiler pass is able to remove these swap gates. | ||
Args: | ||
num_qubits: The number of qubits on which the Quantum Fourier Transform acts. | ||
do_swaps: Whether to synthesize the "QFT" or the "QFT-with-reversal" operation. | ||
approximation_degree: The degree of approximation (0 for no approximation). | ||
It is possible to implement the QFT approximately by ignoring | ||
controlled-phase rotations with the angle beneath a threshold. This is discussed | ||
in more detail in https://arxiv.org/abs/quant-ph/9601018 or | ||
https://arxiv.org/abs/quant-ph/0403071. | ||
insert_barriers: If ``True``, barriers are inserted for improved visualization. | ||
inverse: If ``True``, the inverse Quantum Fourier Transform is constructed. | ||
name: The name of the circuit. | ||
Returns: | ||
A circuit implementing the QFT operation. | ||
""" | ||
|
||
circuit = QuantumCircuit(num_qubits, name=name) | ||
|
||
for j in reversed(range(num_qubits)): | ||
circuit.h(j) | ||
num_entanglements = max(0, j - max(0, approximation_degree - (num_qubits - j - 1))) | ||
for k in reversed(range(j - num_entanglements, j)): | ||
# Use negative exponents so that the angle safely underflows to zero, rather than | ||
# using a temporary variable that overflows to infinity in the worst case. | ||
lam = np.pi * (2.0 ** (k - j)) | ||
circuit.cp(lam, j, k) | ||
|
||
if insert_barriers: | ||
circuit.barrier() | ||
|
||
if do_swaps: | ||
for i in range(num_qubits // 2): | ||
circuit.swap(i, num_qubits - i - 1) | ||
|
||
if inverse: | ||
circuit = circuit.inverse() | ||
|
||
return circuit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.