Ejemplo n.º 1
0
def doRamseyRun(hspace, params, dec):
    tdelay = np.linspace(0, 5000, 500)
    YR = np.zeros([len(tdelay), hspace.dimensions], np.complex64)
    pop = np.zeros([len(tdelay), hspace.dimensions], np.complex64)

    widgets = [progbar.Percentage(), " ", progbar.Bar(), " ", progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(len(tdelay)):
        pulseseq = sim.PulseSequence(
            [sim.Rcar(params, pi / 2, 0), sim.Delay(params, tdelay[i]), sim.Rcar(params, pi / 2, pi / 2)]
        )

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

        YR[i, :] = data.YR[-1, :]

        pbar.update(int(1.0 * (i + 1) * 100 / (len(tdelay))))

    data1 = sim.database(tdelay, YR, hspace, pulseseq=None, statesvalid=False)
    data1.tracedpopulation(0)

    [fitfun, par] = doRamseyFit(data1)

    return data1, fitfun, par
Ejemplo n.º 2
0
def data_optimize(inputparam, params, dec):
    ''' use this function to search for params.ACcorr given params.omac.  '''
    params.ACcorr = inputparam
    data = qc.simulateevolution(pulseseq, params, dec)
    data.tracedpopulation(1)

    return data.YtrI[-1]
Ejemplo n.º 3
0
    def run(self):
        ''' run the simulation and calculate final error '''

        # get the partial pulseseq and starting state
        if self.errormetric == "one":
            self.pulseseq_part = sim.PulseSequence([self.pulseseq.seq[self.gatepos]])
        else:
            self.pulseseq_part = sim.PulseSequence(self.pulseseq.seq[self.gatepos:])
        # if using population measures, estimate input densmat
        if self.fidtype == 'jozsafid' or self.fidtype == 'tracedist-rho':
            self.params.use_rho0(self.evalobj.rhoexp[self.gatepos])
        else:
            pop = np.diag(self.evalobj.rhoexp[self.gatepos])
            rhoIn = np.diag(pop)
            for ii in range(len(pop)):
                for jj in range(len(pop)):
                    if ii != jj:
                        rhoIn[ii, jj] = np.sqrt(pop[ii]*pop[jj]) * \
                            np.exp(1j * np.angle(self.evalobj.rho[self.gatepos][ii,jj]))
            self.params.use_rho0(rhoIn)

        # run it
        pulseseq_inst = copy.deepcopy(self.pulseseq_part)
        self.data = qc.simulateevolution(pulseseq_inst, self.params, self.dec)
        self.data.RhoPNAll = np.array(self.data.RhoPNAll)

        self.evalobj.data = self.data
        self.evalobj.calculate_sim_fidelities(self.fidelity, self.fidtype, \
                                                  startat=self.gatepos, \
                                                  one = (self.errormetric == "one"))

        simerror, simerror_std = self.getICFerror()

        return simerror, simerror_std
Ejemplo n.º 4
0
def test_heating_detailed(figNum):
    NumberOfIons = 1
    NumberofPhonons = 10
    hspace = sim.hspace(NumberOfIons,2,NumberofPhonons,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    # since data.RhoPNAll doesn't save phonons, we'll have to simulate sequentially
    numRuns = 5
    phonons = np.zeros(numRuns)

    dec.doRandNtimes = 1
    dec.dict['heating'] = True
    dec.progbar = False
    params.progbar = False
    params.heatingrate = 250
    maxDelay = 1000

    pulseseq = sim.PulseSequence( [ \
        sim.Delay(params, maxDelay), \
        ] )
    widgets = [progbar.Percentage(), ' ', progbar.Bar(),' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(numRuns): 
        data = qc.simulateevolution(pulseseq, params, dec)
        phonons[i] = qc.indexToState(np.nonzero(data.Yend)[0][0], hspace)[0]
        pbar.update(int(1.*(i+1)*100/numRuns))
    
    epsilon = np.abs(maxDelay/params.heatingrate - np.mean(phonons))

    return epsilon < 2*np.std(phonons)  # allow 2 sigma deviation
Ejemplo n.º 5
0
def MSpulseshaped():
    ''' demonstration of pulse shaping removing fast oscillations '''
    tic = time.time()

    params.shape = 5
    pulselen = np.linspace(10./86*pi/2, 2*pi, 4*160)
    realpulselen = np.zeros(len(pulselen))
    result = np.zeros([len(pulselen), 2])

    for i in range(len(pulselen)):
        print "pulse length ", pulselen[i]
        pulseseq = sim.PulseSequence( [ sim.RMS(params, pulselen[i], 0, -1) ] )
        realpulselen[i] = pulseseq[0].duration
        data = qc.simulateevolution(pulseseq, params, dec)
        data.tracedpopulation(0)
        result[i,:] = 1-data.YtrI[-1]

    toc = time.time()
 
    pl.plot(realpulselen, result)
    pl.show()

    print "MSpulseshaped() runtime ", toc-tic, "sec"

    return realpulselen, result
Ejemplo n.º 6
0
def MSpulseshaped():
    ''' demonstration of pulse shaping removing fast oscillations '''
    tic = time.time()

    params.shape = 5
    pulselen = np.linspace(10. / 86 * pi / 2, 2 * pi, 4 * 160)
    realpulselen = np.zeros(len(pulselen))
    result = np.zeros([len(pulselen), 2])

    for i in range(len(pulselen)):
        print "pulse length ", pulselen[i]
        pulseseq = sim.PulseSequence([sim.RMS(params, pulselen[i], 0, -1)])
        realpulselen[i] = pulseseq[0].duration
        data = qc.simulateevolution(pulseseq, params, dec)
        data.tracedpopulation(0)
        result[i, :] = 1 - data.YtrI[-1]

    toc = time.time()

    pl.plot(realpulselen, result)
    pl.show()

    print "MSpulseshaped() runtime ", toc - tic, "sec"

    return realpulselen, result
Ejemplo n.º 7
0
def doRamseyRun(hspace, params, dec):
    tdelay = np.linspace(0,5000,500)
    YR = np.zeros([len(tdelay),hspace.dimensions], np.complex64)
    pop = np.zeros([len(tdelay),hspace.dimensions], np.complex64)

    widgets = [progbar.Percentage(), ' ', progbar.Bar(),' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(len(tdelay)):
        pulseseq = sim.PulseSequence( [ \
            sim.Rcar(params, pi/2, 0), \
            sim.Delay(params, tdelay[i]), \
            sim.Rcar(params, pi/2, pi/2) \
            ] )

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

        YR[i,:] = data.YR[-1,:]

        pbar.update(int(1.*(i+1)*100/(len(tdelay))))

    data1 = sim.database(tdelay, YR, hspace, pulseseq=None, statesvalid = False)
    data1.tracedpopulation(0)

    [fitfun, par] = doRamseyFit(data1)

    return data1, fitfun, par
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def test_heating_detailed(figNum):
    NumberOfIons = 1
    NumberofPhonons = 10
    hspace = sim.hspace(NumberOfIons, 2, NumberofPhonons, 0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    # since data.RhoPNAll doesn't save phonons, we'll have to simulate sequentially
    numRuns = 5
    phonons = np.zeros(numRuns)

    dec.doRandNtimes = 1
    dec.dict['heating'] = True
    dec.progbar = False
    params.progbar = False
    params.heatingrate = 250
    maxDelay = 1000

    pulseseq = sim.PulseSequence( [ \
        sim.Delay(params, maxDelay), \
        ] )
    widgets = [progbar.Percentage(), ' ', progbar.Bar(), ' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(numRuns):
        data = qc.simulateevolution(pulseseq, params, dec)
        phonons[i] = qc.indexToState(np.nonzero(data.Yend)[0][0], hspace)[0]
        pbar.update(int(1. * (i + 1) * 100 / numRuns))

    epsilon = np.abs(maxDelay / params.heatingrate - np.mean(phonons))

    return epsilon < 2 * np.std(phonons)  # allow 2 sigma deviation
Ejemplo n.º 10
0
    def simulateevolution(self, pulseseq, params, dec, doPP=False):
        if not doPP:
            for ctl in range(2**(self.nOps-1)):
                print ctl
                data = qc.simulateevolution(pulseseq[ctl], params, dec)
                self.data_group.append(data)
                print np.around(data.register,3)
            result =  self.getQFT(self.data_group)

        else:
            job_server = pp.Server( \
                ncpus = 1, 
                ppservers = params.ppservers, 
                secret = params.ppsecret)

            self.data_group = [0 for _ in range(2**(self.nOps-1))]
            dec.doPPprintstats = True
            def jobfunc(x, pulseseq, params, dec):
                return PyTIQC.core.qctools.simulateevolution(pulseseq[x], params, dec)
            controls = range(2**(self.nOps-1))
            jobs = [(ctl, job_server.submit(jobfunc, \
                    args=(ctl, pulseseq, params, dec), \
                    modules=('numpy','scipy', 'PyTIQC.core.simtools', \
                             'PyTIQC.core.qctools', 'Kitaev',
                             'PyTIQC.core.qmtools', 'PyTIQC.core.sequel', \
                             'PyTIQC.tools.progressbar') ) )\
                         for ctl in controls ]
            for ctl, job in jobs:
                data1 = job()
                self.data_group[ctl] = data1

            result = self.getQFT(self.data_group)

        return self.result
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    def simulateevolution(self, pulseseq, params, dec, doPP=False):
        if not doPP:
            for ctl in range(2**(self.nOps-1)):
                print(ctl)
                data = qc.simulateevolution(pulseseq[ctl], params, dec)
                self.data_group.append(data)
                print(np.around(data.register,3))
            result =  self.getQFT(self.data_group)

        else:
            job_server = pp.Server( \
                ncpus = 4, 
                ppservers = params.ppservers, 
                secret = params.ppsecret)

            self.data_group = [0 for _ in range(2**(self.nOps-1))]
            dec.doPPprintstats = True
            def jobfunc(x, pulseseq, params, dec):
                return qc.simulateevolution(pulseseq[x], params, dec)
            controls = range(2**(self.nOps-1))
            jobs = [(ctl, job_server.submit(Kitaev.jobfunc, \
                    args=(copy.deepcopy(pulseseq[ctl]), params, dec), \
                    modules=('numpy','scipy', 'PyTIQC.core.simtools', \
                             'PyTIQC.core.qctools', 'Kitaev',
                             'PyTIQC.core.qmtools', 'PyTIQC.core.sequel', \
                             'progressbar') ) )\
                         for ctl in controls ]
            for ctl, job in jobs:
                data1 = job()
                self.data_group[ctl] = data1

            result = self.getQFT(self.data_group)

        return self.result
Ejemplo n.º 13
0
def test_dephasing_detailed(figNum):
    NumberOfIons = 1
    NumberofPhonons = 0
    hspace = sim.hspace(NumberOfIons, 2, NumberofPhonons, 0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    params.coherenceTime = 1000
    params.correlationTime = 0.1
    dec.doRandNtimes = 20
    dec.dict['dephase'] = True
    dec.progbar = False

    params.stepsize = 10
    params.ODEtimestep = 1
    params.detuning = 2 * pi * 0.01  #kHz
    params.progbar = False
    #dec.doPP = True
    #params.use_servers(['local'])
    #dec.doPPprintstats = False

    tdelay = np.linspace(0, 1000, 100)
    YR = np.zeros([len(tdelay), hspace.dimensions], np.complex64)
    pop = np.zeros([len(tdelay), hspace.dimensions], np.complex64)

    widgets = [progbar.Percentage(), ' ', progbar.Bar(), ' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(len(tdelay)):
        pulseseq = sim.PulseSequence( [ \
            sim.Rcar(params, pi/2, 0), \
            sim.Delay(params, tdelay[i]), \
            sim.Rcar(params, pi/2, pi/2) \
            ] )

        data = qc.simulateevolution(pulseseq, params, dec)
        YR[i, :] = data.YR[-1, :]

        pbar.update(int(1. * (i + 1) * 100 / (len(tdelay))))

    data1 = sim.database(tdelay, YR, hspace, pulseseq=None, statesvalid=False)
    data1.tracedpopulation(figNum)

    # fitting part
    p0 = [0.5, params.detuning, pi / 2, 0.5, params.coherenceTime]
    fitfun = lambda p, x: p[0] * np.cos(p[1] * x + p[2]) * np.exp(-np.log(
        2) * (x / p[4])**2) + p[3]
    errfun = lambda p, x, y: y - fitfun(p, x)
    x = data1.T
    y = data1.YR[:, 0]
    par, covmat, infodict, mesg, ier = leastsq(errfun,
                                               p0,
                                               args=(x, y),
                                               full_output=True)

    epsilon = 100  # with 20 iterations allow 100us offset in coherence time
    #print(par)
    return data1
Ejemplo n.º 14
0
def test_ACStark_detailed(figNum):
    NumberOfIons = 1
    hspace = sim.hspace(NumberOfIons,2,0,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    params.progbar = False

    pulseseq = sim.PulseSequence( [ \
        sim.Rcar(params, pi/2, 0),
        sim.Rac(params, 0, 0, 0),
        sim.Rcar(params, pi/2, 0)
        ] )

    ACtime = np.linspace(0,10*pi,100)
    realtime = np.zeros_like(ACtime)

    YR = np.zeros([len(ACtime), hspace.dimensions], dtype='complex')

    for i in range(len(ACtime)):
        pulseseq[1] = sim.Rac(params, ACtime[i], 0, 0)
        realtime[i] = pulseseq[1].duration
        data = qc.simulateevolution(pulseseq, params, dec)
        YR[i,:] = data.YR[-1,:]


    data1 = sim.database(realtime, YR, hspace, statesvalid = False)
    data1.tracedpopulation(figNum)

    # start with fit here
    x = data1.T
    y = data1.YtrN.transpose()[0] # this is the s-state population

    # p[0] ... amplitude, should be 1
    # p[1] ... freq, should be params.omc
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0

    startparams = np.array([1, params.omac, 0, 0])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: 1-p[0]*np.sin(p[1]*x/2+p[2])**2 + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(x,y), full_output = True)

    epsilon = 10**-3
    if par[0] - startparams[0] > epsilon:
        print("amplitude of AC oscillations wrong")
    if par[1] - startparams[1] > epsilon:
        print("frequency of AC oscillations wrong")
    if par[2] - startparams[2] > epsilon:
        print("phase of AC oscillations wrong")
    if par[3] - startparams[3] > epsilon:
        print("offset of AC oscillations wrong")

    return np.all(par-startparams < epsilon), data1, fitfun, par, startparams
Ejemplo n.º 15
0
def test_ACStark_detailed(figNum):
    NumberOfIons = 1
    hspace = sim.hspace(NumberOfIons,2,0,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    params.progbar = False

    pulseseq = sim.PulseSequence( [ \
        sim.Rcar(params, pi/2, 0),
        sim.Rac(params, 0, 0, 0),
        sim.Rcar(params, pi/2, 0)
        ] )

    ACtime = np.linspace(0,10*pi,100)
    realtime = np.zeros_like(ACtime)

    YR = np.zeros([len(ACtime), hspace.dimensions], dtype='complex')

    for i in range(len(ACtime)):
        pulseseq[1] = sim.Rac(params, ACtime[i], 0, 0)
        realtime[i] = pulseseq[1].duration
        data = qc.simulateevolution(pulseseq, params, dec)
        YR[i,:] = data.YR[-1,:]


    data1 = sim.database(realtime, YR, hspace, statesvalid = False)
    data1.tracedpopulation(figNum)

    # start with fit here
    x = data1.T
    y = data1.YtrN.transpose()[0] # this is the s-state population

    # p[0] ... amplitude, should be 1
    # p[1] ... freq, should be params.omc
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0

    startparams = np.array([1, params.omac, 0, 0])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: 1-p[0]*np.sin(p[1]*x/2+p[2])**2 + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(x,y), full_output = True)

    epsilon = 10**-3
    if par[0] - startparams[0] > epsilon:
        print "amplitude of AC oscillations wrong"
    if par[1] - startparams[1] > epsilon:
        print "frequency of AC oscillations wrong"
    if par[2] - startparams[2] > epsilon:
        print "phase of AC oscillations wrong"
    if par[3] - startparams[3] > epsilon:
        print "offset of AC oscillations wrong"

    return np.all(par-startparams < epsilon), data1, fitfun, par, startparams
Ejemplo n.º 16
0
def test_Rabi_carrier_detailed(figNum):
    #print(TestUserFUnction.figNum, TestUserFunction.figNum_start, "<<<<")
    NumberOfIons = 1
    PhononOverhead = 2

    hspace = sim.hspace(NumberOfIons,2,NumberOfIons+PhononOverhead,0)
    params = sim.parameters(hspace)
    params.stepsize = 1
    dec = sim.decoherence(params)

    params.y0[qc.stateToIndex('S,0', hspace)] = 1
    params.printpulse = False # don't print pulse details

    pulseseq = sim.PulseSequence( [
        sim.Rcar(params, 10*pi, 0, -1)
        ] )

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

    data.tracedpopulation(figNum)

    # start with fit here
    x = data.T
    y = data.YtrN.transpose()[0] # this is the s-state population

    # p[0] ... amplitude, should be 1
    # p[1] ... freq, should be params.omc
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0

    startparams = np.array([1, params.omc, 0, 0])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: 1-p[0]*np.sin(p[1]*x/2+p[2])**2 + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(x,y), full_output = True)

    #print(startparams)
    #print(par)

    #print(startparams-par)

    epsilon = 10**-5
    if par[0] - startparams[0] > epsilon:
        print("amplitude of Rabi oscillations wrong")
    if par[1] - startparams[1] > epsilon:
        print("frequency of Rabi oscillations wrong")
    if par[2] - startparams[2] > epsilon:
        print("phase of Rabi oscillations wrong")
    if par[3] - startparams[3] > epsilon:
        print("offset of Rabi oscillations wrong")


    return np.all(par-startparams < epsilon)
Ejemplo n.º 17
0
def test_Rabi_carrier_detailed(figNum):
    #print TestUserFUnction.figNum, TestUserFunction.figNum_start, "<<<<"
    NumberOfIons = 1
    PhononOverhead = 2

    hspace = sim.hspace(NumberOfIons,2,NumberOfIons+PhononOverhead,0)
    params = sim.parameters(hspace)
    params.stepsize = 1
    dec = sim.decoherence(params)

    params.y0[qc.stateToIndex('S,0', hspace)] = 1
    params.printpulse = False # don't print pulse details

    pulseseq = sim.PulseSequence( [
        sim.Rcar(params, 10*pi, 0, -1)
        ] )

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

    data.tracedpopulation(figNum)

    # start with fit here
    x = data.T
    y = data.YtrN.transpose()[0] # this is the s-state population

    # p[0] ... amplitude, should be 1
    # p[1] ... freq, should be params.omc
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0

    startparams = np.array([1, params.omc, 0, 0])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: 1-p[0]*np.sin(p[1]*x/2+p[2])**2 + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(x,y), full_output = True)

    #print startparams
    #print par

    #print startparams-par

    epsilon = 10**-5
    if par[0] - startparams[0] > epsilon:
        print "amplitude of Rabi oscillations wrong"
    if par[1] - startparams[1] > epsilon:
        print "frequency of Rabi oscillations wrong"
    if par[2] - startparams[2] > epsilon:
        print "phase of Rabi oscillations wrong"
    if par[3] - startparams[3] > epsilon:
        print "offset of Rabi oscillations wrong"


    return np.all(par-startparams < epsilon)
Ejemplo n.º 18
0
def test_dephasing_detailed(figNum):
    NumberOfIons = 1
    NumberofPhonons = 0
    hspace = sim.hspace(NumberOfIons,2,NumberofPhonons,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    params.coherenceTime = 1000
    params.correlationTime = 0.1
    dec.doRandNtimes = 20
    dec.dict['dephase'] = True
    dec.progbar = False

    params.stepsize = 10
    params.ODEtimestep = 1
    params.detuning = 2*pi*0.01  #kHz
    params.progbar = False
    #dec.doPP = True
    #params.use_servers(['local'])
    #dec.doPPprintstats = False

    tdelay = np.linspace(0,1000,100)
    YR = np.zeros([len(tdelay),hspace.dimensions], np.complex64)
    pop = np.zeros([len(tdelay),hspace.dimensions], np.complex64)

    widgets = [progbar.Percentage(), ' ', progbar.Bar(),' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(len(tdelay)):
        pulseseq = sim.PulseSequence( [ \
            sim.Rcar(params, pi/2, 0), \
            sim.Delay(params, tdelay[i]), \
            sim.Rcar(params, pi/2, pi/2) \
            ] )

        data = qc.simulateevolution(pulseseq, params, dec)
        YR[i,:] = data.YR[-1,:]

        pbar.update(int(1.*(i+1)*100/(len(tdelay))))

    data1 = sim.database(tdelay, YR, hspace, pulseseq=None, statesvalid = False)
    data1.tracedpopulation(figNum)

    # fitting part
    p0 = [0.5, params.detuning, pi/2, 0.5, params.coherenceTime]
    fitfun = lambda p, x: p[0] * np.cos(p[1]*x+p[2]) * np.exp(-np.log(2)*(x/p[4])**2) + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)
    x = data1.T
    y = data1.YR[:,0]
    par, covmat, infodict, mesg, ier = leastsq(errfun, p0, args=(x,y), full_output = True)
    
    epsilon = 100 # with 20 iterations allow 100us offset in coherence time
    #print par
    return data1
Ejemplo n.º 19
0
    def runSingle(self, index, param):
        """ run the simulation for one auto-generated pulse sequence """
        if self.verbose:
            print 'running parameter: '+str(param)
        self.simdec.progbar = False
        self.simdec.doPPprintstats = False
        # create the current seq
        pulseseq = self.get_full_sequence(param)

        dataobj = qc.simulateevolution(pulseseq, self.simparams, self.simdec)

        self.calc_output(dataobj, index)
        self.sampledata = dataobj
        if self.save_all_data:
            self.alldata.append(dataobj)
    def runSingle(self, index, param):
        """ run the simulation for one auto-generated pulse sequence """
        if self.verbose:
            print('running parameter: '+str(param))
        self.simdec.progbar = False
        self.simdec.doPPprintstats = False
        # create the current seq
        pulseseq = self.get_full_sequence(param)

        dataobj = qc.simulateevolution(pulseseq, self.simparams, self.simdec)

        self.calc_output(dataobj, index)
        self.sampledata = dataobj
        if self.save_all_data:
            self.alldata.append(dataobj)
Ejemplo n.º 21
0
def test_state_initialisation_detailed(figNum):
    NumberOfIons = 1
    NumberOfPhonons = 1

    hspace = sim.hspace(NumberOfIons, 2, NumberOfPhonons, 0)
    params = sim.parameters(hspace)
    params.stateiniterr = 0.2

    dec = sim.decoherence(params)

    dec.doPP = False
    dec.progbar = False
    dec.doRandNtimes = 10
    dec.dict['initerr'] = True

    params.y0[qc.stateToIndex(NumberOfIons * 'S' + ',0', hspace)] = 1

    pulseseq = sim.PulseSequence( [ \
        sim.Rcar(params, 5*pi, 0),
        ] )

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

    # start with fit here
    x = data.T
    y = data.YtrN.transpose()[-1]  # this is the d-state population

    # p[0] ... amplitude, should be 0.8
    # p[1] ... freq, should be params.omc
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0

    startparams = np.array([0.8, params.omc, 0, 0])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: p[0] * np.sin(p[1] * x / 2 + p[2])**2 + p[3]
    errfun = lambda p, x, y: y - fitfun(p, x)

    par, covmat, infodict, mesg, ier = leastsq(errfun,
                                               startparams,
                                               args=(x, y),
                                               full_output=True)
    #    print(par)

    # even for the 1000 realisations, allow for a 3% error
    epsilon = 0.03
    return abs(abs(par[0]) - startparams[0]) < epsilon
Ejemplo n.º 22
0
def test_state_initialisation_detailed(figNum):
    NumberOfIons = 1
    NumberOfPhonons = 1

    hspace = sim.hspace(NumberOfIons,2,NumberOfPhonons,0)
    params = sim.parameters(hspace)
    params.stateiniterr = 0.2

    dec = sim.decoherence(params)

    dec.doRandNtimes = 1000
    dec.dict['initerr'] = True

    params.y0[qc.stateToIndex(NumberOfIons*'S'+',0', hspace)] = 1

    pulseseq = sim.PulseSequence( [ \
        sim.Rcar(params, 5*pi, 0),
        ] )

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

    # start with fit here
    x = data.T
    y = data.YtrN.transpose()[-1] # this is the d-state population

    # p[0] ... amplitude, should be 0.8
    # p[1] ... freq, should be params.omc
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0

    startparams = np.array([0.8, params.omc, 0, 0])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: p[0]*np.sin(p[1]*x/2+p[2])**2 + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(x,y), full_output = True)
#    print par

    # even for the 1000 realisations, allow for a 3% error
    epsilon = 0.03
    return abs(abs(par[0])-startparams[0]) < epsilon
Ejemplo n.º 23
0
def parity(data, params):
    ''' check the parity of the pi/2 MS gate.
    must run expMS first. call: parity(data.Yend) '''

    phase = np.linspace(0, 2 * pi, 20)
    params.y0 = data.Yend
    P_PMT = data.P_PMT
    parity = np.zeros(len(phase))
    params.printpulse = False
    dec = sim.decoherence(params)

    widgets = [progbar.Percentage(), ' ', progbar.Bar(), ' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(len(phase)):
        pulseseq = sim.PulseSequence([sim.Rcar(params, pi / 2, phase[i], -1)])
        data = qc.simulateevolution(pulseseq, params, dec)
        data.tracedpopulation(0)
        parity[i] = data.YtrN[-1, 0] + data.YtrN[-1, 3] - data.YtrN[
            -1, 1] - data.YtrN[-1, 2]
        pbar.update(int(1. * (i + 1) * 100 / (len(phase))))

    def sinefunc(x, a, b):
        return -a * np.sin(2 * x) + b

    [p, pcov] = spop.curve_fit(sinefunc, phase, parity)

    population = P_PMT[-1, 0] + P_PMT[-1, -1]
    coherence = abs(p[0])
    fidelity = (population + coherence) / 2

    xphase = np.linspace(0, 2 * pi, 200)
    parityfit = sinefunc(xphase, p[0], p[1])
    pl.plot(phase, parity, '.', xphase, parityfit, '-')
    pl.xlabel('phase [rad]')
    pl.ylabel('parity')
    pl.show()

    print "population = ", population
    print "coherence contrast = ", coherence
    print "fidelity = ", fidelity
    return phase, parity, pulseseq
Ejemplo n.º 24
0
def parity(data, params):
    ''' check the parity of the pi/2 MS gate.
    must run expMS first. call: parity(data.Yend) '''

    phase = np.linspace(0,2*pi,20)
    params.y0 = data.Yend
    P_PMT = data.P_PMT
    parity = np.zeros(len(phase))
    params.printpulse = False
    dec = sim.decoherence(params)

    widgets = [progbar.Percentage(), ' ', progbar.Bar(),' ', progbar.ETA()]
    pbar = progbar.ProgressBar(widgets=widgets).start()

    for i in range(len(phase)):
        pulseseq = sim.PulseSequence( [ sim.Rcar(params, pi/2, phase[i], -1) ])
        data = qc.simulateevolution(pulseseq, params, dec)
        data.tracedpopulation(0)
        parity[i] = data.YtrN[-1,0] + data.YtrN[-1,3] - data.YtrN[-1,1] - data.YtrN[-1,2]
        pbar.update(int(1.*(i+1)*100/(len(phase))))

    def sinefunc(x, a, b):
        return -a*np.sin(2*x)+b

    [p,pcov] = spop.curve_fit(sinefunc, phase, parity)

    population = P_PMT[-1,0] + P_PMT[-1,-1]
    coherence = abs(p[0])
    fidelity = (population+coherence)/2

    xphase = np.linspace(0, 2*pi, 200)
    parityfit = sinefunc(xphase, p[0], p[1])
    pl.plot(phase, parity,'.', xphase, parityfit, '-')
    pl.xlabel('phase [rad]')
    pl.ylabel('parity')
    pl.show()

    print "population = ", population
    print "coherence contrast = ", coherence
    print "fidelity = ", fidelity
    return phase, parity, pulseseq
Ejemplo n.º 25
0
def test_spontdecay_detailed(figNum):
    NumberOfIons = 1
    NumberofPhonons = 1
    hspace = sim.hspace(NumberOfIons, 2, NumberofPhonons, 0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    dec.doRandNtimes = 100
    dec.dict['spontdecay'] = True
    dec.doPP = True
    dec.doPPprintstats = False
    dec.progbar = False
    # for the test we set it to 300 mus, instead of 1.168 s
    params.lifetime = 300

    params.y0[qc.stateToIndex(NumberOfIons * 'D' + ',0', hspace)] = 1
    params.y0[qc.stateToIndex(NumberOfIons * 'S' + ',0', hspace)] = 0

    pulseseq = sim.PulseSequence( [ \
        sim.Delay(params, 1000), \
        ] )

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

    # fitting part
    p0 = [1, params.lifetime]
    fitfun = lambda p, x: p[0] * np.exp(-x / float(p[1]))
    errfun = lambda p, x, y: y - fitfun(p, x)
    x = data.T
    y = data.YtrN[:, 0]
    par, covmat, infodict, mesg, ier = leastsq(errfun,
                                               p0,
                                               args=(x, y),
                                               full_output=True)

    epsilon = 50  # with 100 iterations allow 50us offset in decay time

    #    print(np.abs(par[-1] - params.lifetime))
    return np.abs(par[-1] - params.lifetime) < epsilon
Ejemplo n.º 26
0
def timestepcheck(params, dec):
    ''' check that timestep chosen for ODE is converged '''
    timesteps = np.logspace(0, -3, 10)
    result = np.zeros([len(timesteps), 2])

    params.shape = 5
    params.printpulse = False
    pulseseq = sim.PulseSequence( [ sim.RMS(params, pi/2, 0, -1) ] )

    for i in range(len(timesteps)):
        params.ODEtimestep = timesteps[i]
        print "timestep = ", params.ODEtimestep
        data = qc.simulateevolution(pulseseq, params, dec)
        result[i,0] = abs(data.Yend[0])**2
        result[i,1] = abs(data.Yend[int(3*len(data.Yend)/4)])**2

    pl.semilogx(timesteps, result[:,0], '.:')
    pl.xlabel('ODE timestep, [us]')
    pl.ylabel('State population')
    pl.title('convergence of ODE solver vs timestep')
#    pl.legend(['p(DD,0)', 'p(SS,0)'], loc=2)

    return timesteps, result
Ejemplo n.º 27
0
def timestepcheck(params, dec):
    ''' check that timestep chosen for ODE is converged '''
    timesteps = np.logspace(0, -3, 10)
    result = np.zeros([len(timesteps), 2])

    params.shape = 5
    params.printpulse = False
    pulseseq = sim.PulseSequence([sim.RMS(params, pi / 2, 0, -1)])

    for i in range(len(timesteps)):
        params.ODEtimestep = timesteps[i]
        print "timestep = ", params.ODEtimestep
        data = qc.simulateevolution(pulseseq, params, dec)
        result[i, 0] = abs(data.Yend[0])**2
        result[i, 1] = abs(data.Yend[int(3 * len(data.Yend) / 4)])**2

    pl.semilogx(timesteps, result[:, 0], '.:')
    pl.xlabel('ODE timestep, [us]')
    pl.ylabel('State population')
    pl.title('convergence of ODE solver vs timestep')
    #    pl.legend(['p(DD,0)', 'p(SS,0)'], loc=2)

    return timesteps, result
Ejemplo n.º 28
0
def test_spontdecay_detailed(figNum):
    NumberOfIons = 1
    NumberofPhonons = 1
    hspace = sim.hspace(NumberOfIons,2,NumberofPhonons,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    dec.doRandNtimes = 100
    dec.dict['spontdecay'] = True
    dec.doPP = True
    dec.doPPprintstats = False
    dec.progbar = False
    # for the test we set it to 300 mus, instead of 1.168 s
    params.lifetime = 300

    params.y0[qc.stateToIndex(NumberOfIons*'D'+',0', hspace)] = 1
    params.y0[qc.stateToIndex(NumberOfIons*'S'+',0', hspace)] = 0

    pulseseq = sim.PulseSequence( [ \
        sim.Delay(params, 1000), \
        ] )

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

    # fitting part
    p0 = [1, params.lifetime]
    fitfun = lambda p, x: p[0] * np.exp(-x / float(p[1]))
    errfun = lambda p, x, y: y-fitfun(p,x)
    x = data.T
    y = data.YtrN[:,0]
    par, covmat, infodict, mesg, ier = leastsq(errfun, p0, args=(x,y), full_output = True)
    
    epsilon = 50 # with 100 iterations allow 50us offset in decay time

#    print np.abs(par[-1] - params.lifetime)
    return np.abs(par[-1] - params.lifetime) < epsilon
Ejemplo n.º 29
0
    def run(self):
        ''' run the simulation and calculate final error '''

        # get the partial pulseseq and starting state
        if self.errormetric == "one":
            self.pulseseq_part = sim.PulseSequence(
                [self.pulseseq.seq[self.gatepos]])
        else:
            self.pulseseq_part = sim.PulseSequence(
                self.pulseseq.seq[self.gatepos:])
        # if using population measures, estimate input densmat
        if self.fidtype == 'jozsafid' or self.fidtype == 'tracedist-rho':
            self.params.use_rho0(self.evalobj.rhoexp[self.gatepos])
        else:
            pop = np.diag(self.evalobj.rhoexp[self.gatepos])
            rhoIn = np.diag(pop)
            for ii in range(len(pop)):
                for jj in range(len(pop)):
                    if ii != jj:
                        rhoIn[ii, jj] = np.sqrt(pop[ii]*pop[jj]) * \
                            np.exp(1j * np.angle(self.evalobj.rho[self.gatepos][ii,jj]))
            self.params.use_rho0(rhoIn)

        # run it
        pulseseq_inst = copy.deepcopy(self.pulseseq_part)
        self.data = qc.simulateevolution(pulseseq_inst, self.params, self.dec)
        self.data.RhoPNAll = np.array(self.data.RhoPNAll)

        self.evalobj.data = self.data
        self.evalobj.calculate_sim_fidelities(self.fidelity, self.fidtype, \
                                                  startat=self.gatepos, \
                                                  one = (self.errormetric == "one"))

        simerror, simerror_std = self.getICFerror()

        return simerror, simerror_std
Ejemplo n.º 30
0
def test_Ramsey_carrier_detailed(figNum):
    NumberOfIons = 1
    PhononOverhead = 2

    hspace = sim.hspace(NumberOfIons,2,NumberOfIons+PhononOverhead,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    params.y0[qc.stateToIndex('S,0', hspace)] = 1
    params.stepsize = 1
    params.printpulse = False # don't print pulse details

    numberofpoints = 20
    phi = np.linspace(0, 2*pi, numberofpoints)
    ex = np.zeros(numberofpoints)

    for i in range(numberofpoints):
        pulseseq = sim.PulseSequence( [
            sim.Rcar(params, pi/2, 0, -1),
#            sim.Delay(params, tdelay[i]),
            sim.Rcar(params, pi/2, phi[i], -1)
            ])

        data = qc.simulateevolution(pulseseq, params, dec)
        data.tracedpopulation(figNum)
        ex[i] = data.YtrN[-1,0]

    # fig1 = pl.figure(1)
    # ax1 = fig1.add_subplot(111)
    # ax1.plot(phi, ex)
    # fig1.show()


    # p[0] ... amplitude, should be 1
    # p[1] ... because phase is in units of pi -> 1
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0.5

    startparams = np.array([1, 1, 0, 0.5])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: p[0]/2*np.cos(p[1]*x+p[2]) + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(phi,ex), full_output = True)

    #print startparams
    #print par

    #print startparams-par

    epsilon = 10**-5

    if par[0] - startparams[0] > epsilon:
        print "amplitude of Ramsey experiment wrong"
    if par[1] - startparams[1] > epsilon:
        print "frequency of Ramsey experiment wrong"
    if par[2] - startparams[2] > epsilon:
        print "phase of Ramsey experiment wrong"
    if par[3] - startparams[3] > epsilon:
        print "offset of Ramsey experiment wrong"


    return np.all(par-startparams < epsilon)
Ejemplo n.º 31
0
def test_Ramsey_carrier_detailed(figNum):
    NumberOfIons = 1
    PhononOverhead = 2

    hspace = sim.hspace(NumberOfIons,2,NumberOfIons+PhononOverhead,0)
    params = sim.parameters(hspace)
    dec = sim.decoherence(params)

    params.y0[qc.stateToIndex('S,0', hspace)] = 1
    params.stepsize = 1
    params.printpulse = False # don't print pulse details

    numberofpoints = 20
    phi = np.linspace(0, 2*pi, numberofpoints)
    ex = np.zeros(numberofpoints)

    for i in range(numberofpoints):
        pulseseq = sim.PulseSequence( [
            sim.Rcar(params, pi/2, 0, -1),
#            sim.Delay(params, tdelay[i]),
            sim.Rcar(params, pi/2, phi[i], -1)
            ])

        data = qc.simulateevolution(pulseseq, params, dec)
        data.tracedpopulation(figNum)
        ex[i] = data.YtrN[-1,0]

    # fig1 = pl.figure(1)
    # ax1 = fig1.add_subplot(111)
    # ax1.plot(phi, ex)
    # fig1.show()


    # p[0] ... amplitude, should be 1
    # p[1] ... because phase is in units of pi -> 1
    # p[2] ... phase, should be 0
    # p[3] ... offset, should be 0.5

    startparams = np.array([1, 1, 0, 0.5])

    # 1-data ... to get the D-state population
    fitfun = lambda p, x: p[0]/2*np.cos(p[1]*x+p[2]) + p[3]
    errfun = lambda p, x, y: y-fitfun(p,x)

    par, covmat, infodict, mesg, ier = leastsq(errfun, startparams, args=(phi,ex), full_output = True)

    #print(startparams)
    #print(par)

    #print(startparams-par)

    epsilon = 10**-5

    if par[0] - startparams[0] > epsilon:
        print("amplitude of Ramsey experiment wrong")
    if par[1] - startparams[1] > epsilon:
        print("frequency of Ramsey experiment wrong")
    if par[2] - startparams[2] > epsilon:
        print("phase of Ramsey experiment wrong")
    if par[3] - startparams[3] > epsilon:
        print("offset of Ramsey experiment wrong")


    return np.all(par-startparams < epsilon)
Ejemplo n.º 32
0
 def jobfunc(x, pulseseq, params, dec):
     return qc.simulateevolution(pulseseq[x], params, dec)
Ejemplo n.º 33
0
pulseseq = sim.PulseSequence( [ \
    sim.Rcar(params, pi/2, 0),
    sim.Rac(params, pi/2, 0, 0),
    sim.RMS(params, pi/4, 0),
    sim.Rcar(params, pi/4, 0),
    sim.Rac(params, pi, 0, 2),
    sim.Rcar(params, pi/4, 0),
    sim.RMS(params, pi/4, 0),
    sim.Rac(params, pi/2, 0, 0),
    sim.Rcar(params, pi/2, 0),
    sim.Rac(params, pi, 0, 2)
    ] )

#params.y0[qc.stateToIndex('DDD' + ',0', hspace)] =  0.25-0.25j
#params.y0[qc.stateToIndex('DDS' + ',0', hspace)] = -0.25-0.25j
#params.y0[qc.stateToIndex('DSD' + ',0', hspace)] = -0.25-0.25j
#params.y0[qc.stateToIndex('DSS' + ',0', hspace)] = -0.25+0.25j
#params.y0[qc.stateToIndex('SDD' + ',0', hspace)] =  0.25-0.25j
#params.y0[qc.stateToIndex('SDS' + ',0', hspace)] = -0.25-0.25j
#params.y0[qc.stateToIndex('SSD' + ',0', hspace)] = -0.25-0.25j
#params.y0[qc.stateToIndex('SSS' + ',0', hspace)] = -0.25+0.25j

tic = time.clock()
data = qc.simulateevolution(pulseseq, params, dec)
toc = time.clock()
print "runtime: ", toc - tic, " sec"

data.statesatpulse(2)
data.endpopulation()
Ejemplo n.º 34
0
import PyTIQC.core.qctools as qc

pi = np.pi

hspace = sim.hspace(2,2,2,0)
params = sim.parameters(hspace)
dec = sim.decoherence(params)

params.y0[qc.stateToIndex('SS,0', hspace)] = 1
params.stepsize = 10
params.ignorelightshift = 1
#params.addressing = np.array([[1,0.1],[0.1,1]])

ang = np.arccos(-np.real(np.exp(pi/2*1j*np.sqrt(2))));
pulseseq = sim.PulseSequence( [ \
    sim.Rblue(params, pi, 0, 0), \
    sim.Rcar(params, pi/2, 0, 1), \
    sim.Rblue(params, pi/2, 0, 1), \
    sim.Rblue(params, np.sqrt(2)*pi, pi/2, 1), \
    sim.Rblue(params, pi/2, pi, 1), \
    sim.Rcar(params, pi/2, pi + ang, 1), \
    sim.Rblue(params, pi, 0, 0) \
    ] )

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

data.displaypopulation(1)
data.tracedpopulation(2)