Exemplo n.º 1
0
def data_optimize(inputparam, params, dec):
    ''' use this function to search for params.MScorr for every detuning. 
    How-to:
    - in the root-level code above, enter params.MSdelta and params.shortestMS
    - here put 'inputparam' in place of the number you want to optimize
    - run the file and enter the result in above
    - repeat for every number that appears in params.MScorr '''
    #params.MScorr = {
    #    'duration': 1.1642,
    #    'omrabi': 1.0268,
    #    'shortPulseFactorPos': {2: 1.000, 4: 1.0106, 8: inputparam, 16: 1.01835},
    #    'shortPulseFactorNeg': {2: 1.010, 4: 1.0214, 8: 1.0271, 16: 1.02986}
    #    }
    pulseseq = sim.PulseSequence([
        sim.Hide(params, 0, True),
        sim.Hide(params, 1, True),
        sim.RMS(params, pi / 2, 0),
        sim.Rcar(params, pi / 2, pi / 2)
    ])
    pulseseq[2].omrabi_r = params.omc_ms * inputparam
    pulseseq[2].omrabi_b = params.omc_ms * inputparam

    data = qc.simulateevolution(pulseseq, params, dec)
    data.displayPMTpopulations(0)

    inbalance = abs(data.P_PMT_end[2] - data.P_PMT_end[5])
    unwanted = abs(data.P_PMT_end[0] + data.P_PMT_end[1] + data.P_PMT_end[3] +
                   data.P_PMT_end[4])

    print inputparam, inbalance + unwanted

    return inbalance + unwanted
Exemplo n.º 2
0
def SelectPermutation(select_order, doKitaev):
    if select_order == 0:
        Perm = sim.Delay(params, 0.1)
        Perm2 = sim.Delay(params, 0.1)
        Perm4 = sim.Delay(params, 0.1)
    elif select_order == 1:
        Perm = order1
        Perm2 = sim.Delay(params, 0.1)
        Perm4 = sim.Delay(params, 0.1)
    elif select_order == 2:
        Perm = order2
        Perm2 = sim.Delay(params, 0.1)
        Perm4 = sim.Delay(params, 0.1)
    elif select_order == 3:
        Perm = order31
        if not doKitaev:
            Perm2 = sim.PulseSequence([ \
                sim.Hide(params, 1, False),
                sim.Hide(params, 2, True),
                order32 ])
            Perm4 = sim.PulseSequence([ \
                sim.Hide(params, 2, True),
                sim.Hide(params, 1, True),
                sim.Hide(params, 0, False),
                order34, ])
Exemplo n.º 3
0
        def PulseSeqWithControls(ctl):
            # 'ctl' is a bit array of control qubits
            ctlstr = np.binary_repr(ctl).zfill(self.nOps-1)
            pulseseq = sim.PulseSequence([])
            
            for k in range(self.nOps):
                pulseseq.append(Hadamard(0))
                pulseseq.append(Perms[k])
                pulseseq += [copy.deepcopy(controlRots[i] \
                              [int(ctlstr[self.nOps-i-k-1])]) for i in range(k)]
                pulseseq.append(Hadamard(0))

                if k == self.nOps-1:
                    pulseseq += [ \
                      sim.Hide(params, 1, True),
                      sim.Hide(params, 2, True),
                      sim.MeasInit(params, 0, incl_hidingerr=False) ] 
                else:
                    pulseseq += [ \
                      sim.Hide(params, 1, True),
                      sim.Hide(params, 2, True),
                      sim.MeasInit(params, 0),
                      sim.Hide(params, 1, False),
                      sim.Hide(params, 2, False) ]
            return pulseseq
Exemplo n.º 4
0
if doPPKitaev: params.ppcpus = 2

Kit = Kitaev.Kitaev()

##########################################
# load the pulse sequences
# change ion order and define permutations
##########################################
execfile(pulseseqfileShor)

shor7b1 = copy.deepcopy(Fredkin)
shor7b2 = copy.deepcopy(Fredkin)
shor7b1.changeions(params, (0, 1, 3))
shor7b2.changeions(params, (0, 2, 4))
shor7b = sim.PulseSequence([ \
    sim.Hide(params, 2, True),
    sim.Hide(params, 4, True),
    shor7b1,
    sim.Hide(params, 2, False),
    sim.Hide(params, 4, False),
    sim.Hide(params, 1, True),
    sim.Hide(params, 3, True),
    shor7b2,
    sim.Hide(params, 1, False),
    sim.Hide(params, 3, False)])


