Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pengfei Chen committed May 10, 2024
1 parent 39fe775 commit b55e24f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions unitary/alpha/qudit_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions unitary/alpha/qudit_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions unitary/alpha/qudit_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
[
Expand Down

0 comments on commit b55e24f

Please sign in to comment.