diff --git a/pygsti/circuits/circuit.py b/pygsti/circuits/circuit.py index c5df6bc5f..a65629953 100644 --- a/pygsti/circuits/circuit.py +++ b/pygsti/circuits/circuit.py @@ -1193,26 +1193,29 @@ def extract_labels(self, layers=None, lines=None, strict=True): Note that the returned circuit doesn't retain any original metadata, such as the compilable layer indices or occurence id. """ + nonint_layers = not isinstance(layers, int) #Shortcut for common case when lines == None and when we're only taking a layer slice/index if lines is None and layers is not None: if self._static: - if isinstance(layers, int): + if not nonint_layers: return self._labels[layers] if isinstance(layers, slice) and strict is True: # if strict=False, then need to recompute line labels #can speed this up a measurably by manually computing the new hashable tuple value and hash - new_hashable_tup = self._labels[layers] + ('@',) + self._line_labels + if not self._line_labels in (('*',), ()): + new_hashable_tup = self._labels[layers] + ('@',) + self._line_labels + else: + new_hashable_tup = self._labels[layers] ret = Circuit.__new__(Circuit) - return ret._copy_init(self._labels[layers], self._line_labels, not self._static, - hashable_tup= new_hashable_tup, - precomp_hash=hash(new_hashable_tup)) + return ret._copy_init(self._labels[layers], self._line_labels, not self._static, hashable_tup= new_hashable_tup, precomp_hash=hash(new_hashable_tup)) else: - if isinstance(layers, int): + if not nonint_layers: return self.layertup[layers] if isinstance(layers, slice) and strict is True: # if strict=False, then need to recompute line labels return Circuit._fastinit(self._labels[layers], self._line_labels, not self._static) #otherwise assert both are not None: + layers = self._proc_layers_arg(layers) lines = self._proc_lines_arg(lines) if len(layers) == 0 or len(lines) == 0: @@ -1245,7 +1248,7 @@ def get_sslbls(lbl): return lbl.sslbls ret_layer.append(l) ret.append(_Label(ret_layer) if len(ret_layer) != 1 else ret_layer[0]) # Labels b/c we use _fastinit - if not isinstance(layers, int): + if nonint_layers: if not strict: lines = "auto" # since we may have included lbls on other lines # don't worry about string rep for now...