### general pulse sequence
def GeneratePulseSeq(shor7a, shor7b, shor11, a):

    NOP = sim.Delay(params, 0.1)
Exemplo n.º 5
0
def main():
    ### run params ##################################
    pulseseqfileShor = 'experiments/Shorseq_6qubit.py'

    firstMultMap = True  # Do first multiplication with CNOT
    # mapping instead of Multiplier
    # (does nothing in easy cases)

    select_a = 4  # Factoring base: 2,4,5,8,10,11,13,16,17,19

    doRun = True
    doIdeal = True
    printpulse = False
    saveKitaev = False
    doPPKitaev = True

    print('N = 21, a =', select_a)

    NumberOfIons = 6
    NumberOfPhonons = 0 if doIdeal else 7
    hspace = sim.hspace(NumberOfIons, 2, NumberOfPhonons, 0)
    hspace.initial_state("quantum", qstate='DSSSSS')
    params = sim.parameters(hspace)

    params.use_servers(['all'])
    params.ppcpus = 16
    params.shortestMS = 16
    params.calcPulseParams()
    params.progbar = True
    params.saveallpoints = False
    params.coherenceTime = 15000
    params.hidingerr = 1

    params.printpulse = printpulse
    params.progbar = printpulse
    params.pplog = False

    dec = sim.decoherence(params)
    dec.doRandNtimes = 1  #16
    dec.doPP = True
    dec.dict['all'] = False
    #    if doPPKitaev: params.ppcpus = 2

    Kit = Kitaev.Kitaev()

    ##########################################
    # load the pulse sequences
    # change ion order and define permutations
    ##########################################
    # execfile(pulseseqfileShor,locals(),globals())
    def makeexec(f):
        f = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', f))
        c = compile(open(f, 'rb').read(), f, 'exec')
        return c

    exec(makeexec(pulseseqfileShor))

    cnot12_6 = sim.PulseSequence([cnot12])

    Fred35 = copy.deepcopy(Fredkin)
    Fred13 = copy.deepcopy(Fredkin)
    Fred35.changeions(params, (3, 5, 0))
    Fred13.changeions(params, (1, 3, 0))

    cnot15 = copy.deepcopy(cnot12_6)
    cnot23 = copy.deepcopy(cnot12_6)
    cnot24 = copy.deepcopy(cnot12_6)
    cnot25 = copy.deepcopy(cnot12_6)
    cnot35 = copy.deepcopy(cnot12_6)
    cnot15.changeions(params, (0, 1, 5))
    cnot23.changeions(params, (0, 2, 3))
    cnot24.changeions(params, (0, 2, 4))
    cnot25.changeions(params, (0, 2, 5))
    cnot35.changeions(params, (0, 3, 5))


    times4 = sim.PulseSequence([ \
        sim.Hide(params, 1, True),
        sim.Hide(params, 2, True),
        sim.Hide(params, 4, True), #vis: 3,5
        Fred35,
        sim.Hide(params, 1, False),
        sim.Hide(params, 5, True), #vis: 1,3
        Fred13,
        sim.Hide(params, 2, False),
        sim.Hide(params, 4, False),
        sim.Hide(params, 5, False)
        ])

    times16 = sim.PulseSequence([ \
        sim.Hide(params, 2, True),
        sim.Hide(params, 4, True),
        sim.Hide(params, 5, True), #vis: 1,3
        Fred35,
        sim.Hide(params, 5, False),
        sim.Hide(params, 1, True), #vis: 3,5
        Fred13,
        sim.Hide(params, 1, False),
        sim.Hide(params, 2, False),
        sim.Hide(params, 4, False)
        ])

    ### general pulse sequence
    def GeneratePulseSeq(a):

        NOP = sim.PulseSequence([sim.Delay(params, 0.1)])

        if a in (2, 5, 16, 19):  # a^2=4 cases
            if firstMultMap:
                a16modN = cnot15
            else:
                a16modN = times16
            a8modN = times4
            a4modN = times16
            a2modN = times4
            if a == 16:
                a1modN = times16
            else:
                a1modN = cnot24  # only cheating method implimented...

        elif a in (4, 10, 11, 17):  # a^2=16 cases
            if firstMultMap:
                a16modN = cnot13
            else:
                a16modN = times4
            a8modN = times16
            a4modN = times4
            a2modN = times16
            if a == 4:
                a1modN = times4
            else:
                a1modN = cnot24  # only cheating method implimented...

        elif a in (8, 13):
            a16modN = NOP
            a8modN = NOP
            a4modN = NOP
            a2modN = NOP
            if a == 8:
                a1modN = cnot25
            elif a == 13:
                a1modN = cnot23

        oplist = [a16modN, a8modN, a4modN, a2modN, a1modN]

        pulseseq_group = Kit.GeneratePulseSeq(params, oplist)
        return pulseseq_group

    #######################################################

    pulseseq = GeneratePulseSeq(select_a)

    if doIdeal:
        for ps in pulseseq:
            for pulse in ps:
                pulse.use_ideal = True

    ### run it
    if doRun:
        tic = time.time()
        result = Kit.simulateevolution(pulseseq, params, dec, doPP=doPPKitaev)
        if not doIdeal: print("runtime: ", time.time() - tic, "sec")
        print(np.around(result, 6))

    if saveKitaev:
        timestr = datetime.datetime.now().strftime('%Y%m%d-%H%M%S-%f')
        fnameappend = ''
        Kit.getQFTall()
        Kit.datagroupsave('Shor' + str(select_a) + '-data-' + fnameappend +
                          timestr + '.pk',
                          RhoOnly=True)
        Kit.resultSave('Shor' + str(select_a) + '-res-' + fnameappend +
                       timestr + '.npy')
        f = open(
            'Shor' + str(select_a) + '-params-' + fnameappend + timestr +
            '.pk', 'wb')
        pickle.dump(dec.dict_params_static, f)
        f.close()

    return True  #dataobj
