pygsti.baseobjs.outcomelabeldict
Defines the OutcomeLabelDict class
Module Contents
Classes
An ordered dictionary of outcome labels, whose keys are tuple-valued outcome labels. |
- class pygsti.baseobjs.outcomelabeldict.OutcomeLabelDict(items=None)
Bases:
collections.OrderedDict
An ordered dictionary of outcome labels, whose keys are tuple-valued outcome labels.
This class extends an ordinary OrderedDict by implements mapping string-values single-outcome labels to 1-tuples containing that label (and vice versa), allowing the use of strings as outcomes labels from the user’s perspective.
Parameters
- itemslist or dict, optional
Initial values. Should only be used as part of de-serialization.
Attributes
- _strictbool
Whether mapping from strings to 1-tuples is performed.
Creates a new OutcomeLabelDict.
Parameters
- itemslist, optional
Used by pickle and other serializations to initialize elements.
- classmethod to_outcome(val)
Converts string outcomes like “0” to proper outcome tuples, like (“0”,).
(also converts non-tuples to tuples, e.g. [“0”,”1”] to (“0”,”1”) )
Parameters
- valstr or tuple
The value to convert into an outcome label (i.e. a tuple)
Returns
tuple
- get(key, default)
Return the value for key if key is in the dictionary, else default.
- getitem_unsafe(key, defaultval)
Gets an item without checking that key is a properly formatted outcome tuple.
Only use this method when you’re sure key is an outcome tuple and not, e.g., just a string.
Parameters
- keyobject
The key to retrieve
- defaultvalobject
The default value to use (if the key is absent).
Returns
object
- setitem_unsafe(key, val)
Sets item without checking that the key is a properly formatted outcome tuple.
Only use this method when you’re sure key is an outcome tuple and not, e.g., just a string.
Parameters
- keyobject
The key to retrieve.
- valobject
the value to set.
Returns
None