def calculateGateFidelity(self, std):
        ''' extract gate fidelity from the *current* stored unitaries '''
        # note!!! self.data.pulseseq not self.pulseseq
        gatefid = []
        for pulse in self.data.pulseseq:
            gatefid_pulse = []
            if not pulse.use_ideal:
                for i in range(self.data.numruns):
                    chi_id = qproc.Unitary2Chi(pulse.Uidtr)
                    chi_sim = qproc.Unitary2Chi(pulse.UtrAll[i])
                    #print "Unitaries:"
                    #print np.around(chi_id,3) # TEMP
                    #print np.around(chi_sim,3)
                    gatefid_pulse.append(U.fidelity(chi_id, chi_sim))
                gatefid.append(gatefid_pulse)

        gatefid = np.array(gatefid).flatten()
        self.gatefidsample = gatefid

        fid_mean = np.mean(gatefid)
        fid_std = np.std(gatefid)
        fid_med = np.median(gatefid)
        fid_75qtl = spst.scoreatpercentile(gatefid, 75)
        fid_25qtl = spst.scoreatpercentile(gatefid, 25)

        if std:
            return fid_mean, fid_mean + fid_std, fid_mean - fid_std
        else:
            return fid_med, fid_75qtl, fid_25qtl
    def calcAllFid(rho, rhoexp, displ=1):
        ''' calculate final fidelity using different measures '''
        fidelity_exp = np.zeros(len(rho))
        sso_exp = np.zeros(len(rho))
        popdist_exp = np.zeros(len(rho))

        for i in range(len(rho)):
            fidelity_exp[i] = U.fidelity(rho[i], rhoexp[i])
            sso_exp[i] = U.sso(rho[i], rhoexp[i])
            popdist_exp[i] = U.popdist(rho[i], rhoexp[i])

        fig = pl.figure(displ)
        fig.clf()
        ax = fig.add_subplot(111)
        ax.plot(fidelity_exp, '.-')
        ax.plot(sso_exp, '.-')
        ax.plot(popdist_exp, '.-')
        ax.set_ylim([
            np.min(np.hstack([fidelity_exp, sso_exp, popdist_exp])) - 0.05, 1
        ])
        ax.set_xlabel('pulse #')
        ax.set_ylabel('state fidelity')
        ax.legend(['fidelity', 'sso', 'popdist'], loc='lower left')
        fig.show()

        return fidelity_exp, sso_exp, popdist_exp
    def calculateGateFidelity(self, std):
        ''' extract gate fidelity from the *current* stored unitaries '''
        # note!!! self.data.pulseseq not self.pulseseq
        gatefid = []
        for pulse in self.data.pulseseq: 
            gatefid_pulse = []
            if not pulse.use_ideal:
              for i in range(self.data.numruns):
                chi_id = qproc.Unitary2Chi(pulse.Uidtr)
                chi_sim = qproc.Unitary2Chi(pulse.UtrAll[i])
                #print "Unitaries:"
                #print np.around(chi_id,3) # TEMP
                #print np.around(chi_sim,3)
                gatefid_pulse.append(U.fidelity(chi_id, chi_sim))
              gatefid.append(gatefid_pulse)

        gatefid = np.array(gatefid).flatten()
        self.gatefidsample = gatefid

        fid_mean = np.mean(gatefid)
        fid_std = np.std(gatefid)
        fid_med = np.median(gatefid)
        fid_75qtl = spst.scoreatpercentile(gatefid, 75)
        fid_25qtl = spst.scoreatpercentile(gatefid, 25)

        if std:
            return fid_mean, fid_mean+fid_std, fid_mean-fid_std
        else:
            return fid_med, fid_75qtl, fid_25qtl
Exemple #4
0
    def calcAllFid(rho, rhoexp, displ=1):
        ''' calculate final fidelity using different measures '''
        fidelity_exp = np.zeros(len(rho))
        sso_exp = np.zeros(len(rho))
        popdist_exp = np.zeros(len(rho))

        for i in range(len(rho)):
            fidelity_exp[i] = U.fidelity(rho[i], rhoexp[i])
            sso_exp[i] = U.sso(rho[i], rhoexp[i])
            popdist_exp[i] = U.popdist(rho[i], rhoexp[i])

        fig = pl.figure(displ)
        fig.clf()
        ax = fig.add_subplot(111)
        ax.plot(fidelity_exp, '.-')
        ax.plot(sso_exp, '.-')
        ax.plot(popdist_exp, '.-')
        ax.set_ylim([np.min(np.hstack([fidelity_exp, sso_exp, popdist_exp]))-0.05, 1])
        ax.set_xlabel('pulse #')
        ax.set_ylabel('state fidelity')
        ax.legend(['fidelity', 'sso', 'popdist'], loc='lower left')
        fig.show()

        return fidelity_exp, sso_exp, popdist_exp