Exemplo n.º 6
0
hspace = sim.hspace(NumberOfIons, 2, NumberofPhonons, 0)
params = sim.parameters(hspace)
dec = sim.decoherence(params)

params.hidingerr = 0.75

dec.doRandNtimes = 4
dec.dict['hiding'] = True
#dec.doPP = True

dec.progbar = False
#params.progbar= True
#params.printpulse = True

pulseseq = sim.PulseSequence( [ \
    sim.Hide(params, 0, True),
    sim.Hide(params, 0, False),
    sim.Rcar(params, 2*pi, 0), \
    sim.Hide(params, 2, True),
    sim.Hide(params, 2, False),
    sim.Rcar(params, 2*pi, 0), \
    sim.Hide(params, 2, True),
    sim.Hide(params, 2, False),
    sim.Rcar(params, 2*pi, 0), \
    ] )

data = qc.simulateevolution(pulseseq, params, dec)

data.tracedpopulation(1)
Exemplo n.º 7
0
def main():
    ### run params ##################################
    pulseseqfileShor = 'experiments/Shorseq.py'
   
    firstMultMap = True # Do first multiplication with CNOT 
                        # mapping instead of Multiplier 
                        # (does nothing in easy cases)
    select_a = 7 # Factoring base: 2, 4, 7, 8, 13, 11, or 14

    doRun = True
    doIdeal = True
    printpulse = False
    saveKitaev = False
    doPPKitaev = True

    print 'a =',select_a
    
    NumberOfIons = 5
    NumberOfPhonons = 0 if doIdeal else 7 
    hspace = sim.hspace(NumberOfIons,2,NumberOfPhonons,0)
    hspace.initial_state("quantum", qstate='DSSSS')
    params = sim.parameters(hspace)
    
    params.use_servers( ['all'] )
    params.ppcpus = 16
    params.shortestMS = 16
    params.calcPulseParams()
    params.progbar = True
    params.saveallpoints = False
    params.coherenceTime = 15000
    params.hidingerr = 1
    
    params.printpulse = printpulse
    params.progbar = printpulse
    params.pplog = False
    
    dec = sim.decoherence(params)
    dec.doRandNtimes = 16
    dec.doPP = True
    dec.dict['all'] = True
