diff --git a/pygsti/baseobjs/label.py b/pygsti/baseobjs/label.py index c0e6102b9..172d63274 100644 --- a/pygsti/baseobjs/label.py +++ b/pygsti/baseobjs/label.py @@ -187,6 +187,15 @@ def expand_subcircuits(self): :class:`CircuitLabel` objects). """ return (self,) # most labels just expand to themselves + + @property + def is_simple(self): + """ + Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. + """ + + return self.IS_SIMPLE + class LabelTup(Label, tuple): @@ -200,7 +209,7 @@ class LabelTup(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= True + IS_SIMPLE = True @classmethod def init(cls, name, state_space_labels): @@ -436,7 +445,7 @@ class LabelTupWithTime(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= True + IS_SIMPLE = True @classmethod def init(cls, name, state_space_labels, time=0.0): @@ -680,7 +689,7 @@ class LabelStr(Label, str): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= True + IS_SIMPLE = True @classmethod def init(cls, name, time=0.0): @@ -853,7 +862,7 @@ class LabelTupTup(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= False + IS_SIMPLE = False @classmethod def init(cls, tup_of_tups): @@ -1108,7 +1117,7 @@ class LabelTupTupWithTime(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= False + IS_SIMPLE = False @classmethod def init(cls, tup_of_tups, time=None): @@ -1369,7 +1378,7 @@ class CircuitLabel(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= True + IS_SIMPLE = True def __new__(cls, name, tup_of_layers, state_space_labels, reps=1, time=None): # Note: may need default args for all but 1st for pickling! @@ -1641,7 +1650,7 @@ class LabelTupWithArgs(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= True + IS_SIMPLE = True @classmethod def init(cls, name, state_space_labels, time=0.0, args=()): @@ -1909,7 +1918,7 @@ class LabelTupTupWithArgs(Label, tuple): #flag used in certain Circuit subroutines #Whether this is a "simple" (opaque w/a true name, from a circuit perspective) label or not. - is_simple= False + IS_SIMPLE = False @classmethod def init(cls, tup_of_tups, time=None, args=()): diff --git a/pygsti/circuits/circuit.py b/pygsti/circuits/circuit.py index 56c571e94..6764d322c 100644 --- a/pygsti/circuits/circuit.py +++ b/pygsti/circuits/circuit.py @@ -96,7 +96,7 @@ def _label_to_nested_lists_of_simple_labels(lbl, default_sslbls=None, always_ret """ Convert lbl into nested lists of *simple* labels """ if not isinstance(lbl, _Label): # if not a Label, make into a label, lbl = _Label(lbl) # e.g. a string or list/tuple of labels, etc. - if lbl.is_simple: # a *simple* label - the elements of our lists + if lbl.IS_SIMPLE: # a *simple* label - the elements of our lists if lbl.sslbls is None and default_sslbls is not None: lbl = _Label(lbl.name, default_sslbls) return [lbl] if always_return_list else lbl @@ -120,7 +120,7 @@ def _accumulate_explicit_sslbls(obj): """ ret = set() if isinstance(obj, _Label): - if not obj.is_simple: + if not obj.IS_SIMPLE: for lbl in obj.components: ret.update(_accumulate_explicit_sslbls(lbl)) else: # a simple label @@ -1027,7 +1027,7 @@ def copy(self, editable='auto'): if editable: if self._static: #static and editable circuits have different conventions for _labels. - editable_labels =[[lbl] if lbl.is_simple else list(lbl.components) for lbl in self._labels] + editable_labels =[[lbl] if lbl.IS_SIMPLE else list(lbl.components) for lbl in self._labels] return ret._copy_init(editable_labels, self._line_labels, editable, self._name, self._str, self._occurrence_id, self._compilable_layer_indices_tup) @@ -1107,7 +1107,7 @@ def _layer_components(self, ilayer): """ Get the components of the `ilayer`-th layer as a list/tuple. """ #(works for static and non-static Circuits) if self._static: - if self._labels[ilayer].is_simple: return [self._labels[ilayer]] + if self._labels[ilayer].IS_SIMPLE: return [self._labels[ilayer]] else: return self._labels[ilayer].components else: return self._labels[ilayer] if isinstance(self._labels[ilayer], list) \ @@ -2762,7 +2762,7 @@ def mapper_func(gatename): return mapper.get(gatename, None) \ def map_names(obj): # obj is either a simple label or a list if isinstance(obj, _Label): - if obj.is_simple: # *simple* label + if obj.IS_SIMPLE: # *simple* label new_name = mapper_func(obj.name) newobj = _Label(new_name, obj.sslbls) \ if (new_name is not None) else obj @@ -3401,7 +3401,7 @@ def size(self): #TODO HERE -update from here down b/c of sub-circuit blocks if self._static: def size(lbl): # obj a Label, perhaps compound - if lbl.is_simple: # a simple label + if lbl.IS_SIMPLE: # a simple label return len(lbl.sslbls) if (lbl.sslbls is not None) else len(self._line_labels) else: return sum([size(sublbl) for sublbl in lbl.components]) @@ -3456,7 +3456,7 @@ def num_nq_gates(self, nq): """ if self._static: def cnt(lbl): # obj a Label, perhaps compound - if lbl.is_simple: # a simple label + if lbl.IS_SIMPLE: # a simple label return 1 if (lbl.sslbls is not None) and (len(lbl.sslbls) == nq) else 0 else: return sum([cnt(sublbl) for sublbl in lbl.components]) @@ -3484,7 +3484,7 @@ def num_multiq_gates(self): """ if self._static: def cnt(lbl): # obj a Label, perhaps compound - if lbl.is_simple: # a simple label + if lbl.IS_SIMPLE: # a simple label return 1 if (lbl.sslbls is not None) and (len(lbl.sslbls) >= 2) else 0 else: return sum([cnt(sublbl) for sublbl in lbl.components]) @@ -3507,7 +3507,7 @@ def _togrid(self, identity_name): for layercomp in self._layer_components(ilayer): if isinstance(layercomp, _Label): comp_label = layercomp - if layercomp.is_simple: + if layercomp.IS_SIMPLE: comp_sslbls = layercomp.sslbls else: #We can't intelligently flatten compound labels that occur within a layer-label yet...