Skip to content
Closed

qp-qft #1736

Show file tree
Hide file tree
Changes from 2 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
32 changes: 16 additions & 16 deletions demonstrations_v2/tutorial_qft/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"""

from scipy.linalg import dft
import pennylane as qml
import pennylane as qp
import numpy as np

n = 2

print("DFT matrix for n = 2:\n")
print(np.round(1 / np.sqrt(2 ** n) * dft(2 ** n), 2))

qft_inverse = qml.adjoint(qml.QFT([0,1]))
qft_inverse = qp.adjoint(qp.QFT([0,1]))

print("\n inverse QFT matrix for n = 2:\n")
print(np.round(qft_inverse.matrix(), 2))
Expand Down Expand Up @@ -90,19 +90,19 @@
# In PennyLane, we rearrange the qubits in the opposite ordering; that is why we
# apply SWAP gates at the end. Let's see how the decomposition looks like using the drawer:

import pennylane as qml
import pennylane as qp
from functools import partial
import matplotlib.pyplot as plt

plt.style.use('pennylane.drawer.plot')

# This line is to expand the circuit to see the operators
@partial(qml.transforms.decompose, max_expansion=1)
@partial(qp.transforms.decompose, max_expansion=1)

def circuit():
qml.QFT(wires=range(4))
qp.QFT(wires=range(4))

qml.draw_mpl(circuit, decimals = 2, style = "pennylane")()
qp.draw_mpl(circuit, decimals = 2, style = "pennylane")()
plt.show()

#############################################
Expand All @@ -124,17 +124,17 @@ def circuit():

def prep():
"""quntum function that prepares the state."""
qml.PauliX(wires=0)
qp.PauliX(wires=0)
for wire in range(1, 6):
qml.Hadamard(wires=wire)
qml.ControlledSequence(qml.PhaseShift(-2 * np.pi / 10, wires=0), control=range(1, 6))
qml.PauliX(wires=0)
qp.Hadamard(wires=wire)
qp.ControlledSequence(qp.PhaseShift(-2 * np.pi / 10, wires=0), control=range(1, 6))
qp.PauliX(wires=0)

dev = qml.device("default.qubit")
@qml.qnode(dev)
dev = qp.device("default.qubit")
@qp.qnode(dev)
def circuit():
prep()
return qml.state()
return qp.state()

state = circuit().real[:32]

Expand All @@ -149,12 +149,12 @@ def circuit():
# which is able to transform the state into the frequency domain. This is shown in the code below:
#

@qml.qnode(dev)
@qp.qnode(dev)
def circuit():
prep()
qml.QFT(wires=range(1, 6))
qp.QFT(wires=range(1, 6))

return qml.probs(wires=range(1, 6))
return qp.probs(wires=range(1, 6))

state = circuit()[:32]

Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_qft/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2024-04-16T00:00:00+00:00",
"dateOfLastModification": "2025-12-19T00:00:00+00:00",
"dateOfLastModification": "2026-04-06T00:00:00+00:00",
"categories": [
"Algorithms",
"Quantum Computing"
Expand Down
Loading