Skip to content

Commit

Permalink
Fix scalar too (#264)
Browse files Browse the repository at this point in the history
* Fix scalar too

* Fix tests
  • Loading branch information
y-richie-y committed Jan 25, 2024
1 parent b7fdf6e commit 7b2ba65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions discopy/quantum/zx.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@ def gate2zx(box):
if isinstance(box, (Rz, Rx)):
return (Z if isinstance(box, Rz) else X)(1, 1, box.phase)
if isinstance(box, Controlled) and box.name.startswith('CRz'):
s = scalar(2 ** 0.5)
return Z(1, 2) @ Z(1, 2, box.phase / 2)\
>> Id(1) @ (X(2, 1) >> Z(1, 0, -box.phase / 2)) @ Id(1)
>> Id(1) @ (X(2, 1) >> Z(1, 0, -box.phase / 2)) @ Id(1) @ s
if isinstance(box, Controlled) and box.name.startswith('CRx'):
s = scalar(2 ** 0.5)
return X(1, 2) @ X(1, 2, box.phase / 2)\
>> Id(1) @ (Z(2, 1) >> X(1, 0, -box.phase / 2)) @ Id(1)
>> Id(1) @ (Z(2, 1) >> X(1, 0, -box.phase / 2)) @ Id(1) @ s
if isinstance(box, quantum.CU1):
return Z(1, 2, box.phase) @ Z(1, 2, box.phase)\
>> Id(1) @ (X(2, 1) >> Z(1, 0, -box.phase)) @ Id(1)
Expand Down
6 changes: 3 additions & 3 deletions test/quantum/zx.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def test_circuit2zx():
assert circuit2zx(circuit) == Diagram.decode(
dom=PRO(0), boxes_and_offsets=zip([
X(0, 1), X(0, 1), scalar(0.5), H, X(1, 1),
Z(1, 2), Z(1, 2), X(2, 1), Z(1, 0),
X(1, 2), X(1, 2), Z(2, 1), X(1, 0),
Z(1, 2), Z(1, 2), X(2, 1), Z(1, 0), scalar(2 ** 0.5),
X(1, 2), X(1, 2), Z(2, 1), X(1, 0), scalar(2 ** 0.5),
Z(1, 2), Z(1, 2), X(2, 1), Z(1, 0)],
[0, 1, 2, 0, 1, 0, 2, 1, 1, 0, 2, 1, 1, 0, 2, 1, 1]))
[0, 1, 2, 0, 1, 0, 2, 1, 1, 2, 0, 2, 1, 1, 2, 0, 2, 1, 1]))

# Verify XYZ=iI
t = circuit2zx(quantum.Z >> quantum.Y >> quantum.X)
Expand Down

0 comments on commit 7b2ba65

Please sign in to comment.