@@ -2294,43 +2294,41 @@ def _add_badfit_estimates(results, base_estimate_label, badfit_options,
2294
2294
def _compute_wildcard_budget_1d_model (estimate , objfn_cache , mdc_objfn , parameters , badfit_options , verbosity , gaugeopt_suite = None ):
2295
2295
"""
2296
2296
Create a wildcard budget for a model estimate. This version of the function produces a wildcard estimate
2297
- using the model introduced by Tim and Stefan in the RCSGST paper.
2298
- TODO: docstring (update)
2297
+ using the model introduced in https://doi.org/10.1038/s41534-023-00764-y.
2299
2298
2300
2299
Parameters
2301
2300
----------
2302
- model : Model
2303
- The model to add a wildcard budget to .
2301
+ estimate : Estimate
2302
+ The estimate object containing the model and data to be used .
2304
2303
2305
- ds : DataSet
2306
- The data the model predictions are being compared with .
2304
+ objfn_cache : ObjectiveFunctionCache
2305
+ A cache for objective function evaluations .
2307
2306
2308
- circuits_to_use : list
2309
- The circuits whose data are compared .
2307
+ mdc_objfn : ModelDatasetCircuitsStore
2308
+ An object that stores the model, dataset, and circuits to be used in the computation .
2310
2309
2311
2310
parameters : dict
2312
2311
Various parameters of the estimate at hand.
2313
2312
2314
2313
badfit_options : GSTBadFitOptions, optional
2315
2314
Options specifying what post-processing actions should be performed when
2316
- a fit is unsatisfactory. Contains detailed parameters for wildcard budget
2315
+ a fit is unsatisfactory. Contains detailed parameters for wildcard budget
2317
2316
creation.
2318
2317
2319
- comm : mpi4py.MPI.Comm, optional
2320
- An MPI communicator used to run this computation in parallel.
2321
-
2322
- mem_limit : int, optional
2323
- A rough per-processor memory limit in bytes.
2324
-
2325
2318
verbosity : int, optional
2326
2319
Level of detail printed to stdout.
2327
-
2320
+
2328
2321
gaugeopt_suite : GSTGaugeOptSuite, optional (default None)
2329
- The 1-D wildcard models can be based on gauge-variant functions such as the diamond distance. When gauge optimization is applied this will ensure the gauge optimized models used are consistent in the wildcard model and the parent estimates.
2322
+ The 1-D wildcard models can be based on gauge-variant functions such as the diamond distance.
2323
+ When gauge optimization is applied, this will ensure the gauge optimized models used are consistent
2324
+ in the wildcard model and the parent estimates.
2330
2325
2331
2326
Returns
2332
2327
-------
2333
- PrimitiveOpsWildcardBudget
2328
+ PrimitiveOpsWildcardBudget or dict
2329
+ The computed wildcard budget. If gauge optimization is applied, a dictionary of
2330
+ budgets keyed by gauge optimization labels is returned.
2331
+
2334
2332
"""
2335
2333
printer = _baseobjs .VerbosityPrinter .create_printer (verbosity , mdc_objfn .resource_alloc )
2336
2334
badfit_options = GSTBadFitOptions .cast (badfit_options )
@@ -2387,9 +2385,32 @@ def _compute_wildcard_budget_1d_model(estimate, objfn_cache, mdc_objfn, paramete
2387
2385
2388
2386
2389
2387
def _compute_1d_reference_values_and_name (estimate , badfit_options , gaugeopt_suite = None ):
2390
- '''
2391
- DOCSTRING: TODO
2392
- '''
2388
+ """
2389
+ Compute the reference values and name for the 1D wildcard budget.
2390
+
2391
+ Parameters
2392
+ ----------
2393
+ estimate : Estimate
2394
+ The estimate object containing the models to be used.
2395
+
2396
+ badfit_options : GSTBadFitOptions
2397
+ Options specifying what post-processing actions should be performed when
2398
+ a fit is unsatisfactory. Contains detailed parameters for wildcard budget
2399
+ creation.
2400
+
2401
+ gaugeopt_suite : GSTGaugeOptSuite, optional (default None)
2402
+ The gauge optimization suite used by the estimate. If None, final iteration
2403
+ estimate will be used.
2404
+
2405
+ Returns
2406
+ -------
2407
+ dict or dict of dicts
2408
+ The computed reference values for the 1D wildcard budget. If gauge optimization is applied,
2409
+ a dictionary of reference values keyed by gauge optimization labels is returned.
2410
+
2411
+ str
2412
+ The name of the reference metric used.
2413
+ """
2393
2414
if badfit_options .wildcard1d_reference == 'diamond distance' :
2394
2415
if gaugeopt_suite is None or gaugeopt_suite .gaugeopt_suite_names is None :
2395
2416
final_model = estimate .models ['final iteration estimate' ]
@@ -2398,10 +2419,13 @@ def _compute_1d_reference_values_and_name(estimate, badfit_options, gaugeopt_sui
2398
2419
if isinstance (final_model , _ExplicitOpModel ):
2399
2420
gaugeopt_model = _alg .gaugeopt_to_target (final_model , target_model )
2400
2421
operations_dict = gaugeopt_model .operations
2401
- targetops_dict = target_model .operations
2422
+ targetops_dict = target_model .operations
2402
2423
preps_dict = gaugeopt_model .preps
2403
2424
targetpreps_dict = target_model .preps
2404
2425
povmops_dict = gaugeopt_model .povms
2426
+ insts_dict = gaugeopt_model .instruments
2427
+ targetinsts_dict = target_model .instruments
2428
+
2405
2429
else :
2406
2430
# Local/cloud noise models don't have default_gauge_group attribute and can't be gauge
2407
2431
# optimized - at least not easily.
@@ -2419,6 +2443,14 @@ def _compute_1d_reference_values_and_name(estimate, badfit_options, gaugeopt_sui
2419
2443
_warnings .warn (("Diamond distance failed to compute %s reference value for 1D wildcard budget!"
2420
2444
" Falling back to trace distance." ) % str (key ))
2421
2445
dd [key ] = _tools .jtracedist (op .to_dense (), targetops_dict [key ].to_dense ())
2446
+
2447
+ for key , op in insts_dict .items ():
2448
+ inst_dd = .5 * _tools .instrument_diamonddist (op , targetinsts_dict [key ])
2449
+ if inst_dd < 0 : # indicates that instrument_diamonddist failed
2450
+ _warnings .warn (("Diamond distance failed to compute %s reference value for 1D wildcard budget!"
2451
+ "No fallback presently available for instruments, so skipping." ) % str (key ))
2452
+ else :
2453
+ dd [key ] = inst_dd
2422
2454
2423
2455
spamdd = {}
2424
2456
for key , op in preps_dict .items ():
@@ -2444,15 +2476,22 @@ def _compute_1d_reference_values_and_name(estimate, badfit_options, gaugeopt_sui
2444
2476
" Falling back to trace distance." ) % str (key ))
2445
2477
dd [lbl ][key ] = _tools .jtracedist (op .to_dense (), target_model .operations [key ].to_dense ())
2446
2478
2447
- spamdd = {}
2448
- for key , op in gaugeopt_model .preps .items ():
2449
- spamdd [key ] = _tools .tracedist (_tools .vec_to_stdmx (op .to_dense (), 'pp' ),
2450
- _tools .vec_to_stdmx (target_model .preps [key ].to_dense (), 'pp' ))
2479
+ for key , op in gaugeopt_model .instruments .items ():
2480
+ inst_dd = .5 * _tools .instrument_diamonddist (op , target_model .instruments [key ], gaugeopt_model .basis )
2481
+ if inst_dd < 0 : # indicates that instrument_diamonddist failed
2482
+ _warnings .warn (("Diamond distance failed to compute %s reference value for 1D wildcard budget!"
2483
+ "No fallback presently available for instruments, so skipping." ) % str (key ))
2484
+ else :
2485
+ dd [lbl ][key ] = inst_dd
2486
+ spamdd = {}
2487
+ for key , op in gaugeopt_model .preps .items ():
2488
+ spamdd [key ] = _tools .tracedist (_tools .vec_to_stdmx (op .to_dense (), 'pp' ),
2489
+ _tools .vec_to_stdmx (target_model .preps [key ].to_dense (), 'pp' ))
2451
2490
2452
- for key in gaugeopt_model .povms .keys ():
2453
- spamdd [key ] = 0.5 * _tools .optools .povm_diamonddist (gaugeopt_model , target_model , key )
2491
+ for key in gaugeopt_model .povms .keys ():
2492
+ spamdd [key ] = 0.5 * _tools .optools .povm_diamonddist (gaugeopt_model , target_model , key )
2454
2493
2455
- dd [lbl ]['SPAM' ] = sum (spamdd .values ())
2494
+ dd [lbl ]['SPAM' ] = sum (spamdd .values ())
2456
2495
return dd , 'diamond distance'
2457
2496
else :
2458
2497
raise ValueError ("Invalid wildcard1d_reference value (%s) in bad-fit options!"
0 commit comments