示例#1
0
"""

import gatestringconstruction as _strc
import gatesetconstruction as _setc

description = "X(pi/2) and Z(pi/2) gates"

gates = ['Gx','Gz']
prepFiducials = _strc.gatestring_list([(),
                                       ('Gx',),
                                       ('Gx','Gz'),
                                       ('Gx','Gx'),
                                       ('Gx','Gx','Gx'),
                                       ('Gx','Gz','Gx','Gx')]) # for 1Q MUB
                                               
measFiducials = _strc.gatestring_list([(),
                                       ('Gx',),
                                       ('Gz','Gx'),
                                       ('Gx','Gx'),
                                       ('Gx','Gx','Gx'),
                                       ('Gx','Gx','Gz','Gx')])
                                               
germs = _strc.gatestring_list( [('Gx',), ('Gz',), ('Gz','Gx','Gx'), ('Gz','Gz','Gx')] )

#Construct a target gateset:  X(pi/2), Z(pi/2)
gs_target = _setc.build_gateset([2],[('Q0',)], ['Gx','Gz'], 
                                [ "X(pi/2,Q0)", "Z(pi/2,Q0)"],
                                prepLabels=["rho0"], prepExpressions=["0"],
                                effectLabels=["E0"], effectExpressions=["1"], 
                                spamdefs={'plus': ('rho0','E0'), 'minus': ('rho0','remainder') } )
示例#2
0
def rpe_ensemble_test(alphaTrue,
                      epsilonTrue,
                      Yrot,
                      SPAMdepol,
                      log2kMax,
                      N,
                      runs,
                      plot=False,
                      savePlot=False):
    """ Experimental test function """
    kList = [2**k for k in range(log2kMax + 1)]

    alphaCosStrList, alphaSinStrList = make_rpe_alpha_str_lists_gx_gz(kList)
    epsilonCosStrList, epsilonSinStrList = make_rpe_epsilon_str_lists_gx_gz(
        kList)
    thetaCosStrList, thetaSinStrList = make_rpe_theta_str_lists_gx_gz(kList)

    percentAlphaError = 100 * _np.abs((_np.pi / 2 - alphaTrue) / alphaTrue)
    percentEpsilonError = 100 * _np.abs(
        (_np.pi / 4 - epsilonTrue) / epsilonTrue)

    simGateset = _setc.build_gateset([2], [('Q0', )], ['Gi', 'Gx', 'Gz'], [
        "I(Q0)", "X(" + str(epsilonTrue) + ",Q0)",
        "Z(" + str(alphaTrue) + ",Q0)"
    ],
                                     prepLabels=["rho0"],
                                     prepExpressions=["0"],
                                     effectLabels=["E0"],
                                     effectExpressions=["1"],
                                     spamdefs={
                                         'plus': ('rho0', 'E0'),
                                         'minus': ('rho0', 'remainder')
                                     })

    gatesetAux1 = _setc.build_gateset(
        [2], [('Q0', )], ['Gi', 'Gy', 'Gz'],
        ["I(Q0)", "Y(" + str(Yrot) + ",Q0)", "Z(pi/2,Q0)"],
        prepLabels=["rho0"],
        prepExpressions=["0"],
        effectLabels=["E0"],
        effectExpressions=["1"],
        spamdefs={
            'plus': ('rho0', 'E0'),
            'minus': ('rho0', 'remainder')
        })

    simGateset.gates['Gx'] = _objs.FullyParameterizedGate(
        _np.dot(
            _np.dot(_np.linalg.inv(gatesetAux1.gates['Gy']),
                    simGateset.gates['Gx']), gatesetAux1.gates['Gy']))

    simGateset = simGateset.depolarize(spam_noise=SPAMdepol)

    thetaTrue = _tools.rpe.extract_theta(simGateset)

    SPAMerror = _np.dot(simGateset.effects['E0'].T,
                        simGateset.preps['rho0'])[0, 0]

    jMax = runs

    alphaHatListArray = _np.zeros([jMax, log2kMax + 1], dtype='object')
    epsilonHatListArray = _np.zeros([jMax, log2kMax + 1], dtype='object')
    thetaHatListArray = _np.zeros([jMax, log2kMax + 1], dtype='object')

    alphaErrorArray = _np.zeros([jMax, log2kMax + 1], dtype='object')
    epsilonErrorArray = _np.zeros([jMax, log2kMax + 1], dtype='object')
    thetaErrorArray = _np.zeros([jMax, log2kMax + 1], dtype='object')
    PhiFunErrorArray = _np.zeros([jMax, log2kMax + 1], dtype='object')

    for j in xrange(jMax):
        #    simDS = _dsc.generate_fake_data(gateset3,alphaCosStrList+alphaSinStrList+epsilonCosStrList+epsilonSinStrList+thetaCosStrList+epsilonSinStrList,
        simDS = _dsc.generate_fake_data(simGateset,
                                        alphaCosStrList + alphaSinStrList +
                                        epsilonCosStrList + epsilonSinStrList +
                                        thetaCosStrList + thetaSinStrList,
                                        N,
                                        sampleError='binomial',
                                        seed=j)
        alphaErrorList = []
        epsilonErrorList = []
        thetaErrorList = []
        PhiFunErrorList = []
        alphaHatList = _tools.rpe.est_angle_list(simDS, alphaSinStrList,
                                                 alphaCosStrList, 'alpha')
        epsilonHatList = _tools.rpe.est_angle_list(simDS, epsilonSinStrList,
                                                   epsilonCosStrList,
                                                   'epsilon')
        thetaHatList, PhiFunList = _tools.rpe.est_theta_list(
            simDS,
            thetaSinStrList,
            thetaCosStrList,
            epsilonHatList,
            returnPhiFunList=True)
        for alphaTemp1 in alphaHatList:
            alphaErrorList.append(abs(alphaTrue - alphaTemp1))
        for epsilonTemp1 in epsilonHatList:
            epsilonErrorList.append(abs(epsilonTrue - epsilonTemp1))
    #        print abs(_np.pi/2-abs(alphaTemp1))
        for thetaTemp1 in thetaHatList:
            thetaErrorList.append(abs(thetaTrue - thetaTemp1))
        for PhiFunTemp1 in PhiFunList:
            PhiFunErrorList.append(PhiFunTemp1)

        alphaErrorArray[j, :] = _np.array(alphaErrorList)
        epsilonErrorArray[j, :] = _np.array(epsilonErrorList)
        thetaErrorArray[j, :] = _np.array(thetaErrorList)
        PhiFunErrorArray[j, :] = _np.array(PhiFunErrorList)

        alphaHatListArray[j, :] = _np.array(alphaHatList)
        epsilonHatListArray[j, :] = _np.array(epsilonHatList)
        thetaHatListArray[j, :] = _np.array(thetaHatList)

    #print "True alpha:",alphaTrue
    #print "True alpha:",alphaTrue
    #print "True alpha:",alphaTrue
    #print "True alpha:",alphaTrue
    #print "% true alpha deviation from target:", percentAlphaError

    if plot:
        import matplotlib as _mpl
        _mpl.pyplot.loglog(kList,
                           _np.median(alphaErrorArray, axis=0),
                           label='N=' + str(N))

        _mpl.pyplot.loglog(kList, _np.array(kList)**-1., '-o', label='1/k')
        _mpl.pyplot.xlabel('k')
        _mpl.pyplot.ylabel(r'$\alpha_z - \widehat{\alpha_z}$')
        _mpl.pyplot.title('RPE error in Z angle\n% error in Z angle ' +
                          str(percentAlphaError) + '%, % error in X angle ' +
                          str(percentEpsilonError) + '%\n% error in SPAM, ' +
                          str(100 * SPAMerror) + '%, X-Z axis error ' +
                          str(Yrot) + '\nMedian of ' + str(jMax) + ' Trials')
        _mpl.pyplot.legend()

        _mpl.pyplot.show()

        _mpl.pyplot.loglog(kList,
                           _np.median(epsilonErrorArray, axis=0),
                           label='N=' + str(N))

        _mpl.pyplot.loglog(kList, _np.array(kList)**-1., '-o', label='1/k')
        _mpl.pyplot.xlabel('k')
        _mpl.pyplot.ylabel(r'$\epsilon_x - \widehat{\epsilon_x}$')
        _mpl.pyplot.title('RPE error in X angle\n% error in Z angle ' +
                          str(percentAlphaError) + '%, % error in X angle ' +
                          str(percentEpsilonError) + '%\n% error in SPAM, ' +
                          str(100 * SPAMerror) + '%, X-Z axis error ' +
                          str(Yrot) + '\nMedian of ' + str(jMax) + ' Trials')
        _mpl.pyplot.legend()

        _mpl.pyplot.show()

        _mpl.pyplot.loglog(kList,
                           _np.median(thetaErrorArray, axis=0),
                           label='N=' + str(N))

        _mpl.pyplot.loglog(kList, _np.array(kList)**-1., '-o', label='1/k')
        _mpl.pyplot.xlabel('k')
        _mpl.pyplot.ylabel(r'$\theta_{xz} - \widehat{\theta_{xz}}$')
        _mpl.pyplot.title('RPE error in X axis angle\n% error in Z angle ' +
                          str(percentAlphaError) + '%, % error in X angle ' +
                          str(percentEpsilonError) + '%\n% error in SPAM, ' +
                          str(100 * SPAMerror) + '%, X-Z axis error ' +
                          str(Yrot) + '\nMedian of ' + str(jMax) + ' Trials')
        _mpl.pyplot.legend()

        _mpl.pyplot.show()

        _mpl.pyplot.loglog(kList,
                           _np.median(PhiFunErrorArray, axis=0),
                           label='N=' + str(N))

        #        _mpl.pyplot.loglog(kList,_np.array(kList)**-1.,'-o',label='1/k')
        _mpl.pyplot.xlabel('k')
        _mpl.pyplot.ylabel(r'$\Phi func.$')
        _mpl.pyplot.title('RPE error in Phi func.\n% error in Z angle ' +
                          str(percentAlphaError) + '%, % error in X angle ' +
                          str(percentEpsilonError) + '%\n% error in SPAM, ' +
                          str(100 * SPAMerror) + '%, X-Z axis error ' +
                          str(Yrot) + '\nMedian of ' + str(jMax) + ' Trials')
        _mpl.pyplot.legend()

    outputDict = {}
    #    outputDict['alphaArray'] = alphaHatListArray
    #    outputDict['alphaErrorArray'] = alphaErrorArray
    #    outputDict['epsilonArray'] = epsilonHatListArray
    #    outputDict['epsilonErrorArray'] = epsilonErrorArray
    #    outputDict['thetaArray'] = thetaHatListArray
    #    outputDict['thetaErrorArray'] = thetaErrorArray
    #    outputDict['PhiFunErrorArray'] = PhiFunErrorArray
    #    outputDict['alpha'] = alphaTrue
    #    outputDict['epsilonTrue'] = epsilonTrue
    #    outputDict['thetaTrue'] = thetaTrue
    #    outputDict['Yrot'] = Yrot
    #    outputDict['SPAMdepol'] = SPAMdepol#Input value to depolarize SPAM by
    #    outputDict['SPAMerror'] = SPAMerror#<<E|rho>>
    #    outputDict['gs'] = simGateset
    #    outputDict['N'] = N

    return outputDict
示例#3
0
"""

