예제 #1
0
    def test_timed_block(self):
        with timed_block('40th fibonacci'):
            print(fib(40))

        timeDict = defaultdict(list)
        with timed_block('100th fibonacci', timeDict): # Duration saved to dict under label "100th fibonacci"
            print(fib(100))

        #test "preMessage" argument
        with timed_block('40th fibonacci', preMessage="Hello"):
            print(fib(40))
예제 #2
0
파일: basic.py 프로젝트: stjordanis/pyGSTi
def main():
    gs_target  = std2Q_XYICNOT.gs_target
    gs = gs_target.depolarize(gate_noise=0.1, spam_noise=0.001).rotate(0.1)
    gs = gs.kick(0.1, seed=1234)

    gs_target.set_all_parameterizations("TP")
    gs = contract(gs, "TP")
    gs.set_all_parameterizations("TP")

    #del gs.spamdefs['11']
    #del gs_target.spamdefs['11']
    #del gs.preps['rho0']
    #del gs_target.preps['rho0']
    #envSettings = dict(MKL_NUM_THREADS=1, NUMEXPR_NUM_THREADS=1, OMP_NUM_THREADS=1)

    print(gs.get_prep_labels())
    print(gs.get_effect_labels())
    print(gs.num_elements(include_povm_identity=True))
    print(gs.spamdefs)

    with timed_block('Basic gauge opt:'):
        gs_gaugeopt = gaugeopt_to_target(
            gs, gs_target,
            #method="L-BFGS-B",
            method="auto",
            itemWeights={'spam' : 0.0001, 'gates':1.0},
            spamMetric='frobenius',
            gatesMetric='frobenius',
            cptp_penalty_factor=1.0,
            spam_penalty_factor=1.0,
            comm=comm, verbosity=3, checkJac=True)

        if comm is None or comm.Get_rank() == 0:
            print("Final Diff = ", gs_gaugeopt.frobeniusdist(gs_target, None, 1.0, 0.0001))
            print(gs_gaugeopt.strdiff(gs_target))
예제 #3
0
def main():
    with open('data/example_report_results.pkl', 'rb') as infile:
        results = pickle.load(infile)
    with timed_block('example report creation'):
        pygsti.report.create_general_report(results,
                                            "report/exampleGenReport.html",
                                            verbosity=0,
                                            auto_open=False)
예제 #4
0
def main():
    gs, gs_target = load()
    #envSettings = dict(MKL_NUM_THREADS=1, NUMEXPR_NUM_THREADS=1, OMP_NUM_THREADS=1)

    with timed_block('TP penalty gauge opt'):
        gs_gaugeopt = pygsti.gaugeopt_to_target(gs, gs_target,
                                                item_weights={'spam' : 0.0001, 'gates':1.0},
                                                TPpenalty=1.0)
예제 #5
0
def main():
    digest = pygsti.tools.smartcache.digest
    native = pygsti.tools.smartcache.native_hash

    iterations = 100

    s = 'adfasdkfj;asldfa;ldfja;sdfja;sdfjas;dlkfja;sdfafad1*(@#&$)(@#*&$)(#&@'
    l = [(s, s) for i in range(50)]
    t = tuple(l)
    d = dict(l)
    keys = [s, l, t, d]
    for key in keys:
        with timed_block('digest_' + str(type(key))):
            for i in range(iterations):
                digest(key)
        with timed_block('native_' + str(type(key))):
            for i in range(iterations):
                native(key)
예제 #6
0
파일: cp.py 프로젝트: stjordanis/pyGSTi
def main():
    gs, gs_target = load()
    with timed_block('Gauge opt with CP Penalty:'):
        gs_gaugeopt = pygsti.gaugeopt_to_target(gs,
                                                gs_target,
                                                itemWeights={
                                                    'spam': 0.0001,
                                                    'gates': 1.0
                                                },
                                                CPpenalty=1.0,
                                                validSpamPenalty=1.0)
예제 #7
0
def main():
    with open('data/full_report_results.pkl', 'rb') as infile:
        results_tp, results_full = pickle.load(infile)
    with timed_block('TP/Full multi report'):
        ws = pygsti.report.create_general_report(
            {
                'TP': results_tp,
                "Full": results_full
            },
            "tutorial_files/exampleMultiGenReport.html",
            verbosity=3,
            auto_open=False)
예제 #8
0
def main():
    with open('data/full_report_results.pkl', 'rb') as infile:
        results_tp, results_full = pickle.load(infile)
    ws = pygsti.report.Workspace('data/wscache.pkl')
    with timed_block('reused ws'):
        pygsti.report.create_general_report(
            {
                'TP': results_tp,
                "Full": results_full
            },
            "tutorial_files/exampleMultiGenReport.html",
            verbosity=3,
            auto_open=False,
            ws=ws)
