Skip to content

Commit 4a5bebc

Browse files
Leonardo RanzaniLeonardo Ranzani
Leonardo Ranzani
authored and
Leonardo Ranzani
committed
Adding SWAP gates
1 parent ee4b523 commit 4a5bebc

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

QGL/Cliffords.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -359,34 +359,42 @@ def XYXClifford(qubit, cliff_num):
359359

360360
clifford_map = {}
361361
clifford_map['STD'] = StdClifford
362-
clifford_map['DIAC'] = DiAC
362+
clifford_map['DIAC'] = DiAC
363363
clifford_map['ZXZXZ'] = lambda q,c: DiAC(q,c,compiled=False)
364-
clifford_map['AC'] = AC
364+
clifford_map['AC'] = AC
365365
clifford_map['XYX'] = XYXClifford
366366

367367
def Cx2(c1, c2, q1, q2, kind='std'):
368368
"""
369369
Helper function to create pulse block for a pair of single-qubit Cliffords
370370
"""
371-
371+
372372
clifford_fun = clifford_map[kind.upper()]
373373
seq1 = clifford_fun(q1, c1)
374374
seq2 = clifford_fun(q2, c2)
375375

376376
#Create the pulse block
377377
return seq1 * seq2
378378

379-
def entangling_seq(gate, q1, q2):
379+
def entangling_seq(gate, q1, q2,swap=False):
380380
"""
381381
Helper function to create the entangling gate sequence
382382
"""
383-
if gate == "CNOT":
384-
return ZX90_CR(q2, q1)
385-
elif gate == "iSWAP":
386-
return [ZX90_CR(q2, q1) , Y90m(q1) * Y90m(q2), ZX90_CR(q2, q1)]
387-
elif gate == "SWAP":
388-
return [ZX90_CR(q2, q1), Y90m(q1) * Y90m(q2), ZX90_CR(
389-
q2, q1), (X90(q1) + Y90m(q1)) * X90(q2), ZX90_CR(q2, q1)]
383+
if swap==False:
384+
if gate == "CNOT":
385+
return ZX90_CR(q2, q1)
386+
elif gate == "iSWAP":
387+
return [ZX90_CR(q2, q1) , Y90m(q1) * Y90m(q2), ZX90_CR(q2, q1)]
388+
elif gate == "SWAP":
389+
return [ZX90_CR(q2, q1), Y90m(q1) * Y90m(q2), ZX90_CR(
390+
q2, q1), (X90(q1) + Y90m(q1)) * X90(q2), ZX90_CR(q2, q1)]
391+
else:
392+
if gate == "CNOT":
393+
return ZX90_CR(q2, q1)
394+
elif gate == "iSWAP":
395+
return [ZX90_CR(q2, q1) , Y90m(q1) * Y90m(q2), ZX90_CR(q2, q1)]
396+
elif gate == "SWAP":
397+
return [SWAP(q2,q1)]
390398

391399
def TwoQubitClifford(q1, q2, cliffNum, kind='std'):
392400

@@ -399,4 +407,4 @@ def TwoQubitClifford(q1, q2, cliffNum, kind='std'):
399407
seq += entangling_seq(c[1], q1, q2)
400408
if c[2]:
401409
seq += [Cx2(c[2][0], c[2][1], q1, q2, kind=kind)]
402-
return seq
410+
return seq

QGL/PulsePrimitives.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ def arb_axis_drag(qubit,
339339

340340

341341
def DiatomicPulse(qubit, a, b, c):
342-
return (Ztheta(qubit, angle=c) + X90(qubit) +
343-
Ztheta(qubit, angle=b) + X90(qubit) +
342+
return (Ztheta(qubit, angle=c) + X90(qubit) +
343+
Ztheta(qubit, angle=b) + X90(qubit) +
344344
Ztheta(qubit, angle=a))
345345

346346
def ZYZPulse(qubit, a, b, c):
@@ -576,3 +576,21 @@ def TRIG(marker_chan, length):
576576
if not isinstance(marker_chan, Channels.LogicalMarkerChannel):
577577
raise ValueError("TRIG pulses can only be generated on LogicalMarkerChannels.")
578578
return TAPulse("TRIG", marker_chan, length, 1.0, 0., 0.)
579+
580+
def iSWAP(Q1,Q2, **kwargs):
581+
edge = ChannelLibraries.EdgeFactory(Q1,Q2)
582+
583+
p = X(edge, **kwargs)
584+
return p._replace(label="iSWAP")
585+
586+
def SWAP(Q1,Q2, **kwargs):
587+
edge = ChannelLibraries.EdgeFactory(Q1,Q2)
588+
589+
p = X(edge, **kwargs)
590+
return p._replace(label="SWAP")
591+
592+
def SQRTSWAP(Q1,Q2, **kwargs):
593+
edge = ChannelLibraries.EdgeFactory(Q1,Q2)
594+
595+
p = X90(edge, **kwargs)
596+
return p._replace(label="SQRTSWAP")

memory:.sqlite

172 KB
Binary file not shown.

memory:.sqlite-journal

12.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)