import gatestringconstruction as _strc
import gatesetconstruction as _setc

description = "X(pi/2) and Z(pi/2) gates"

gates = ['Gx', 'Gz']
prepFiducials = _strc.gatestring_list([(), ('Gx', ), ('Gx', 'Gz'),
                                       ('Gx', 'Gx'), ('Gx', 'Gx', 'Gx'),
                                       ('Gx', 'Gz', 'Gx', 'Gx')])  # for 1Q MUB

measFiducials = _strc.gatestring_list([(), ('Gx', ), ('Gz', 'Gx'),
                                       ('Gx', 'Gx'), ('Gx', 'Gx', 'Gx'),
                                       ('Gx', 'Gx', 'Gz', 'Gx')])

germs = _strc.gatestring_list([('Gx', ), ('Gz', ), ('Gz', 'Gx', 'Gx'),
                               ('Gz', 'Gz', 'Gx')])

#Construct a target gateset:  X(pi/2), Z(pi/2)
gs_target = _setc.build_gateset([2], [('Q0', )], ['Gx', 'Gz'],
                                ["X(pi/2,Q0)", "Z(pi/2,Q0)"],
                                prepLabels=["rho0"],
                                prepExpressions=["0"],
                                effectLabels=["E0"],
                                effectExpressions=["1"],
                                spamdefs={
                                    'plus': ('rho0', 'E0'),
                                    'minus': ('rho0', 'remainder')
                                })