#    if doPPKitaev: params.ppcpus = 2
    
    Kit = Kitaev.Kitaev()
    
    ##########################################
    # load the pulse sequences
    # change ion order and define permutations
    ##########################################
    execfile(pulseseqfileShor,locals(),globals())

    Fred12 = copy.deepcopy(Fredkin)
    Fred23 = copy.deepcopy(Fredkin)
    Fred34 = copy.deepcopy(Fredkin)
    Fred24 = copy.deepcopy(Fredkin)
    Fred13 = copy.deepcopy(Fredkin)
    Fred12.changeions(params, (1,2,0))
    Fred23.changeions(params, (2,3,0))
    Fred34.changeions(params, (3,4,0))
    Fred24.changeions(params, (2,4,0))
    Fred13.changeions(params, (1,3,0))
   
    cnot13 = copy.deepcopy(cnot12)
    cnot24 = copy.deepcopy(cnot12)
    cnot13.changeions(params,(0,1,3))
    cnot24.changeions(params,(0,2,4))

    times2 = sim.PulseSequence([ \
        sim.Hide(params, 3, True),
        sim.Hide(params, 4, True), #vis: 1,2
        Fred12,
        sim.Hide(params, 3, False),
        sim.Hide(params, 1, True), #vis: 2,3
        Fred23,
        sim.Hide(params, 4, False),
        sim.Hide(params, 2, True), #vis: 3,4
        Fred34,
        sim.Hide(params, 1, False),
        sim.Hide(params, 2, False) #vis: 1,2,3,4
        ])

    times4 = sim.PulseSequence([ \
        sim.Hide(params, 1, True),
        sim.Hide(params, 3, True), #vis: 2,4
        Fred24,
        sim.Hide(params, 1, False),
        sim.Hide(params, 3, False),
        sim.Hide(params, 2, True),
        sim.Hide(params, 4, True), #vis: 1,3
        Fred13,
        sim.Hide(params, 2, False),
        sim.Hide(params, 4, False)
        ])

    times8 = sim.PulseSequence([ \
        sim.Hide(params, 1, True),
        sim.Hide(params, 2, True), #vis: 3,4
        Fred34,
        sim.Hide(params, 2, False),
        sim.Hide(params, 4, True), #vis: 2,3
        Fred23,
        sim.Hide(params, 1, False),
        sim.Hide(params, 3, True), #vis: 1,2
        Fred12,
        sim.Hide(params, 3, False),
        sim.Hide(params, 4, False)
        ])

    times13 = copy.deepcopy(times8)
    times13.append(cnot1234)

    times7 = copy.deepcopy(times2)
    times7.append(cnot1234)


    ### general pulse sequence
    def GeneratePulseSeq(a):
    
        NOP = sim.PulseSequence([sim.Delay(params, 0.1)])

        if a in (2,7,8,13): # hard cases
            if firstMultMap:
                a2modN = cnot24
            else:
                a2modN = times4
        else:               # easy cases
            a2modN = NOP
        
        if   a == 2:
            amodN = times2
        elif a == 7:
            amodN = times7
        elif a == 8:
            amodN = times8
        elif a == 13:
            amodN = times13
        elif a == 4:
            amodN = cnot24
        elif a == 11:
            amodN = cnot13
        elif a == 14:
            amodN = cnot1234

        pulseseq_group = Kit.GeneratePulseSeq(params, [NOP, a2modN, amodN])
        return pulseseq_group
    
    #######################################################
    
    pulseseq = GeneratePulseSeq(select_a)
    
    if doIdeal:
        for ps in pulseseq:
            for pulse in ps:
                pulse.use_ideal = True
    
    ### run it
    if doRun:
        tic = time.time()
        result = Kit.simulateevolution(pulseseq, params, dec, doPP=doPPKitaev)
        if not doIdeal: print "runtime: ", time.time()-tic, "sec"
        print np.around(result,6)
    
    if saveKitaev:
        timestr = datetime.datetime.now().strftime('%Y%m%d-%H%M%S-%f')
        fnameappend = ''
        Kit.getQFTall()
        Kit.datagroupsave('Shor'+str(select_a)+'-data-'+fnameappend+timestr+'.pk', 
                          RhoOnly=True)
        Kit.resultSave('Shor'+str(select_a)+'-res-'+fnameappend+timestr+'.npy')
        f = open('Shor'+str(select_a)+'-params-'+fnameappend+timestr+'.pk', 'wb')
        pickle.dump(dec.dict_params_static, f)
        f.close()

    return True#dataobj
