Skip to content

Commit ad85a98

Browse files
author
Corey Ostrove
committed
Patch broken BCH code path
I hadn't yet updated that codepath after adding in the 'include_spam' kwarg so needed to patch this in.
1 parent 3eda8c0 commit ad85a98

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

pygsti/errorgenpropagation/errorpropagator_dev.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def propagate_errorgens(self, circuit, multi_gate_dict=None, include_spam=True):
196196
return propagated_errorgen_layers
197197

198198

199-
def propagate_errorgens_bch(self, circuit, bch_order=1, bch_layerwise=False, multi_gate_dict=None):
199+
def propagate_errorgens_bch(self, circuit, bch_order=1, bch_layerwise=False, multi_gate_dict=None,
200+
include_spam=True):
200201
"""
201202
Propagate all of the error generators for each circuit to the end,
202203
performing approximation/recombination either along the way (layerwise)
@@ -222,6 +223,10 @@ def propagate_errorgens_bch(self, circuit, bch_order=1, bch_layerwise=False, mul
222223
multi_gate_dict : dict, optional (default None)
223224
An optional dictionary mapping between gate name aliases and their
224225
standard name counterparts.
226+
227+
include_spam : bool, optional (default True)
228+
If True then we include in the propagation the error generators associated
229+
with state preparation and measurement.
225230
"""
226231

227232
msg = 'When bch_layerwise is True this can take the values of either 1 or 2.'\
@@ -235,13 +240,14 @@ def propagate_errorgens_bch(self, circuit, bch_order=1, bch_layerwise=False, mul
235240

236241
#if not doing layerwise BCH then we can re-use `propagate_errorgens` fully.
237242
if not bch_layerwise:
238-
propagated_errorgen_layers = self.propagate_errorgens(circuit, multi_gate_dict)
243+
propagated_errorgen_layers = self.propagate_errorgens(circuit, multi_gate_dict,
244+
include_spam=include_spam)
239245
#otherwise we need to do the error generator layer propagation slightly
240246
#differently.
241247
else:
242248
#start by converting the input circuit into a list of stim Tableaus with the
243249
#first element dropped.
244-
stim_layers = self.construct_stim_layers(circuit, multi_gate_dict, drop_first_layer=True)
250+
stim_layers = self.construct_stim_layers(circuit, multi_gate_dict, drop_first_layer= not include_spam)
245251

246252
#We next want to construct a new set of Tableaus corresponding to the cumulative products
247253
#of each of the circuit layers with those that follow. These Tableaus correspond to the
@@ -253,11 +259,12 @@ def propagate_errorgens_bch(self, circuit, bch_order=1, bch_layerwise=False, mul
253259
#to the error generators for a particular gate layer.
254260
#TODO: Add proper inferencing for number of qubits:
255261
assert circuit.line_labels is not None and circuit.line_labels != ('*',)
256-
errorgen_layers = self.construct_errorgen_layers(circuit, len(circuit.line_labels))
262+
errorgen_layers = self.construct_errorgen_layers(circuit, len(circuit.line_labels), include_spam)
257263

258264
#propagate the errorgen_layers through the propagation_layers to get a list
259265
#of end of circuit error generator dictionaries.
260-
propagated_errorgen_layers = self._propagate_errorgen_layers_bch(errorgen_layers, propagation_layers)
266+
propagated_errorgen_layers = self._propagate_errorgen_layers_bch(errorgen_layers, propagation_layers,
267+
include_spam = include_spam)
261268

262269
return propagated_errorgen_layers
263270

@@ -527,7 +534,7 @@ def _propagate_errorgen_layers(self, errorgen_layers, propagation_layers, includ
527534
return fully_propagated_layers
528535

529536
#TODO: Add an option to return the results with the different BCH order combined.
530-
def _propagate_errorgen_layers_bch(self, errorgen_layers, propagation_layers, bch_order=1):
537+
def _propagate_errorgen_layers_bch(self, errorgen_layers, propagation_layers, bch_order=1, include_spam=True):
531538
"""
532539
Propagates the error generator layers through each of the corresponding propagation layers
533540
(i.e. the clifford operations for the remainder of the circuit). In this version we
@@ -551,6 +558,11 @@ def _propagate_errorgen_layers_bch(self, errorgen_layers, propagation_layers, bc
551558
bch_order : int, optional (default 1)
552559
Order of the BCH approximation to use.
553560
561+
include_spam : bool, optional (default True)
562+
If True then include the error generators for state preparation and measurement
563+
are included in errogen_layers, and the state preparation error generator should
564+
be propagated through (the measurement one is simply appended at the end).
565+
554566
Returns
555567
-------
556568
@@ -570,7 +582,14 @@ def _propagate_errorgen_layers_bch(self, errorgen_layers, propagation_layers, bc
570582
if len(errorgen_layers)>0:
571583
combined_err_layer = errorgen_layers[0]
572584

573-
for i in range(len(errorgen_layers)-1):
585+
#the stopping index in errorgen_layers will depend on whether the measurement error
586+
#generator is included or not.
587+
if include_spam:
588+
stopping_idx = len(errorgen_layers)-2
589+
else:
590+
stopping_idx = len(errorgen_layers)-1
591+
592+
for i in range(stopping_idx):
574593
#err_layer = errorgen_layers[i]
575594
prop_layer = propagation_layers[i]
576595
new_err_layer = []

0 commit comments

Comments
 (0)