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
def test_ProcTomo_detailed(): NumberOfIons = 1 PhononOverhead = 7 hspace = sim.hspace(NumberOfIons, 2, NumberOfIons + PhononOverhead, 0) params = sim.parameters(hspace) dec = sim.decoherence(params) params.y0[qc.stateToIndex('S,0', hspace)] = 1 pulseseq = sim.PulseSequence( [ \ sim.Rcar(params, pi/2,0), ] ) ScanObj = IPS.ScanParameter_in_Sequence(pulseseq, params, dec, np.arange(12**NumberOfIons), type='ProcTomo') ScanObj.runScan() data_proctom = ScanObj.output_dict['qstates_camera'] chi = proctom.proctomo(data_proctom, 100) #if np.real(chi[0,0]) > 0.99: # print 'proctomo passed' chiId = qproc.Unitary2Chi(pulseseq[0].Uidtr.conjugate()) return np.max(abs(chi - chiId)) < 0.001
def test_StateTomo_detailed(): NumberOfIons = 2 PhononOverhead = 1 hspace = sim.hspace(NumberOfIons, 2, NumberOfIons + PhononOverhead, 0) params = sim.parameters(hspace) dec = sim.decoherence(params) params.y0[qc.stateToIndex('SS,0', hspace)] = 1 pulseseq = sim.PulseSequence( [ \ sim.Rcar(params, 2*pi, 0, 0), \ ] ) ScanObj = IPS.ScanParameter_in_Sequence(pulseseq, params, dec, np.arange(3**NumberOfIons), type='StateTomo') ScanObj.runScan() data_dmr = ScanObj.output_dict['qstates_camera'] rho = dmr.IterML.iterfun(data_dmr, 100) #if np.real(rho[3,3]) > 0.99: # print 'statetomo passed' return np.real(rho[3, 3]) > 0.99
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
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
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
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
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
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
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
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
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)
def cnot1234(): return sim.PulseSequence([ \ sim.Rcar(params, 1.5*pi, 0*pi), sim.Rac(params, 1.5*pi, 0, 0), sim.RMS(params, 0.25*pi, 0.5*pi), sim.Rcar(params, 0.75*pi, 0*pi), sim.Rac(params, 1*pi, 0, 0), sim.RMS(params, 1.75*pi, 0.5*pi), sim.Rcar(params, 0.75*pi, 0*pi), sim.Rac(params, 1.5*pi, 0, 0), sim.Rcar(params, 0.5*pi, 0*pi) ])
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, ]) 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
def GeneratePulseSeq(self, params, Perms, perm2=None, perm3=None): #Legacy support for old-style calls: if perm2 and perm3: Perms = [Perms, perm2, perm3] ''' generate pulse sequences given all permutations '''\ self.nOps = len(Perms) controlRots = [ \ [sim.Delay(params, sim.Rac(params, pi/2**(i+1), 0, 0).duration), sim.Rac(params, pi/2**(i+1), 0, 0)] for i in range(self.nOps)] Hadamard0 = sim.PulseSequence( [ \ sim.Rcar(params, pi/4, pi), sim.Rac(params, pi, 0), sim.Rcar(params, pi/4, 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(Hadamard0) pulseseq.append(Perms[k]) pulseseq += [copy.deepcopy(controlRots[i] \ [int(ctlstr[self.nOps-i-k-1])]) for i in range(k)] pulseseq.append(Hadamard0) 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 pulseseq_group = [] for ctl in range(2**(self.nOps - 1)): pulseseq_group.append(PulseSeqWithControls(ctl)) return pulseseq_group
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
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
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
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
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
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
def calculateGateFidelityProcTomo(self, ErrorBars=False, ind=None): ''' use proctomo to convert error of gate to fidelity ''' #print "Using ProcTomo to calculate gate fidelity. This may take a while ..." if ind != None: indreal = [ind] if ErrorBars: indreal = [ind, ind, ind] elif not ErrorBars: indreal = [self.error0] else: indreal = [self.error0, self.error0max, self.error0min] result = [] for ind in indreal: if self.noisetype == 'all': for noisetype in self.dec.dict_params_static.keys(): self.setNoiseAmp(noisetype, ind) else: self.setNoiseAmp(self.noisetype, ind) if not self.verbose: widgets = [ progressbar.Percentage(), ' ', progressbar.Bar(), ' ', progressbar.ETA() ] pbar = progressbar.ProgressBar(widgets=widgets).start() else: pbar = None pos = self.gates[0] # only do it once, for now newpulseseq = sim.PulseSequence( [copy.deepcopy(self.pulseseq[pos])]) self.pulseseq[pos].UtrAll = [] newpulseseq[0].use_ideal = False ScanObj = ips.ScanParameter_in_Sequence( newpulseseq, self.params, self.dec, np.arange(12**self.params.hspace.nuions), type='ProcTomo', verbose=self.verbose, doPP=True, use_ideal=True, pbar=pbar) ScanObj.runScan(batchsize=40) data_proctom = ScanObj.output_dict['qstates_camera'] chi = proctom.proctomo(data_proctom, 100) chiId = qproc.Unitary2Chi(newpulseseq[0].Uidtr.conjugate()) result.append(U.jozsafid(chiId, chi)) #print "PT:" #print np.around(chiId,3) #print np.around(chi,3) # TEMP if ind != None and ErrorBars: result.sort() result.append(result[0]) result.remove(result[0]) if not ErrorBars: print self._printGatetype(self.gatetype), ":", np.around( result[0], 4) return [result[0], result[0], result[0]] else: print self._printGatetype( self.gatetype) + " : %0.4f + %0.4f - %0.4f" % (np.around( result[0], 4), np.around(result[1] - result[0], 4), np.around(result[0] - result[2], 4)) return result
''' pulse sequences for order-finding ''' import PyTIQC.core.simtools as sim # order 1 - Toffoli(1,3,2) - from Volkmarizer order1 = sim.PulseSequence( [ \ sim.Rcar(params, pi/2, pi/2), #0 sim.Rac(params, pi/4, 0, 1), #1 sim.RMS(params, pi/2, pi/2), #2 sim.Rcar(params, pi/2,pi), #3 sim.Rac(params, 3*pi/2, 0, 1), #4 sim.Rcar(params, pi/4,1*pi), #5 sim.RMS(params, pi/4, pi/2), #6 sim.Rac(params, pi/2, 0, 1), #7 sim.RMS(params, pi/2, pi/2), #8 sim.Rcar(params, pi/2,0*pi), #9 sim.Rcar(params, pi/2,-pi/2) ]) # order 2 - CNOT(1,3) - from paper (IV.A first one) order2 = sim.PulseSequence( [ \ sim.Rcar(params, pi/2, 0), sim.Rac(params, 7*pi/2, 0, 2), # 3pi/2 in experiment sim.RMS(params, pi/4, pi/2), sim.Rcar(params, pi/4, 0), sim.Rac(params, 3*pi, 0, 1), sim.Rcar(params, pi/4, 0), sim.RMS(params, pi/4, pi/2), sim.Rac(params, 7*pi/2, 0, 2), sim.Rcar(params, pi/2, 0), sim.Rac(params, 3*pi, 0, 1) ])
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
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)
runStateTomo = False runStateTomoPP = False runProcTomo = False runProcTomoPP = True if runStateTomo or runStateTomoPP: NumberOfIons = 2 PhononOverhead = 1 hspace = sim.hspace(NumberOfIons,2,NumberOfIons+PhononOverhead,0) params = sim.parameters(hspace) dec = sim.decoherence(params) params.use_servers(['lindhard']) pulseseq = sim.PulseSequence( [ \ sim.Rcar(params, 2*pi, 0, 0), ] ) if runStateTomo: ScanObj = ScanParameter_in_Sequence(pulseseq, params, dec, np.arange(3**NumberOfIons), type='StateTomo', verbose=True) elif runStateTomoPP: ScanObj = ScanParameter_in_Sequence(pulseseq, params, dec, np.arange(3**NumberOfIons), type='StateTomo', verbose=True, doPP=True, use_ideal=True) ScanObj.runScan() data_dmr = ScanObj.output_dict['qstates_camera'] rho = dmr.IterML.iterfun(data_dmr, 100) if np.real(rho[-1,-1]) > 0.99: print('statetomo passed') else: print('statetomo failed')
NumberOfIons = 3 NumberOfPhonons = 7 hspace = sim.hspace(NumberOfIons, 2, NumberOfPhonons, 0) params = sim.parameters(hspace) params.stepsize = 100 params.printpulse = True dec = sim.decoherence(params) 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
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
########################################## # 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) if a == 7: a2modN = shor7b amodN = shor7a elif a == 11:
params = sim.parameters(hspace) dec = sim.decoherence(params) #dec.doRandNtimes = 1 #dec.dict['all'] = True #dec.doPP = False #params.use_servers( ['local']) params.progbar = True #params.shortestMS = 4 params.calcPulseParams() pulseseq = sim.PulseSequence( [ \ # sim.Hide(params, 3, True), # sim.Hide(params, 4, True), sim.RMS(params, pi/2, 0), #sim.Rcar(params, pi/2, pi/2) ] ) data = qc.simulateevolution(pulseseq, params, dec) data.displaypopulation(0) data.displayPMTpopulations(1) #data.displayPhaseSpace(0) #################################################### # extra post-run diagnostic functions def data_optimize(inputparam, params, dec):