Skip to content

Commit

Permalink
Adding SWAP gates
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Ranzani authored and Leonardo Ranzani committed Feb 10, 2025
1 parent ee4b523 commit 4a5bebc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
32 changes: 20 additions & 12 deletions QGL/Cliffords.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,34 +359,42 @@ def XYXClifford(qubit, cliff_num):

clifford_map = {}
clifford_map['STD'] = StdClifford
clifford_map['DIAC'] = DiAC
clifford_map['DIAC'] = DiAC
clifford_map['ZXZXZ'] = lambda q,c: DiAC(q,c,compiled=False)
clifford_map['AC'] = AC
clifford_map['AC'] = AC
clifford_map['XYX'] = XYXClifford

def Cx2(c1, c2, q1, q2, kind='std'):
"""
Helper function to create pulse block for a pair of single-qubit Cliffords
"""

clifford_fun = clifford_map[kind.upper()]
seq1 = clifford_fun(q1, c1)
seq2 = clifford_fun(q2, c2)

#Create the pulse block
return seq1 * seq2

def entangling_seq(gate, q1, q2):
def entangling_seq(gate, q1, q2,swap=False):
"""
Helper function to create the entangling gate sequence
"""
if gate == "CNOT":
return ZX90_CR(q2, q1)
elif gate == "iSWAP":
return [ZX90_CR(q2, q1) , Y90m(q1) * Y90m(q2), ZX90_CR(q2, q1)]
elif gate == "SWAP":
return [ZX90_CR(q2, q1), Y90m(q1) * Y90m(q2), ZX90_CR(
q2, q1), (X90(q1) + Y90m(q1)) * X90(q2), ZX90_CR(q2, q1)]
if swap==False:
if gate == "CNOT":
return ZX90_CR(q2, q1)
elif gate == "iSWAP":
return [ZX90_CR(q2, q1) , Y90m(q1) * Y90m(q2), ZX90_CR(q2, q1)]
elif gate == "SWAP":
return [ZX90_CR(q2, q1), Y90m(q1) * Y90m(q2), ZX90_CR(
q2, q1), (X90(q1) + Y90m(q1)) * X90(q2), ZX90_CR(q2, q1)]
else:
if gate == "CNOT":
return ZX90_CR(q2, q1)
elif gate == "iSWAP":
return [ZX90_CR(q2, q1) , Y90m(q1) * Y90m(q2), ZX90_CR(q2, q1)]
elif gate == "SWAP":
return [SWAP(q2,q1)]

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

Expand All @@ -399,4 +407,4 @@ def TwoQubitClifford(q1, q2, cliffNum, kind='std'):
seq += entangling_seq(c[1], q1, q2)
if c[2]:
seq += [Cx2(c[2][0], c[2][1], q1, q2, kind=kind)]
return seq
return seq
22 changes: 20 additions & 2 deletions QGL/PulsePrimitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def arb_axis_drag(qubit,


def DiatomicPulse(qubit, a, b, c):
return (Ztheta(qubit, angle=c) + X90(qubit) +
Ztheta(qubit, angle=b) + X90(qubit) +
return (Ztheta(qubit, angle=c) + X90(qubit) +
Ztheta(qubit, angle=b) + X90(qubit) +
Ztheta(qubit, angle=a))

def ZYZPulse(qubit, a, b, c):
Expand Down Expand Up @@ -576,3 +576,21 @@ def TRIG(marker_chan, length):
if not isinstance(marker_chan, Channels.LogicalMarkerChannel):
raise ValueError("TRIG pulses can only be generated on LogicalMarkerChannels.")
return TAPulse("TRIG", marker_chan, length, 1.0, 0., 0.)

def iSWAP(Q1,Q2, **kwargs):
edge = ChannelLibraries.EdgeFactory(Q1,Q2)

p = X(edge, **kwargs)
return p._replace(label="iSWAP")

def SWAP(Q1,Q2, **kwargs):
edge = ChannelLibraries.EdgeFactory(Q1,Q2)

p = X(edge, **kwargs)
return p._replace(label="SWAP")

def SQRTSWAP(Q1,Q2, **kwargs):
edge = ChannelLibraries.EdgeFactory(Q1,Q2)

p = X90(edge, **kwargs)
return p._replace(label="SQRTSWAP")
Binary file added memory:.sqlite
Binary file not shown.
Binary file added memory:.sqlite-journal
Binary file not shown.

0 comments on commit 4a5bebc

Please sign in to comment.