Exemplo n.º 8
0
def GeneratePulseSeq(a):

    NOP = lambda: sim.PulseSequence([sim.Delay(params, 0.1)])

    if a in (2, 7, 8, 13):  # hard cases
        if firstMultMap:
            a2modN = cnotij(2, 4)
        else:
            a2modN = sim.PulseSequence([ \
                sim.Hide(params, 1, True),
                sim.Hide(params, 3, True), #vis: 2,4
                Fredij(2,4),
                sim.Hide(params, 1, False),
                sim.Hide(params, 3, False),
                sim.Hide(params, 2, True),
                sim.Hide(params, 4, True), #vis: 1,3
                Fredij(1,3),
                sim.Hide(params, 2, False),
                sim.Hide(params, 4, False)
                ])
    else:  # easy cases
        a2modN = NOP()

    if a == 4:
        amodN = cnotij(2, 4)
    elif a == 11:
        amodN = cnotij(1, 3)
    elif a == 14:
        amodN = cnot1234()
    elif a in (8, 13):
        amodN = sim.PulseSequence([ \
            sim.Hide(params, 1, True),
            sim.Hide(params, 2, True), #vis: 3,4
            Fredij(3,4),
            sim.Hide(params, 2, False),
            sim.Hide(params, 4, True), #vis: 2,3
            Fredij(2,3),
            sim.Hide(params, 1, False),
            sim.Hide(params, 3, True), #vis: 1,2
            Fredij(1,2),
            sim.Hide(params, 3, False),
            sim.Hide(params, 4, False)
            ])
    elif a in (2, 7):
        amodN = sim.PulseSequence([ \
            sim.Hide(params, 3, True),
            sim.Hide(params, 4, True), #vis: 1,2
            Fredij(1,2),
            sim.Hide(params, 3, False),
            sim.Hide(params, 1, True), #vis: 2,3
            Fredij(2,3),
            sim.Hide(params, 4, False),
            sim.Hide(params, 2, True), #vis: 3,4
            Fredij(3,4),
            sim.Hide(params, 1, False),
            sim.Hide(params, 2, False) #vis: 1,2,3,4
            ])

    if a in (7, 13):
        amodN.append(cnot1234())

    # if   a == 2:
    #     amodN = times2
    # elif a == 7:
    #     # amodN = times7
    #     amodN = copy.deepcopy(times2)
    #     amodN.append(cnot1234)
    # elif a == 8:
    #     amodN = times8
    # elif a == 13:
    #     # amodN = times13
    #     amodN = copy.deepcopy(times8)
    #     amodN.append(cnot1234)
    # elif a == 4:
    #     amodN = cnot24
    # elif a == 11:
    #     amodN = cnot13
    # elif a == 14:
    #     amodN = cnot1234

    pulseseq_group = Kit.GeneratePulseSeq(params, [NOP(), a2modN, amodN])
    return pulseseq_group
Exemplo n.º 9
0
def GeneratePulseSeq(Perm, Perm2, Perm4, QFTseq, doKitaev):
    if not doKitaev:
        pulseseq = sim.PulseSequence([ \
            sim.Hide(params, 3, True),
            sim.Hide(params, 4, True),
            sim.Rcar(params, pi/2, -pi/2),
            sim.Hide(params, 3, False),
            sim.Hide(params, 4, False),
            sim.Hide(params, 0, True),
            sim.Hide(params, 1, True,),
            Perm, 
            Perm2,
            Perm4,
            sim.Hide(params, 0, False),
            sim.Hide(params, 1, False),
            sim.Hide(params, 2, False),
            sim.Hide(params, 3, True),
            sim.Hide(params, 4, True),
            QFTseq,
        ])
        return pulseseq
    else:
        pulseseq_group = Kit.GeneratePulseSeq(params, [Perm4, Perm2, Perm])

        return pulseseq_group
Exemplo n.º 10
0
                sim.Hide(params, 1, False),
                sim.Hide(params, 2, True),
                order32 ])
            Perm4 = sim.PulseSequence([ \
                sim.Hide(params, 2, True),
                sim.Hide(params, 1, True),
                sim.Hide(params, 0, False),
                order34, ])
        else:
            Perm2 = order32
            Perm4 = order34
    elif select_order == 4:
        Perm = order4
        if not doKitaev:
            Perm2 = sim.PulseSequence([ \
                sim.Hide(params, 1, False),
                sim.Hide(params, 2, True),
                order42 ])
        else:
            Perm2 = order42
        Perm4 = sim.Delay(params, 0.1)

    return Perm, Perm2, Perm4

### general pulse sequence
def GeneratePulseSeq(Perm, Perm2, Perm4, QFTseq, doKitaev):
    if not doKitaev:
        pulseseq = sim.PulseSequence([ \
            sim.Hide(params, 3, True),
            sim.Hide(params, 4, True),
            sim.Rcar(params, pi/2, -pi/2),