Skip to content

Commit

Permalink
adding GRZ gate
Browse files Browse the repository at this point in the history
  • Loading branch information
01110011011101010110010001101111 committed Nov 18, 2023
1 parent 9e20154 commit 46b04ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions test/layers/test_rotgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
find_global_phase,
)

from qiskit.circuit.library import GR, GRX, GRY
from qiskit.circuit.library import GR, GRX, GRY, GRZ
import numpy as np

all_pairs = [
# {"qiskit": GR, "tq": tq.layer.GlobalR, "params": 2},
{"qiskit": GR, "tq": tq.layer.GlobalR, "params": 2},
{"qiskit": GRX, "tq": tq.layer.GlobalRX, "params": 1},
{"qiskit": GRY, "tq": tq.layer.GlobalRY, "params": 1},
{"qiskit": GRZ, "tq": tq.layer.GlobalRZ, "params": 1},
]

ITERATIONS = 10
Expand Down
21 changes: 21 additions & 0 deletions torchquantum/layer/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"GlobalR",
"GlobalRX",
"GlobalRY",
"GlobalRZ",
]


Expand Down Expand Up @@ -81,3 +82,23 @@ def __init__(
):
"""Create the layer"""
super().__init__(n_wires, theta, phi=torch.pi / 2)

class GlobalRZ(tq.QuantumModule):
"""Layer Template for a Global RZ General Gate"""

def __init__(
self,
n_wires: int = 0,
phi: float = 0,
):
"""Create the layer"""
super().__init__()
self.n_wires = n_wires
self.params = torch.tensor([[phi]])

@tq.static_support
def forward(self, q_device, x=None):
for k in range(self.n_wires):
tq.RZ()(q_device, wires=k, params=self.params)


0 comments on commit 46b04ca

Please sign in to comment.