예제 #9
0
def main():
    gs_target = pygsti.construction.build_gateset(
            [8], [('Q0','Q1','Q2')],['Gx1','Gy1','Gx2','Gy2','Gx3','Gy3','Gcnot12','Gcnot23'],
            [ "X(pi/2,Q0):I(Q1):I(Q2)", "Y(pi/2,Q0):I(Q1):I(Q2)", "I(Q0):X(pi/2,Q1):I(Q2)", "I(Q0):Y(pi/2,Q1):I(Q2)",
                  "I(Q0):I(Q1):X(pi/2,Q2)", "I(Q0):I(Q1):Y(pi/2,Q2)", "CX(pi,Q0,Q1):I(Q2)", "I(Q0):CX(pi,Q1,Q2)"],
            prep_labels=['rho0'], prep_expressions=["0"],
            effect_labels=['E0','E1','E2','E3','E4','E5','E6'], effect_expressions=["0","1","2","3","4","5","6"],
            spamdefs={'upupup': ('rho0','E0'), 'upupdn': ('rho0','E1'), 'updnup': ('rho0','E2'), 'updndn': ('rho0','E3'),
                'dnupup': ('rho0','E4'), 'dnupdn': ('rho0','E5'), 'dndnup': ('rho0','E6'), 'dndndn': ('rho0','remainder')},
            basis="pp")
    gs = load_3q()

    with timed_block('Basic gauge opt (3Q)'):
        gs_gaugeopt = gaugeopt_to_target(gs, gs_target, 
                item_weights={'spam' : 0.0001, 'gates':1.0},
                spam_metric='frobenius',
                gates_metric='frobenius')
예제 #10
0
def main():
    gs_target = std1Q_XYI.gs_target
    gs_datagen = gs_target.depolarize(gate_noise=0.1,
                                      spam_noise=0.001).rotate(0.1)

    #DEBUG
    #del gs_target.spamdefs['1']
    #del gs_datagen.spamdefs['1']
    print(gs_datagen.get_prep_labels())
    print(gs_datagen.get_effect_labels())
    print(gs_datagen.num_elements(include_povm_identity=True))
    print(gs_datagen.spamdefs)

    with timed_block('Basic gauge opt:'):
        gs_gaugeopt = gaugeopt_to_target(
            gs_datagen,
            gs_target,
            tol=1e-7,
            method="auto",
            #method="L-BFGS-B",
            item_weights={
                'spam': 1.0,
                'gates': 1.0
            },
            spam_metric='frobenius',
            gates_metric='frobenius',
            check_jac=True,
            cptp_penalty_factor=1.0,
            spam_penalty_factor=1.0,
            comm=comm,
            verbosity=3)

        if comm is None or comm.Get_rank() == 0:
            print("Final Diff = ",
                  gs_gaugeopt.frobeniusdist(gs_target, None, 1.0, 1.0))
            print(gs_gaugeopt.strdiff(gs_target))
예제 #11
0
def main():
    gates = ['Gi', 'Gx', 'Gy']
    fiducials = pc.gatestring_list([(), ('Gx', ), ('Gy', ), ('Gx', 'Gx'),
                                    ('Gx', 'Gx', 'Gx'), ('Gy', 'Gy', 'Gy')
                                    ])  # fiducials for 1Q MUB
    germs = pc.gatestring_list([('Gx', ), ('Gy', ), ('Gi', ), (
        'Gx',
        'Gy',
    ), (
        'Gx',
        'Gy',
        'Gi',
    ), (
        'Gx',
        'Gi',
        'Gy',
    ), (
        'Gx',
        'Gi',
        'Gi',
    ), (
        'Gy',
        'Gi',
        'Gi',
    ), (
        'Gx',
        'Gx',
        'Gi',
        'Gy',
    ), (
        'Gx',
        'Gy',
        'Gy',
        'Gi',
    ), (
        'Gx',
        'Gx',
        'Gy',
        'Gx',
        'Gy',
        'Gy',
    )])
    maxLengths = [1, 2, 4, 8, 16, 32, 64, 128, 256]
    lsgst_lists = pc.create_lsgst_circuits(gates, fiducials, fiducials, germs,
                                           maxLengths)
    lsgst_tuple = tuple(lsgst_lists)
    iterations = 1000
    timeDict = dict()
    with timed_block('hash_gatestring_list', timeDict):
        for i in range(iterations):
            hash(lsgst_tuple)

    exampleUUID = uuid.uuid4()
    alt_hash = pygsti.tools.smartcache.digest
    with timed_block('digest_uuid', timeDict):
        for i in range(iterations):
            alt_hash(exampleUUID)

    print('Hashing gslist of length {} takes {} seconds on average'.format(
        len(lsgst_tuple), timeDict['hash_gatestring_list'] / iterations))
    print('UUID digest takes {} seconds on average'.format(
        timeDict['digest_uuid'] / iterations))