def t3(): """ Expected: [X(q1), X(q1), X(q1)] """ q1 = QRegister('q1') total = 0 if total == 0: X(q1) else: Y(q1) total += 2 if total == 2: total += 2 X(q1) else: total += 1 Y(q1) if total == 4: X(q1) else: Y(q1)
def t2(): """ Expected: [X(q1), X(q1), X(q1), X(q1)] """ q1 = QRegister('q1') l1 = [0, 1, 2, 3] l1 = l1[:2] + l1[2:] if l1 == [0, 1, 2, 3]: X(q1) else: Y(q1) l1 = l1[2:] + l1[:2] if l1 == [2, 3, 0, 1]: X(q1) else: Y(q1) l1 = l1[3:] + l1[:3] if l1 == [1, 2, 3, 0]: X(q1) else: Y(q1) l1 = l1[1:] + l1[:1] if l1 == [2, 3, 0, 1]: X(q1) else: Y(q1)
def t1(): """ Correct result is [ X(q1), X(q1), X(q1) ] """ q1 = QRegister('q1') (x, y, z) = (1, 2, 3) if (x, y, z) == (1, 2, 3): X(q1) else: print('oops 1') Y(q1) (x, y, z) = (y, z, x) if (x, y, z) == (2, 3, 1): X(q1) else: print('oops 2') Y(q1) (x, y, z) = (y, z, x) if (x, y, z) == (3, 1, 2): X(q1) else: print('oops 3') Y(q1)
def anotherMulti2(): qs = QRegister(3) qsub = QRegister(qs[0], qs[1]) Id(qsub) X(qs[0:2]) # equivalent to calling with qsub argument Barrier(qs) MEAS(qsub) Barrier(qs) Y(qs[0]) Y(qs[2])
def anotherMulti3(): qs = QRegister(3) # create the QRegister with slicing qsub = QRegister(qs[0:2]) Id(qsub) X(qsub) Barrier(qs) MEAS(qsub) Barrier(qs) Y(qs[0]) Y(qs[2])
def anotherMulti(): qs = QRegister(2) Id(qs) X(qs) Barrier(qs) MEAS(qs) Y(qs)
def edgeTest3(): q1 = QRegister('q1') q2 = QRegister('q2') for q in [q1, q2]: init(q) echoCR(q1, q2) X(q2) Y(q2) Id(q2) X(q2)
def main(): x = QubitFactory('1') y = QubitFactory('2') z = QubitFactory('3') for q in [x, y, z]: with concur: X(q) Y(q)
def t1(): """ Expected: [X(q1), X(q1)] """ q1 = QRegister('q1') l1 = list() l1 += [ 0 ] l1 += [ 1 ] l1 += [ 2 ] if l1 == [0, 1, 2]: X(q1) else: Y(q1) if len(l1) == 3: X(q1) else: Y(q1)
def t3(): """ Correct result is [ X(q1), X(q1), X(q1), X(q1) ] """ q1 = QRegister('q1') a = [0, 1, 2, 3] a[0], a[1] = a[1], a[0] if a == [1, 0, 2, 3]: X(q1) else: print('oops 1') Y(q1) a[2], a[3] = a[3], a[2] if a == [1, 0, 3, 2]: X(q1) else: print('oops 2') Y(q1) a[0], a[2] = a[2], a[0] if a == [3, 0, 1, 2]: X(q1) else: print('oops 3') Y(q1) a[1], a[3] = a[3], a[1] if a == [3, 2, 1, 0]: X(q1) else: print('oops 4') Y(q1)
def t3(): """ Correct result is X(q1) """ q1 = QRegister('q1') a = 1 for i in range(5): a += 1 if a == 6: X(q1) else: Y(q1) print('T3 a = %d' % a)
def CPMG(qubit: qreg, numPulses, pulseSpacing, calRepeats=2): """ CPMG pulse train with fixed pulse spacing. Note this pulse spacing is centre to centre, i.e. it accounts for the pulse width Parameters ---------- qubit : logical channel to implement sequence (LogicalChannel) numPulses : number of 180 pulses; should be even (iterable) pulseSpacing : spacing between the 180's (seconds) calRepeats : how many times to repeat calibration scalings (default 2) """ # Original: # # First setup the t-180-t block # CPMGBlock = [Id(qubit, (pulseSpacing-qubit.pulse_params['length'])/2), # Y(qubit), Id(qubit, (pulseSpacing-qubit.pulse_params['length'])/2)] # seqs = [[X90(qubit)] + CPMGBlock*rep + [X90(qubit), MEAS(qubit)] for rep in numPulses] # # Tack on the calibration scalings # seqs += create_cal_seqs((qubit,), calRepeats) # fileNames = compile_to_hardware(seqs, 'CPMG/CPMG') # print(fileNames) # if showPlot: # plot_pulse_files(fileNames) # Create numPulses sequences for rep in numPulses: init(qubit) X90(qubit) # Repeat the t-180-t block rep times for _ in range(rep): pulseCentered(qubit, Id, pulseSpacing) Y(qubit) pulseCentered(qubit, Id, pulseSpacing) X90(qubit) MEAS(qubit) # Tack on calibration create_cal_seqs(qubit, calRepeats)
def t1(): """ Not intended to be a valid or useful sequence; only meant to test assignment and control flow """ q1 = QRegister('q1') a = 1 if True: a = 2 # We should do an X, because the change to a should stick. if a == 2: X(q1) elif a == 1: # oops! Y(q1) else: # double oops! Z(q1)
def t2(): q1 = QRegister('q1') a = 1 if False: a = 2 else: a = 3 # We should do an X, because the change to a should stick. if a == 3: X(q1) elif a == 1: Y(q1) elif a == 2: Z(q1) else: Id(q1) print('T2 a = %d' % a)
def t5(): """ Expected: [X(q1), Y(q1), Y(q1), Z(q1), Z(q1), Z(q1), Z(q1)] Like t4, but uses operators that work properly right now. """ q1 = QRegister('q1') l1 = list() l1 += ['a'] for _ in l1: X(q1) l1 += ['b'] for _ in l1: Y(q1) l1 += ['c', 'd'] for _ in l1: Z(q1)
def HahnEcho(qubit: qreg, pulseSpacings, periods=0, calRepeats=2): """ A single pulse Hahn echo with variable phase of second pi/2 pulse. Parameters ---------- qubit : logical channel to implement sequence (LogicalChannel) pulseSpacings : pulse spacings to sweep over; the t in 90-t-180-t-180 (iterable) periods: number of artificial oscillations calRepeats : how many times to repeat calibration scalings (default 2) """ # Original: # seqs=[]; # for k in range(len(pulseSpacings)): # seqs.append([X90(qubit), Id(qubit, pulseSpacings[k]), Y(qubit), Id(qubit,pulseSpacings[k]), \ # U90(qubit,phase=2*pi*periods/len(pulseSpacings)*k), MEAS(qubit)]) # # Tack on the calibration scalings # seqs += create_cal_seqs((qubit,), calRepeats) # fileNames = compile_to_hardware(seqs, 'Echo/Echo') # print(fileNames) # if showPlot: # plot_pulse_files(fileNames) for k in range(len(pulseSpacings)): init(qubit) X90(qubit) # FIXME 9/28/16: Must name the length arg (issue #45) Id(qubit, length=pulseSpacings[k]) Y(qubit) Id(qubit, length=pulseSpacings[k]) U90(qubit, phase=2 * pi * periods / len(pulseSpacings) * k) MEAS(qubit) create_cal_seqs(qubit, calRepeats)
def t4(): """ Expected: [X(q1), Y(q1), Y(q1), Z(q1), Z(q1), Z(q1), Z(q1)] TODO: currently fails; instance methods confuse the evaluator. """ q1 = QRegister('q1') l1 = list() l1.append('a') for _ in l1: X(q1) l1.append('b') for _ in l1: Y(q1) l1.append('c') l1.append('d') for _ in l1: Z(q1)
def YX(q: qreg): # pulsing around orthogonal axes Y(q) X(q)
def X90Y(q: qreg): # pulse pairs with 2e sensitivity X90(q) Y(q)
def t1(q_a: qreg, q_b: qreg): with concur: X(q_a) + X90(q_a) + Y90(q_a) Y(q_b) + Y90(q_b) + X90(q_b)
def XY(q: qreg): # pulsing around orthogonal axes X(q) Y(q)
def YY90(q: qreg): # pulse pairs around common axis with 3e error sensitivity Y(q) Y90(q)
def YId(q: qreg): # single pulses Y(q) Id(q)
def YY(q: qreg): # pulse around same axis Y(q) Y(q)
def func_c(a: qreg, x: classical): for n in range(2): mark(a, n) for op in [Id, X90]: op(a) Y(a, kwarg1=x)
def YX90(q: qreg): # pulse pairs with 2e sensitivity Y(q) X90(q)