Example for qutrit GST

This notebook demonstrates how to construct the operation sequences and perform the analysis for qutrit GST when the model consists of symmetric $\pi/2$-rotations on each single qubit separately, X, Y and a 2-qubit Molmer-Sorenson gate which rotates around the XX axis by $\pi/2$.

In [1]:
import pygsti
import pygsti.construction as pc
from pygsti.construction import qutrit

from numpy import pi, array
import pickle

import numpy as np

First, we construct the target model. This functionality is built into pyGSTi, so we just need to specify the single-qubit and M-S angles.

In [2]:
target_model = qutrit.make_qutrit_model(errorScale=0, Xangle=pi/2, Yangle=pi/2, MSglobal=pi/2, MSlocal=0, basis="qt")
#print(target_model)

Now construct the operation sequences needed by GST. These fiducials and germs have been computed ahead of time and the results are used to construct the operation sequence lists below. Then we construct an empty dataset containing all of the necessary experimental sequences which can serve as a template for the actual experimental results.

In [3]:
fiducialPrep = pc.circuit_list(
    [(),('Gy',),('Gx',),('Gm',),
    ('Gx','Gx'), ('Gm','Gy'),('Gm','Gx'),
    ('Gy','Gy','Gy'),('Gx','Gx','Gx')])

fiducialMeasure = pc.circuit_list(
    [(),('Gy',),('Gx',),('Gm',),
    ('Gy','Gm'),('Gx','Gm')])

maxLengths = [1,2,4]

germs = pygsti.construction.circuit_list(
[('Gi',),
 ('Gy',),
 ('Gx',),
 ('Gm',),
 ('Gi', 'Gy'),
 ('Gi', 'Gx'),
 ('Gi', 'Gm'),
 ('Gy', 'Gx'),
 ('Gy', 'Gm'),
 ('Gx', 'Gm'),
 ('Gi', 'Gi', 'Gy'),
 ('Gi', 'Gi', 'Gx'),
 ('Gi', 'Gi', 'Gm'),
 ('Gi', 'Gy', 'Gy'),
 ('Gi', 'Gy', 'Gx'),
 ('Gi', 'Gy', 'Gm'),
 ('Gi', 'Gx', 'Gy'),
 ('Gi', 'Gx', 'Gx'),
 ('Gi', 'Gx', 'Gm'),
 ('Gi', 'Gm', 'Gy'),
 ('Gi', 'Gm', 'Gx'),
 ('Gi', 'Gm', 'Gm'),
 ('Gy', 'Gy', 'Gx'),
 ('Gy', 'Gy', 'Gm'),
 ('Gy', 'Gx', 'Gx'),
 ('Gy', 'Gx', 'Gm'),
 ('Gy', 'Gm', 'Gx'),
 ('Gy', 'Gm', 'Gm'),
 ('Gx', 'Gx', 'Gm'),
 ('Gx', 'Gm', 'Gm')])
In [4]:
#Note above construction is now a "standard" qutrit model
from pygsti.construction import stdQT_XYIMS
target_model = stdQT_XYIMS.target_model()
fiducialPrep = stdQT_XYIMS.prepStrs
fiducialMeasure = stdQT_XYIMS.effectStrs
germs = stdQT_XYIMS.germs_lite
maxLengths = [1,2,4]
In [5]:
print("%d prep fiducials" % len(fiducialPrep))
print("%d meas fiducials" % len(fiducialMeasure))
print("%d germs" % len(germs))
9 prep fiducials
7 meas fiducials
31 germs
In [6]:
#generate data template
expList = pygsti.construction.make_lsgst_experiment_list(target_model.operations.keys(), fiducialPrep, fiducialMeasure, germs,  maxLengths)
pygsti.io.write_empty_dataset("example_files/dataTemplate_qutrit_maxL=4.txt", expList, "## Columns = 0bright count, 1bright count, 2bright count")

At this point STOP and create/fill a dataset file using the template written in the above cell. Then proceed with the lines below to run GST on the data and create (hopefully useful) reports telling you about your gates.

