diff --git a/test/layers/test_rotgate.py b/test/layers/test_rotgate.py index beec6d72..c69d5569 100644 --- a/test/layers/test_rotgate.py +++ b/test/layers/test_rotgate.py @@ -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 diff --git a/torchquantum/layer/general.py b/torchquantum/layer/general.py index 65847e23..9857220a 100644 --- a/torchquantum/layer/general.py +++ b/torchquantum/layer/general.py @@ -36,6 +36,7 @@ "GlobalR", "GlobalRX", "GlobalRY", + "GlobalRZ", ] @@ -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) + +