From b55e24f14d3b19f35a5032ec5c91104260261671 Mon Sep 17 00:00:00 2001 From: Pengfei Chen Date: Fri, 10 May 2024 15:25:42 -0700 Subject: [PATCH] update --- unitary/alpha/qudit_effects.py | 4 +--- unitary/alpha/qudit_gates.py | 8 ++++++-- unitary/alpha/qudit_gates_test.py | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/unitary/alpha/qudit_effects.py b/unitary/alpha/qudit_effects.py index a7b816f1..9ff71bbb 100644 --- a/unitary/alpha/qudit_effects.py +++ b/unitary/alpha/qudit_effects.py @@ -137,9 +137,7 @@ def effect(self, *objects): if q.qubit.dimension == 2: yield cirq.H(q.qubit) else: - yield QuditHadamardGate(dimension=q.qubit.dimension)( - q.qubit - ) + yield QuditHadamardGate(dimension=q.qubit.dimension)(q.qubit) class QuditSuperpose(Superpose): diff --git a/unitary/alpha/qudit_gates.py b/unitary/alpha/qudit_gates.py index e44acfbc..d9c8b1c3 100644 --- a/unitary/alpha/qudit_gates.py +++ b/unitary/alpha/qudit_gates.py @@ -87,7 +87,7 @@ class QuditControlledXGate(cirq.Gate): Args: dimension: dimension of the qudits, for instance, a dimension of 3 would be a qutrit. - control_state: the state of first qudit that when satisfied the X gate on the second qudit will be activated. + control_state: the state of first qudit that when satisfied the X gate on the second qudit will be activated. For instance, if `control_state` is set to 2, then the X gate will be activated when the first qudit is in the |2> state. state: the destination state of the second qudit. For instance, if set to 1, it will perform a @@ -222,7 +222,11 @@ def _qid_shape_(self): return (self.dimension,) def _unitary_(self): - arr = 1.0 / np.sqrt(self.dimension) * np.ones((self.dimension, self.dimension), dtype=np.complex64) + arr = ( + 1.0 + / np.sqrt(self.dimension) + * np.ones((self.dimension, self.dimension), dtype=np.complex64) + ) w = np.exp(1j * 2 * np.pi / self.dimension) # Note: this unitary matrice always has first row and first column elements equal to one, # so we only do calculation for rest of the elements. diff --git a/unitary/alpha/qudit_gates_test.py b/unitary/alpha/qudit_gates_test.py index e6494a21..117459d6 100644 --- a/unitary/alpha/qudit_gates_test.py +++ b/unitary/alpha/qudit_gates_test.py @@ -125,6 +125,7 @@ def test_control_x(control: int, dest: int): assert np.all(results.measurements["m0"] == control) assert np.all(results.measurements["m1"] == non_active) + @pytest.mark.parametrize("dest", [1, 2]) def test_control_of_0_x(dest: int): qutrit0 = cirq.NamedQid("q0", dimension=3) @@ -186,6 +187,7 @@ def test_control_of_0_x(dest: int): assert np.all(results.measurements["m0"] == 0) assert np.all(results.measurements["m1"] == non_active) + @pytest.mark.parametrize( "gate", [