示例#4
0
def make_parameterized_rpe_gate_set(alphaTrue,
                                    epsilonTrue,
                                    Yrot,
                                    SPAMdepol,
                                    gateDepol=None,
                                    withId=True):
    """
    Make a gateset for simulating RPE, paramaterized by rotation angles.  Note
    that the output gateset also has thetaTrue, alphaTrue, and epsilonTrue 
    added attributes.

    Parameters
    ----------
    alphaTrue : float
       Angle of Z rotation (canonical RPE requires alphaTrue to be close to 
       pi/2).

    epsilonTrue : float
       Angle of X rotation (canonical RPE requires epsilonTrue to be close to
       pi/4).

    Yrot : float
       Angle of rotation about Y axis that, by similarity transformation,
       rotates X rotation.

    SPAMdepol : float
       Amount to depolarize SPAM by.

    gateDepol : float, optional
       Amount to depolarize gates by (defaults to None).

    withId : bool, optional
       Do we include (perfect) identity or no identity? (Defaults to False;
       should be False for RPE, True for GST)

    Returns
    -------
    GateSet
        The desired gateset for RPE; gateset also has attributes thetaTrue,
        alphaTrue, and epsilonTrue, automatically extracted.
    """

    if withId:
        outputGateset = _setc.build_gateset(
            [2], [('Q0', )], ['Gi', 'Gx', 'Gz'],
            ["I(Q0)",
             "X(%s,Q0)" % epsilonTrue,
             "Z(%s,Q0)" % alphaTrue],
            prepLabels=["rho0"],
            prepExpressions=["0"],
            effectLabels=["E0"],
            effectExpressions=["1"],
            spamdefs={
                'plus': ('rho0', 'E0'),
                'minus': ('rho0', 'remainder')
            })
    else:
        outputGateset = _setc.build_gateset(
            [2], [('Q0', )], ['Gx', 'Gz'],
            ["X(%s,Q0)" % epsilonTrue,
             "Z(%s,Q0)" % alphaTrue],
            prepLabels=["rho0"],
            prepExpressions=["0"],
            effectLabels=["E0"],
            effectExpressions=["1"],
            spamdefs={
                'plus': ('rho0', 'E0'),
                'minus': ('rho0', 'remainder')
            })

    if Yrot != 0:
        gatesetAux1 = _setc.build_gateset(
            [2], [('Q0', )], ['Gi', 'Gy', 'Gz'],
            ["I(Q0)", "Y(%s,Q0)" % Yrot, "Z(pi/2,Q0)"],
            prepLabels=["rho0"],
            prepExpressions=["0"],
            effectLabels=["E0"],
            effectExpressions=["1"],
            spamdefs={
                'plus': ('rho0', 'E0'),
                'minus': ('rho0', 'remainder')
            })

        outputGateset.gates['Gx'] = _objs.FullyParameterizedGate(
            _np.dot(
                _np.dot(_np.linalg.inv(gatesetAux1.gates['Gy']),
                        outputGateset.gates['Gx']), gatesetAux1.gates['Gy']))

    outputGateset = outputGateset.depolarize(gate_noise=gateDepol,
                                             spam_noise=SPAMdepol)

    thetaTrue = _tools.rpe.extract_theta(outputGateset)
    outputGateset.thetaTrue = thetaTrue

    outputGateset.alphaTrue = _tools.rpe.extract_alpha(outputGateset)
    outputGateset.alphaTrue = alphaTrue

    outputGateset.epsilonTrue = _tools.rpe.extract_epsilon(outputGateset)
    outputGateset.epsilonTrue = epsilonTrue

    return outputGateset