In [7]:
mdl_datagen = target_model.depolarize(op_noise=0.05)
DS = pygsti.construction.generate_fake_data(mdl_datagen, expList, 500, sampleError='multinomial', seed=2018)
In [8]:
#DS = pygsti.io.load_dataset('PATH_TO_YOUR_DATASET',cache=True) # (cache=True speeds up future loads)
In [9]:
#Run qutrit GST... which could take a while on a single CPU.  Please adjust memLimit to machine specs 
# (now 3GB; usually set to slightly less than the total machine memory)
result = pygsti.do_stdpractice_gst(DS,target_model,fiducialPrep,fiducialMeasure,germs,maxLengths,
                                     verbosity=2, comm=None, memLimit=3*(1024)**3, modes="TP,CPTP")
-- Std Practice:  Iter 1 of 2  (TP) --: 
  --- Circuit Creation ---
  --- LGST ---
  --- Iterative MLGST: [##################################################] 100.0%  2017 operation sequences ---
  Iterative MLGST Total Time: 33.1s
  -- Performing 'single' gauge optimization on TP estimate --
-- Std Practice:  Iter 2 of 2  (CPTP) --: 
  --- Circuit Creation ---
  --- Iterative MLGST: [##################################################] 100.0%  2017 operation sequences ---
  Iterative MLGST Total Time: 586.1s
  --- Re-optimizing logl after robust data scaling ---
  -- Performing 'single' gauge optimization on CPTP estimate --
  -- Conveying 'single' gauge optimization to CPTP.Robust+ estimate --
In [10]:
#Create a report
ws = pygsti.report.create_standard_report(result, "example_files/sampleQutritReport",
                                         "Example Qutrit Report", verbosity=3, auto_open=True)
*** Creating workspace ***
*** Generating switchboard ***
/Users/enielse/research/pyGSTi/packages/pygsti/report/factory.py:785: UserWarning:

Idle tomography failed:
Label{layers}

/Users/enielse/research/pyGSTi/packages/pygsti/objects/operation.py:967: ComplexWarning:

Casting complex values to real discards the imaginary part

*** Generating tables ***
  targetSpamBriefTable                          took 0.948642 seconds
  targetGatesBoxTable                           took 0.408834 seconds
  datasetOverviewTable                          took 0.12006 seconds
  bestGatesetSpamParametersTable                took 0.001933 seconds
  bestGatesetSpamBriefTable                     took 1.165074 seconds
  bestGatesetSpamVsTargetTable                  took 0.67162 seconds
  bestGatesetGaugeOptParamsTable                took 0.001592 seconds
  bestGatesetGatesBoxTable                      took 0.960349 seconds
  bestGatesetChoiEvalTable                      took 1.359139 seconds
  bestGatesetDecompTable                        took 32.569516 seconds
  bestGatesetEvalTable                          took 0.028175 seconds
  bestGermsEvalTable                            took 0.680471 seconds
  bestGatesetVsTargetTable                      took 0.011108 seconds
  bestGatesVsTargetTable_gv                     took 2.653336 seconds
  bestGatesVsTargetTable_gvgerms                took 3.52283 seconds
  bestGatesVsTargetTable_gi                     took 0.083563 seconds
  bestGatesVsTargetTable_gigerms                took 1.005465 seconds
  bestGatesVsTargetTable_sum                    took 2.513654 seconds
  bestGatesetErrGenBoxTable                     took 2.718083 seconds
  metadataTable                                 took 0.002088 seconds
  stdoutBlock                                   took 0.000354 seconds
  profilerTable                                 took 0.002132 seconds
  softwareEnvTable                              took 0.059882 seconds
  exampleTable                                  took 0.073524 seconds
  singleMetricTable_gv                          took 1.809641 seconds
  singleMetricTable_gi                          took 0.061872 seconds
  fiducialListTable                             took 0.000658 seconds
  prepStrListTable                              took 0.00024 seconds
  effectStrListTable                            took 0.000194 seconds
  colorBoxPlotKeyPlot                           took 0.251883 seconds
  germList2ColTable                             took 0.000432 seconds
  progressTable                                 took 3.431832 seconds
*** Generating plots ***
  gramBarPlot                                   took 0.109183 seconds
  progressBarPlot                               took 0.375818 seconds
  progressBarPlot_sum                           took 0.000835 seconds
  finalFitComparePlot                           took 0.144866 seconds
  bestEstimateColorBoxPlot                      took 12.789732 seconds
  bestEstimateTVDColorBoxPlot                   took 11.530546 seconds
  bestEstimateColorScatterPlot                  took 13.806537 seconds
  bestEstimateColorHistogram                    took 11.955992 seconds
  progressTable_scl                             took 1.511275 seconds
  progressBarPlot_scl                           took 0.232363 seconds
  bestEstimateColorBoxPlot_scl                  took 6.033762 seconds
  bestEstimateColorScatterPlot_scl              took 6.666415 seconds
  bestEstimateColorHistogram_scl                took 5.965612 seconds
  dataScalingColorBoxPlot                       took 0.137673 seconds
*** Merging into template file ***
  Rendering topSwitchboard                      took 0.000134 seconds
  Rendering maxLSwitchboard1                    took 7.6e-05 seconds
  Rendering targetSpamBriefTable                took 0.098134 seconds
  Rendering targetGatesBoxTable                 took 0.085305 seconds
  Rendering datasetOverviewTable                took 0.001947 seconds
  Rendering bestGatesetSpamParametersTable      took 0.00314 seconds
  Rendering bestGatesetSpamBriefTable           took 0.379709 seconds
  Rendering bestGatesetSpamVsTargetTable        took 0.002969 seconds
  Rendering bestGatesetGaugeOptParamsTable      took 0.002197 seconds
  Rendering bestGatesetGatesBoxTable            took 0.38997 seconds
  Rendering bestGatesetChoiEvalTable            took 0.318637 seconds
  Rendering bestGatesetDecompTable              took 0.213322 seconds
  Rendering bestGatesetEvalTable                took 0.042549 seconds
  Rendering bestGermsEvalTable                  took 0.320558 seconds
  Rendering bestGatesetVsTargetTable            took 0.00131 seconds
  Rendering bestGatesVsTargetTable_gv           took 0.005009 seconds
  Rendering bestGatesVsTargetTable_gvgerms      took 0.014515 seconds
  Rendering bestGatesVsTargetTable_gi           took 0.005062 seconds
  Rendering bestGatesVsTargetTable_gigerms      took 0.010149 seconds
  Rendering bestGatesVsTargetTable_sum          took 0.004553 seconds
  Rendering bestGatesetErrGenBoxTable           took 1.01326 seconds
  Rendering metadataTable                       took 0.004815 seconds
  Rendering stdoutBlock                         took 0.001379 seconds
  Rendering profilerTable                       took 0.002674 seconds
  Rendering softwareEnvTable                    took 0.002272 seconds
  Rendering exampleTable                        took 0.021317 seconds
  Rendering metricSwitchboard_gv                took 7e-05 seconds
  Rendering metricSwitchboard_gi                took 4.4e-05 seconds
  Rendering singleMetricTable_gv                took 0.008173 seconds
  Rendering singleMetricTable_gi                took 0.007073 seconds
  Rendering fiducialListTable                   took 0.003428 seconds
  Rendering prepStrListTable                    took 0.002495 seconds
  Rendering effectStrListTable                  took 0.002131 seconds
  Rendering colorBoxPlotKeyPlot                 took 0.024398 seconds
  Rendering germList2ColTable                   took 0.010392 seconds
  Rendering progressTable                       took 0.005172 seconds
  Rendering gramBarPlot                         took 0.020919 seconds
  Rendering progressBarPlot                     took 0.037914 seconds
  Rendering progressBarPlot_sum                 took 0.038827 seconds
  Rendering finalFitComparePlot                 took 0.016507 seconds
  Rendering bestEstimateColorBoxPlot            took 0.217022 seconds
  Rendering bestEstimateTVDColorBoxPlot         took 0.210556 seconds
  Rendering bestEstimateColorScatterPlot        took 0.358414 seconds
  Rendering bestEstimateColorHistogram          took 0.203399 seconds
  Rendering progressTable_scl                   took 0.002996 seconds
  Rendering progressBarPlot_scl                 took 0.020068 seconds
  Rendering bestEstimateColorBoxPlot_scl        took 0.113779 seconds
  Rendering bestEstimateColorScatterPlot_scl    took 0.18969 seconds
  Rendering bestEstimateColorHistogram_scl      took 0.102361 seconds
  Rendering dataScalingColorBoxPlot             took 0.056695 seconds
Output written to example_files/sampleQutritReport directory
Opening example_files/sampleQutritReport/main.html...
*** Report Generation Complete!  Total time 134.806s ***
In [11]:
print(target_model.basis)
Qutrit Basis : (no labels computed yet)
In [ ]: