Skip to content

Commit

Permalink
Fix bugs in new extract_labels implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Ostrove committed Jun 5, 2024
1 parent c39101d commit 6cc69bc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pygsti/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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...

Expand Down

0 comments on commit 6cc69bc

Please sign in to comment.