示例#5
0
     ('Gxi', 'Giy', 'Gix', 'Gix', 'Gxi', 'Giy', 'Gxi', 'Gcnot'),
     ('Giy', 'Gix', 'Gcnot', 'Gxi', 'Gcnot', 'Gxi', 'Gcnot', 'Gyi'),
     ('Gix', 'Giy', 'Gix', 'Gxi', 'Gix', 'Giy', 'Gxi', 'Gxi'),
     ('Gix', 'Gix', 'Gyi', 'Gxi', 'Giy', 'Gix', 'Gcnot', 'Gyi'),
     ('Gxi', 'Gyi', 'Gxi', 'Giy', 'Gxi', 'Giy', 'Gix', 'Giy'),
     ('Giy', 'Giy', 'Gyi', 'Gix', 'Gcnot', 'Gxi', 'Gyi', 'Gyi'),
     ('Gix', 'Gxi', 'Gxi', 'Giy', 'Gxi', 'Gyi', 'Gix', 'Gcnot'),
     ('Gyi', 'Gyi', 'Gyi', 'Gyi', 'Gix', 'Giy', 'Gix', 'Gyi'),
     ('Gxi', 'Gix', 'Gcnot', 'Gyi', 'Gix', 'Gcnot', 'Gix', 'Giy'),
     ('Giy', 'Gcnot', 'Gxi', 'Gyi', 'Gyi', 'Gcnot', 'Gix', 'Gcnot')] )

#Construct the target gateset
gs_target = _setc.build_gateset( 
    [4], [('Q0','Q1')],['Gix','Giy','Gxi','Gyi','Gcnot'], 
    [ "I(Q0):X(pi/2,Q1)", "I(Q0):Y(pi/2,Q1)", "X(pi/2,Q0):I(Q1)", "Y(pi/2,Q0):I(Q1)", "CX(pi,Q0,Q1)" ],
    prepLabels=['rho0'], prepExpressions=["0"],
    effectLabels=['E0','E1','E2'], effectExpressions=["0","1","2"], 
    spamdefs={'upup': ('rho0','E0'), 'updn': ('rho0','E1'),
              'dnup': ('rho0','E2'), 'dndn': ('rho0','remainder') }, basis="pp")


specs16x10 = _spamc.build_spam_specs(
    prepStrs=prepStrs,
    effectStrs=effectStrs,
    prep_labels=gs_target.get_prep_labels(),
    effect_labels=gs_target.get_effect_labels() )

specs16 = _spamc.build_spam_specs(
    fiducials16,
    prep_labels=gs_target.get_prep_labels(),
    effect_labels=gs_target.get_effect_labels() )