pyGSTi 0.9.12__cp39-cp39-win32.whl → 0.9.13__cp39-cp39-win32.whl
Sign up to get free protection for your applications and to get access to all the features.
- pyGSTi-0.9.13.dist-info/METADATA +197 -0
- {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/RECORD +211 -220
- {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/WHEEL +1 -1
- pygsti/_version.py +2 -2
- pygsti/algorithms/contract.py +1 -1
- pygsti/algorithms/core.py +62 -35
- pygsti/algorithms/fiducialpairreduction.py +95 -110
- pygsti/algorithms/fiducialselection.py +17 -8
- pygsti/algorithms/gaugeopt.py +2 -2
- pygsti/algorithms/germselection.py +87 -77
- pygsti/algorithms/mirroring.py +0 -388
- pygsti/algorithms/randomcircuit.py +165 -1333
- pygsti/algorithms/rbfit.py +0 -234
- pygsti/baseobjs/basis.py +94 -396
- pygsti/baseobjs/errorgenbasis.py +0 -132
- pygsti/baseobjs/errorgenspace.py +0 -10
- pygsti/baseobjs/label.py +52 -168
- pygsti/baseobjs/opcalc/fastopcalc.cp39-win32.pyd +0 -0
- pygsti/baseobjs/opcalc/fastopcalc.pyx +2 -2
- pygsti/baseobjs/polynomial.py +13 -595
- pygsti/baseobjs/protectedarray.py +72 -132
- pygsti/baseobjs/statespace.py +1 -0
- pygsti/circuits/__init__.py +1 -1
- pygsti/circuits/circuit.py +753 -504
- pygsti/circuits/circuitconstruction.py +0 -4
- pygsti/circuits/circuitlist.py +47 -5
- pygsti/circuits/circuitparser/__init__.py +8 -8
- pygsti/circuits/circuitparser/fastcircuitparser.cp39-win32.pyd +0 -0
- pygsti/circuits/circuitstructure.py +3 -3
- pygsti/circuits/cloudcircuitconstruction.py +27 -14
- pygsti/data/datacomparator.py +4 -9
- pygsti/data/dataset.py +51 -46
- pygsti/data/hypothesistest.py +0 -7
- pygsti/drivers/bootstrap.py +0 -49
- pygsti/drivers/longsequence.py +46 -10
- pygsti/evotypes/basereps_cython.cp39-win32.pyd +0 -0
- pygsti/evotypes/chp/opreps.py +0 -61
- pygsti/evotypes/chp/statereps.py +0 -32
- pygsti/evotypes/densitymx/effectcreps.cpp +9 -10
- pygsti/evotypes/densitymx/effectreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/densitymx/effectreps.pyx +1 -1
- pygsti/evotypes/densitymx/opreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/densitymx/opreps.pyx +2 -2
- pygsti/evotypes/densitymx/statereps.cp39-win32.pyd +0 -0
- pygsti/evotypes/densitymx/statereps.pyx +1 -1
- pygsti/evotypes/densitymx_slow/effectreps.py +7 -23
- pygsti/evotypes/densitymx_slow/opreps.py +16 -23
- pygsti/evotypes/densitymx_slow/statereps.py +10 -3
- pygsti/evotypes/evotype.py +39 -2
- pygsti/evotypes/stabilizer/effectreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/effectreps.pyx +0 -4
- pygsti/evotypes/stabilizer/opreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/opreps.pyx +0 -4
- pygsti/evotypes/stabilizer/statereps.cp39-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/statereps.pyx +1 -5
- pygsti/evotypes/stabilizer/termreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/stabilizer/termreps.pyx +0 -7
- pygsti/evotypes/stabilizer_slow/effectreps.py +0 -22
- pygsti/evotypes/stabilizer_slow/opreps.py +0 -4
- pygsti/evotypes/stabilizer_slow/statereps.py +0 -4
- pygsti/evotypes/statevec/effectreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/statevec/effectreps.pyx +1 -1
- pygsti/evotypes/statevec/opreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/statevec/opreps.pyx +2 -2
- pygsti/evotypes/statevec/statereps.cp39-win32.pyd +0 -0
- pygsti/evotypes/statevec/statereps.pyx +1 -1
- pygsti/evotypes/statevec/termreps.cp39-win32.pyd +0 -0
- pygsti/evotypes/statevec/termreps.pyx +0 -7
- pygsti/evotypes/statevec_slow/effectreps.py +0 -3
- pygsti/evotypes/statevec_slow/opreps.py +0 -5
- pygsti/extras/__init__.py +0 -1
- pygsti/extras/drift/signal.py +1 -1
- pygsti/extras/drift/stabilityanalyzer.py +3 -1
- pygsti/extras/interpygate/__init__.py +12 -0
- pygsti/extras/interpygate/core.py +0 -36
- pygsti/extras/interpygate/process_tomography.py +44 -10
- pygsti/extras/rpe/rpeconstruction.py +0 -2
- pygsti/forwardsims/__init__.py +1 -0
- pygsti/forwardsims/forwardsim.py +50 -93
- pygsti/forwardsims/mapforwardsim.py +78 -20
- pygsti/forwardsims/mapforwardsim_calc_densitymx.cp39-win32.pyd +0 -0
- pygsti/forwardsims/mapforwardsim_calc_densitymx.pyx +65 -66
- pygsti/forwardsims/mapforwardsim_calc_generic.py +91 -13
- pygsti/forwardsims/matrixforwardsim.py +72 -17
- pygsti/forwardsims/termforwardsim.py +9 -111
- pygsti/forwardsims/termforwardsim_calc_stabilizer.cp39-win32.pyd +0 -0
- pygsti/forwardsims/termforwardsim_calc_statevec.cp39-win32.pyd +0 -0
- pygsti/forwardsims/termforwardsim_calc_statevec.pyx +0 -651
- pygsti/forwardsims/torchfwdsim.py +265 -0
- pygsti/forwardsims/weakforwardsim.py +2 -2
- pygsti/io/__init__.py +1 -2
- pygsti/io/mongodb.py +0 -2
- pygsti/io/stdinput.py +6 -22
- pygsti/layouts/copalayout.py +10 -12
- pygsti/layouts/distlayout.py +0 -40
- pygsti/layouts/maplayout.py +103 -25
- pygsti/layouts/matrixlayout.py +99 -60
- pygsti/layouts/prefixtable.py +1534 -52
- pygsti/layouts/termlayout.py +1 -1
- pygsti/modelmembers/instruments/instrument.py +3 -3
- pygsti/modelmembers/instruments/tpinstrument.py +2 -2
- pygsti/modelmembers/modelmember.py +0 -17
- pygsti/modelmembers/operations/__init__.py +3 -4
- pygsti/modelmembers/operations/affineshiftop.py +206 -0
- pygsti/modelmembers/operations/composederrorgen.py +1 -1
- pygsti/modelmembers/operations/composedop.py +1 -24
- pygsti/modelmembers/operations/denseop.py +5 -5
- pygsti/modelmembers/operations/eigpdenseop.py +2 -2
- pygsti/modelmembers/operations/embeddederrorgen.py +1 -1
- pygsti/modelmembers/operations/embeddedop.py +0 -1
- pygsti/modelmembers/operations/experrorgenop.py +5 -2
- pygsti/modelmembers/operations/fullarbitraryop.py +1 -0
- pygsti/modelmembers/operations/fullcptpop.py +2 -2
- pygsti/modelmembers/operations/fulltpop.py +28 -6
- pygsti/modelmembers/operations/fullunitaryop.py +5 -4
- pygsti/modelmembers/operations/lindbladcoefficients.py +93 -78
- pygsti/modelmembers/operations/lindbladerrorgen.py +268 -441
- pygsti/modelmembers/operations/linearop.py +7 -27
- pygsti/modelmembers/operations/opfactory.py +1 -1
- pygsti/modelmembers/operations/repeatedop.py +1 -24
- pygsti/modelmembers/operations/staticstdop.py +1 -1
- pygsti/modelmembers/povms/__init__.py +3 -3
- pygsti/modelmembers/povms/basepovm.py +7 -36
- pygsti/modelmembers/povms/complementeffect.py +4 -9
- pygsti/modelmembers/povms/composedeffect.py +0 -320
- pygsti/modelmembers/povms/computationaleffect.py +1 -1
- pygsti/modelmembers/povms/computationalpovm.py +3 -1
- pygsti/modelmembers/povms/effect.py +3 -5
- pygsti/modelmembers/povms/marginalizedpovm.py +3 -81
- pygsti/modelmembers/povms/tppovm.py +74 -2
- pygsti/modelmembers/states/__init__.py +2 -5
- pygsti/modelmembers/states/composedstate.py +0 -317
- pygsti/modelmembers/states/computationalstate.py +3 -3
- pygsti/modelmembers/states/cptpstate.py +4 -4
- pygsti/modelmembers/states/densestate.py +10 -8
- pygsti/modelmembers/states/fullpurestate.py +0 -24
- pygsti/modelmembers/states/purestate.py +1 -1
- pygsti/modelmembers/states/state.py +5 -6
- pygsti/modelmembers/states/tpstate.py +28 -10
- pygsti/modelmembers/term.py +3 -6
- pygsti/modelmembers/torchable.py +50 -0
- pygsti/modelpacks/_modelpack.py +1 -1
- pygsti/modelpacks/smq1Q_ZN.py +3 -1
- pygsti/modelpacks/smq2Q_XXYYII.py +2 -1
- pygsti/modelpacks/smq2Q_XY.py +3 -3
- pygsti/modelpacks/smq2Q_XYI.py +2 -2
- pygsti/modelpacks/smq2Q_XYICNOT.py +3 -3
- pygsti/modelpacks/smq2Q_XYICPHASE.py +3 -3
- pygsti/modelpacks/smq2Q_XYXX.py +1 -1
- pygsti/modelpacks/smq2Q_XYZICNOT.py +3 -3
- pygsti/modelpacks/smq2Q_XYZZ.py +1 -1
- pygsti/modelpacks/stdtarget.py +0 -121
- pygsti/models/cloudnoisemodel.py +1 -2
- pygsti/models/explicitcalc.py +3 -3
- pygsti/models/explicitmodel.py +3 -13
- pygsti/models/fogistore.py +5 -3
- pygsti/models/localnoisemodel.py +1 -2
- pygsti/models/memberdict.py +0 -12
- pygsti/models/model.py +801 -68
- pygsti/models/modelconstruction.py +4 -4
- pygsti/models/modelnoise.py +2 -2
- pygsti/models/modelparaminterposer.py +1 -1
- pygsti/models/oplessmodel.py +1 -1
- pygsti/models/qutrit.py +15 -14
- pygsti/objectivefns/objectivefns.py +75 -140
- pygsti/objectivefns/wildcardbudget.py +2 -7
- pygsti/optimize/__init__.py +1 -0
- pygsti/optimize/arraysinterface.py +28 -0
- pygsti/optimize/customcg.py +0 -12
- pygsti/optimize/customlm.py +129 -323
- pygsti/optimize/customsolve.py +2 -2
- pygsti/optimize/optimize.py +0 -84
- pygsti/optimize/simplerlm.py +841 -0
- pygsti/optimize/wildcardopt.py +19 -598
- pygsti/protocols/confidenceregionfactory.py +28 -14
- pygsti/protocols/estimate.py +31 -14
- pygsti/protocols/gst.py +238 -142
- pygsti/protocols/modeltest.py +19 -12
- pygsti/protocols/protocol.py +9 -37
- pygsti/protocols/rb.py +450 -79
- pygsti/protocols/treenode.py +8 -2
- pygsti/protocols/vb.py +108 -206
- pygsti/protocols/vbdataframe.py +1 -1
- pygsti/report/factory.py +0 -15
- pygsti/report/fogidiagram.py +1 -17
- pygsti/report/modelfunction.py +12 -3
- pygsti/report/mpl_colormaps.py +1 -1
- pygsti/report/plothelpers.py +11 -3
- pygsti/report/report.py +16 -0
- pygsti/report/reportables.py +41 -37
- pygsti/report/templates/offline/pygsti_dashboard.css +6 -0
- pygsti/report/templates/offline/pygsti_dashboard.js +12 -0
- pygsti/report/workspace.py +2 -14
- pygsti/report/workspaceplots.py +328 -505
- pygsti/tools/basistools.py +9 -36
- pygsti/tools/edesigntools.py +124 -96
- pygsti/tools/fastcalc.cp39-win32.pyd +0 -0
- pygsti/tools/fastcalc.pyx +35 -81
- pygsti/tools/internalgates.py +151 -15
- pygsti/tools/jamiolkowski.py +5 -5
- pygsti/tools/lindbladtools.py +19 -11
- pygsti/tools/listtools.py +0 -114
- pygsti/tools/matrixmod2.py +1 -1
- pygsti/tools/matrixtools.py +173 -339
- pygsti/tools/nameddict.py +1 -1
- pygsti/tools/optools.py +154 -88
- pygsti/tools/pdftools.py +0 -25
- pygsti/tools/rbtheory.py +3 -320
- pygsti/tools/slicetools.py +64 -12
- pyGSTi-0.9.12.dist-info/METADATA +0 -157
- pygsti/algorithms/directx.py +0 -711
- pygsti/evotypes/qibo/__init__.py +0 -33
- pygsti/evotypes/qibo/effectreps.py +0 -78
- pygsti/evotypes/qibo/opreps.py +0 -376
- pygsti/evotypes/qibo/povmreps.py +0 -98
- pygsti/evotypes/qibo/statereps.py +0 -174
- pygsti/extras/rb/__init__.py +0 -13
- pygsti/extras/rb/benchmarker.py +0 -957
- pygsti/extras/rb/dataset.py +0 -378
- pygsti/extras/rb/io.py +0 -814
- pygsti/extras/rb/simulate.py +0 -1020
- pygsti/io/legacyio.py +0 -385
- pygsti/modelmembers/povms/denseeffect.py +0 -142
- {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/LICENSE +0 -0
- {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/top_level.txt +0 -0
pygsti/_version.py
CHANGED
pygsti/algorithms/contract.py
CHANGED
@@ -358,7 +358,7 @@ def _contract_to_valid_spam(model, verbosity=0):
|
|
358
358
|
|
359
359
|
# ** assumption: only the first vector element of pauli vectors has nonzero trace
|
360
360
|
dummyVec = _np.zeros((model.dim, 1), 'd'); dummyVec[0, 0] = 1.0
|
361
|
-
firstElTrace = _np.real(
|
361
|
+
firstElTrace = _np.real(_np.trace(_tools.ppvec_to_stdmx(dummyVec))) # == sqrt(2)**nQubits
|
362
362
|
diff = 0
|
363
363
|
|
364
364
|
# rhoVec must be positive semidefinite and trace = 1
|
pygsti/algorithms/core.py
CHANGED
@@ -31,8 +31,9 @@ from pygsti.modelmembers import instruments as _instrument
|
|
31
31
|
from pygsti.modelmembers import states as _state
|
32
32
|
from pygsti.circuits.circuitlist import CircuitList as _CircuitList
|
33
33
|
from pygsti.baseobjs.resourceallocation import ResourceAllocation as _ResourceAllocation
|
34
|
-
from pygsti.optimize.
|
35
|
-
from pygsti
|
34
|
+
from pygsti.optimize.simplerlm import Optimizer as _Optimizer, SimplerLMOptimizer as _SimplerLMOptimizer
|
35
|
+
from pygsti import forwardsims as _fwdsims
|
36
|
+
from pygsti import layouts as _layouts
|
36
37
|
|
37
38
|
_dummy_profiler = _DummyProfiler()
|
38
39
|
|
@@ -53,7 +54,7 @@ FLOATSIZE = 8 # TODO: better way?
|
|
53
54
|
|
54
55
|
|
55
56
|
def run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=None, op_label_aliases=None,
|
56
|
-
guess_model_for_gauge=None, svd_truncate_to=None, verbosity=0):
|
57
|
+
guess_model_for_gauge=None, svd_truncate_to=None, verbosity=0, check=True):
|
57
58
|
"""
|
58
59
|
Performs Linear-inversion Gate Set Tomography on the dataset.
|
59
60
|
|
@@ -102,6 +103,10 @@ def run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=
|
|
102
103
|
verbosity : int, optional
|
103
104
|
How much detail to send to stdout.
|
104
105
|
|
106
|
+
check : bool, optional
|
107
|
+
Specifies whether we perform computationally expensive assertion checks.
|
108
|
+
Computationally cheap assertions will always be checked.
|
109
|
+
|
105
110
|
Returns
|
106
111
|
-------
|
107
112
|
Model
|
@@ -193,8 +198,8 @@ def run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=
|
|
193
198
|
"or decrease svd_truncate_to" % (rankAB, ABMat_p.shape[0]))
|
194
199
|
|
195
200
|
invABMat_p = _np.dot(Pjt, _np.dot(_np.diag(1.0 / s), Pj)) # (trunc,trunc)
|
196
|
-
|
197
|
-
|
201
|
+
if check:
|
202
|
+
assert(_np.linalg.norm(_np.linalg.inv(ABMat_p) - invABMat_p) < 1e-8)
|
198
203
|
assert(len((_np.isnan(invABMat_p)).nonzero()[0]) == 0)
|
199
204
|
|
200
205
|
if svd_truncate_to is None or svd_truncate_to == target_model.dim: # use target sslbls and basis
|
@@ -231,10 +236,6 @@ def run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=
|
|
231
236
|
assert(len(X_ps) == 1); X_p = X_ps[0] # shape (nESpecs, nRhoSpecs)
|
232
237
|
lgstModel.operations[opLabel] = _op.FullArbitraryOp(_np.dot(invABMat_p, X_p)) # shape (trunc,trunc)
|
233
238
|
|
234
|
-
#print "DEBUG: X(%s) = \n" % opLabel,X
|
235
|
-
#print "DEBUG: Evals(X) = \n",_np.linalg.eigvals(X)
|
236
|
-
#print "DEBUG: %s = \n" % opLabel,lgstModel[ opLabel ]
|
237
|
-
|
238
239
|
#Form POVMs
|
239
240
|
for povmLabel in povmLabelsToEstimate:
|
240
241
|
povm_effects = []
|
@@ -247,7 +248,10 @@ def run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=
|
|
247
248
|
circuit = rhostr
|
248
249
|
dsRow_fractions = dataset[circuit].fractions
|
249
250
|
# outcome labels should just be effect labels (no instruments!)
|
250
|
-
|
251
|
+
# when using a sparse data set format it might not be the case
|
252
|
+
# that all effect labels are present (only ones with non-zero counts are)
|
253
|
+
# so return 0 for the fraction in that case.
|
254
|
+
EVec[0, i] = dsRow_fractions.get((effectLabel,), 0)
|
251
255
|
EVec_p = _np.dot(_np.dot(EVec, Vd), Pj) # truncate Evec => Evec', shape (1,trunc)
|
252
256
|
povm_effects.append((effectLabel, _np.transpose(EVec_p)))
|
253
257
|
lgstModel.povms[povmLabel] = _povm.UnconstrainedPOVM(povm_effects, evotype='default')
|
@@ -262,7 +266,10 @@ def run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=
|
|
262
266
|
# try without prepLabel since it will be the default
|
263
267
|
circuit = estr
|
264
268
|
dsRow_fractions = dataset[circuit].fractions
|
265
|
-
|
269
|
+
# when using a sparse data set format it might not be the case
|
270
|
+
# that all effect labels are present (only ones with non-zero counts are)
|
271
|
+
# so return 0 for the fraction in that case.
|
272
|
+
rhoVec[eoff:eoff + povmLen, 0] = [dsRow_fractions.get((ol,),0) for ol in target_model.povms[povmLbl]]
|
266
273
|
eoff += povmLen
|
267
274
|
rhoVec_p = _np.dot(Pjt, _np.dot(Ud, rhoVec)) # truncate rhoVec => rhoVec', shape (trunc, 1)
|
268
275
|
rhoVec_p = _np.dot(invABMat_p, rhoVec_p)
|
@@ -394,7 +401,7 @@ def _construct_ab(prep_fiducials, effect_fiducials, model, dataset, op_label_ali
|
|
394
401
|
for j, rhostr in enumerate(prep_fiducials):
|
395
402
|
opLabelString = rhostr + estr # LEXICOGRAPHICAL VS MATRIX ORDER
|
396
403
|
dsStr = opLabelString.replace_layers_with_aliases(op_label_aliases)
|
397
|
-
expd_circuit_outcomes =
|
404
|
+
expd_circuit_outcomes = model.expand_instruments_and_separate_povm(opLabelString)
|
398
405
|
assert(len(expd_circuit_outcomes) == 1), "No instruments are allowed in LGST fiducials!"
|
399
406
|
unique_key = next(iter(expd_circuit_outcomes.keys()))
|
400
407
|
outcomes = expd_circuit_outcomes[unique_key]
|
@@ -423,7 +430,7 @@ def _construct_x_matrix(prep_fiducials, effect_fiducials, model, op_label_tuple,
|
|
423
430
|
for j, rhostr in enumerate(prep_fiducials):
|
424
431
|
opLabelString = rhostr + _circuits.Circuit(op_label_tuple, line_labels=rhostr.line_labels) + estr
|
425
432
|
dsStr = opLabelString.replace_layers_with_aliases(op_label_aliases)
|
426
|
-
expd_circuit_outcomes =
|
433
|
+
expd_circuit_outcomes = model.expand_instruments_and_separate_povm(opLabelString)
|
427
434
|
dsRow_fractions = dataset[dsStr].fractions
|
428
435
|
assert(len(expd_circuit_outcomes) == nVariants)
|
429
436
|
|
@@ -444,6 +451,10 @@ def _construct_a(effect_fiducials, model):
|
|
444
451
|
dim = model.dim
|
445
452
|
A = _np.empty((n, dim))
|
446
453
|
# st = _np.empty(dim, 'd')
|
454
|
+
|
455
|
+
# Remove restrictions on state param types for computation
|
456
|
+
old_default_param = model.preps.default_param
|
457
|
+
model.preps.default_param = "full"
|
447
458
|
|
448
459
|
basis_st = _np.zeros((dim, 1), 'd'); eoff = 0
|
449
460
|
for k, (estr, povmLbl, povmLen) in enumerate(zip(effect_fiducials, povmLbls, povmLens)):
|
@@ -459,6 +470,9 @@ def _construct_a(effect_fiducials, model):
|
|
459
470
|
basis_st[i] = 0.0
|
460
471
|
|
461
472
|
eoff += povmLen
|
473
|
+
|
474
|
+
model.preps.default_param = old_default_param
|
475
|
+
|
462
476
|
return A
|
463
477
|
|
464
478
|
|
@@ -468,6 +482,10 @@ def _construct_b(prep_fiducials, model):
|
|
468
482
|
B = _np.empty((dim, n))
|
469
483
|
# st = _np.empty(dim, 'd')
|
470
484
|
|
485
|
+
# Remove restrictions on POVM param types for computation
|
486
|
+
old_default_param = model.povms.default_param
|
487
|
+
model.povms.default_param = "full"
|
488
|
+
|
471
489
|
#Create POVM of vector units
|
472
490
|
basis_Es = []
|
473
491
|
for i in range(dim): # propagate each basis initial state
|
@@ -484,6 +502,8 @@ def _construct_b(prep_fiducials, model):
|
|
484
502
|
B[:, k] = [probs[("E%d" % i,)] for i in range(dim)] # CHECK will this work?
|
485
503
|
|
486
504
|
del model.povms['M_LGST_tmp_povm']
|
505
|
+
model.povms.default_param = old_default_param
|
506
|
+
|
487
507
|
return B
|
488
508
|
|
489
509
|
|
@@ -598,7 +618,7 @@ def run_gst_fit_simple(dataset, start_model, circuits, optimizer, objective_func
|
|
598
618
|
model : Model
|
599
619
|
the best-fit model.
|
600
620
|
"""
|
601
|
-
optimizer = optimizer if isinstance(optimizer, _Optimizer) else
|
621
|
+
optimizer = optimizer if isinstance(optimizer, _Optimizer) else _SimplerLMOptimizer.cast(optimizer)
|
602
622
|
objective_function_builder = _objfns.ObjectiveFunctionBuilder.cast(objective_function_builder)
|
603
623
|
array_types = optimizer.array_types + \
|
604
624
|
objective_function_builder.compute_array_types(optimizer.called_objective_methods, start_model.sim)
|
@@ -645,7 +665,7 @@ def run_gst_fit(mdc_store, optimizer, objective_function_builder, verbosity=0):
|
|
645
665
|
objfn_store : MDCObjectiveFunction
|
646
666
|
the objective function and store containing the best-fit model evaluated at the best-fit point.
|
647
667
|
"""
|
648
|
-
optimizer = optimizer if isinstance(optimizer, _Optimizer) else
|
668
|
+
optimizer = optimizer if isinstance(optimizer, _Optimizer) else _SimplerLMOptimizer.cast(optimizer)
|
649
669
|
comm = mdc_store.resource_alloc.comm
|
650
670
|
profiler = mdc_store.resource_alloc.profiler
|
651
671
|
printer = VerbosityPrinter.create_printer(verbosity, comm)
|
@@ -658,16 +678,10 @@ def run_gst_fit(mdc_store, optimizer, objective_function_builder, verbosity=0):
|
|
658
678
|
if _np.linalg.norm(mdc_store.model.to_vector() - v_cmp) > 1e-6:
|
659
679
|
raise ValueError("MPI ERROR: *different* MC2GST start models"
|
660
680
|
" given to different processors!") # pragma: no cover
|
661
|
-
|
662
|
-
#MEM from ..baseobjs.profiler import Profiler
|
663
|
-
#MEM debug_prof = Profiler(comm)
|
664
|
-
#MEM debug_prof.print_memory("run_gst_fit1", True)
|
665
|
-
|
681
|
+
|
666
682
|
if objective_function_builder is not None:
|
667
683
|
objective_function_builder = _objfns.ObjectiveFunctionBuilder.cast(objective_function_builder)
|
668
|
-
#MEM debug_prof.print_memory("run_gst_fit2", True)
|
669
684
|
objective = objective_function_builder.build_from_store(mdc_store, printer) # (objective is *also* a store)
|
670
|
-
#MEM debug_prof.print_memory("run_gst_fit3", True)
|
671
685
|
else:
|
672
686
|
assert(isinstance(mdc_store, _objfns.ObjectiveFunction)), \
|
673
687
|
"When `objective_function_builder` is None, `mdc_store` must be an objective fn!"
|
@@ -686,14 +700,8 @@ def run_gst_fit(mdc_store, optimizer, objective_function_builder, verbosity=0):
|
|
686
700
|
|
687
701
|
printer.log("Completed in %.1fs" % (_time.time() - tStart), 1)
|
688
702
|
|
689
|
-
#if target_model is not None:
|
690
|
-
# target_vec = target_model.to_vector()
|
691
|
-
# targetErrVec = _objective_func(target_vec)
|
692
|
-
# return minErrVec, soln_gs, targetErrVec
|
693
703
|
profiler.add_time("do_mc2gst: total time", tStart)
|
694
|
-
|
695
|
-
# but maybe best to just remove minErrVec from return value since this isn't very useful
|
696
|
-
# anyway?
|
704
|
+
|
697
705
|
return opt_result, objective
|
698
706
|
|
699
707
|
|
@@ -834,7 +842,7 @@ def iterative_gst_generator(dataset, start_model, circuit_lists,
|
|
834
842
|
(an "evaluated" model-dataset-circuits store).
|
835
843
|
"""
|
836
844
|
resource_alloc = _ResourceAllocation.cast(resource_alloc)
|
837
|
-
optimizer = optimizer if isinstance(optimizer, _Optimizer) else
|
845
|
+
optimizer = optimizer if isinstance(optimizer, _Optimizer) else _SimplerLMOptimizer.cast(optimizer)
|
838
846
|
comm = resource_alloc.comm
|
839
847
|
profiler = resource_alloc.profiler
|
840
848
|
printer = VerbosityPrinter.create_printer(verbosity, comm)
|
@@ -869,10 +877,30 @@ def iterative_gst_generator(dataset, start_model, circuit_lists,
|
|
869
877
|
#The ModelDatasetCircuitsStore
|
870
878
|
printer.log('Precomputing CircuitOutcomeProbabilityArray layouts for each iteration.', 2)
|
871
879
|
precomp_layouts = []
|
880
|
+
|
881
|
+
#pre-compute a dictionary caching completed circuits for layout construction performance.
|
882
|
+
unique_circuits = list({ckt for circuit_list in circuit_lists for ckt in circuit_list})
|
883
|
+
if isinstance(mdl.sim, (_fwdsims.MatrixForwardSimulator, _fwdsims.MapForwardSimulator)):
|
884
|
+
precomp_layout_circuit_cache = mdl.sim.create_copa_layout_circuit_cache(unique_circuits, mdl, dataset=dataset)
|
885
|
+
else:
|
886
|
+
precomp_layout_circuit_cache = None
|
887
|
+
|
872
888
|
for i, circuit_list in enumerate(circuit_lists):
|
873
889
|
printer.log(f'Layout for iteration {i}', 2)
|
874
|
-
precomp_layouts.append(mdl.sim.create_layout(circuit_list, dataset, resource_alloc, array_types, verbosity= printer - 1
|
875
|
-
|
890
|
+
precomp_layouts.append(mdl.sim.create_layout(circuit_list, dataset, resource_alloc, array_types, verbosity= printer - 1,
|
891
|
+
layout_creation_circuit_cache = precomp_layout_circuit_cache))
|
892
|
+
|
893
|
+
#precompute a cache of possible outcome counts for each circuits to accelerate MDC store creation
|
894
|
+
if isinstance(mdl, _models.model.OpModel):
|
895
|
+
if precomp_layout_circuit_cache is not None: #then grab the split circuits from there.
|
896
|
+
expanded_circuit_outcome_list = mdl.bulk_expand_instruments_and_separate_povm(unique_circuits,
|
897
|
+
completed_circuits= precomp_layout_circuit_cache['completed_circuits'].values())
|
898
|
+
else:
|
899
|
+
expanded_circuit_outcome_list = mdl.bulk_expand_instruments_and_separate_povm(unique_circuits)
|
900
|
+
outcome_count_by_circuit_cache = {ckt: len(outcome_tup) for ckt,outcome_tup in zip(unique_circuits, expanded_circuit_outcome_list)}
|
901
|
+
else:
|
902
|
+
outcome_count_by_circuit_cache = {ckt: mdl.compute_num_outcomes(ckt) for ckt in unique_circuits}
|
903
|
+
|
876
904
|
with printer.progress_logging(1):
|
877
905
|
for i in range(starting_index, len(circuit_lists)):
|
878
906
|
circuitsToEstimate = circuit_lists[i]
|
@@ -889,7 +917,8 @@ def iterative_gst_generator(dataset, start_model, circuit_lists,
|
|
889
917
|
mdl.basis = start_model.basis # set basis in case of CPTP constraints (needed?)
|
890
918
|
initial_mdc_store = _objfns.ModelDatasetCircuitsStore(mdl, dataset, circuitsToEstimate, resource_alloc,
|
891
919
|
array_types=array_types, verbosity=printer - 1,
|
892
|
-
precomp_layout = precomp_layouts[i]
|
920
|
+
precomp_layout = precomp_layouts[i],
|
921
|
+
outcome_count_by_circuit=outcome_count_by_circuit_cache)
|
893
922
|
mdc_store = initial_mdc_store
|
894
923
|
|
895
924
|
for j, obj_fn_builder in enumerate(iteration_objfn_builders):
|
@@ -1120,8 +1149,6 @@ def find_closest_unitary_opmx(operation_mx):
|
|
1120
1149
|
# d = _np.sqrt(operation_mx.shape[0])
|
1121
1150
|
# I = _np.identity(d)
|
1122
1151
|
|
1123
|
-
#def getu_1q(basisVec): # 1 qubit version
|
1124
|
-
# return _spl.expm( 1j * (basisVec[0]*_tools.sigmax + basisVec[1]*_tools.sigmay + basisVec[2]*_tools.sigmaz) )
|
1125
1152
|
def _get_gate_mx_1q(basis_vec): # 1 qubit version
|
1126
1153
|
return _tools.single_qubit_gate(basis_vec[0],
|
1127
1154
|
basis_vec[1],
|