Skip to content

Commit c35f75c

Browse files
committed
ionq prepare output
1 parent 3beaa5e commit c35f75c

File tree

3 files changed

+86
-21
lines changed

3 files changed

+86
-21
lines changed

discopy/circuit.py

+21
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ def scalar(complex):
881881
0, 1, 0, 0,
882882
0, 0, 0, 1,
883883
0, 0, 1, 0], _dagger=None)
884+
CZ = Gate('CZ', 2, [1, 0, 0, 0,
885+
0, 1, 0, 0,
886+
0, 0, 1, 0,
887+
0, 0, 0, -1], _dagger=None)
884888
H = Gate('H', 1, 1 / np.sqrt(2) * np.array([1, 1, 1, -1]), _dagger=None)
885889
S = Gate('S', 1, [1, 0, 0, 1j])
886890
T = Gate('T', 1, [1, 0, 0, np.exp(1j * np.pi / 4)])
@@ -940,3 +944,20 @@ def IQPansatz(n, params):
940944
for i in range(1, depth):
941945
ansatz = ansatz >> IQPlayer(params[i])
942946
return ansatz
947+
948+
949+
def Perm(perm):
950+
""" Constructs a permutation
951+
952+
>>> assert Perm([2, 1, 0]) == Perm([2, 0, 1]) >> Perm([0, 2, 1])
953+
"""
954+
assert set(range(len(perm))) == set(perm)
955+
gates, offsets = [], []
956+
frame = perm.copy()
957+
for i in range(len(perm)):
958+
if i < frame[i]:
959+
num_swaps = frame[i] - i
960+
gates += [SWAP for x in range(num_swaps)]
961+
offsets += range(i, frame[i])[::-1]
962+
frame[i: i + num_swaps] = [x + 1 for x in frame[i: i + num_swaps]]
963+
return Circuit(len(perm), len(perm), gates, offsets)

discopy/tk_interface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from discopy.tensor import np, Dim, Tensor
1010
from discopy.circuit import (
1111
CircuitFunctor, Circuit, Id, Bra, Ket, PRO,
12-
Rx, Rz, SWAP, CX, H, S, T, X, Y, Z, scalar, CRz)
12+
Rx, Rz, SWAP, CZ, CX, H, S, T, X, Y, Z, scalar, CRz)
1313

1414
import pytket as tk
1515
from pytket.circuit import Qubit
@@ -122,7 +122,7 @@ def box_from_tk(tk_gate):
122122
return Rz(tk_gate.op.params[0] / 2)
123123
if name == 'CRz':
124124
return CRz(tk_gate.op.params[0] / 2)
125-
for gate in [SWAP, CX, H, S, T, X, Y, Z]:
125+
for gate in [SWAP, CZ, CX, H, S, T, X, Y, Z]:
126126
if name == gate.name:
127127
return gate
128128
raise NotImplementedError

0 commit comments

Comments
 (0)