Skip to content

Commit

Permalink
add support for qft algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
01110011011101010110010001101111 committed Aug 4, 2023
1 parent e763d38 commit a54b0b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion torchquantum/algorithm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
"""

from .vqe import *
from .hamiltonian import *
from .hamiltonian import *
from .qft import *
32 changes: 32 additions & 0 deletions torchquantum/algorithm/qft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import torchquantum as tq
from typing import Iterable

__all__ = ["QFT"]

class QFT(object):
def __init__(
self, n_wires: int = None, wires: Iterable = None, do_swaps=True
) -> None:
"""Init function for QFT class
Args:
n_wires (int): Number of wires for the QFT as an integer
wires (Iterable): Wires to perform the QFT as an Iterable
add_swaps (bool): Whether or not to add the final swaps in a boolean format
inverse (bool): Whether to create an inverse QFT layer in a boolean format
"""
super().__init__()

self.n_wires = n_wires
self.wires = wires
self.do_swaps = do_swaps

def construct_qft_circuit(self) -> tq.QuantumModule:
"""Construct the QFT circuit."""
return tq.layer.QFTLayer(n_wires=self.n_wires, wires=self.wires, do_swaps=self.do_swaps)

def construct_inverse_qft_circuit(self) -> tq.QuantumModule:
"""Construct the inverse of a QFT circuit."""
return tq.layer.QFTLayer(
n_wires=self.n_wires, wires=self.wires, do_swaps=self.do_swaps, inverse=True
)

0 comments on commit a54b0b7

Please sign in to comment.