pygsti.baseobjs.outcomelabeldict

Defines the OutcomeLabelDict class

Module Contents

Classes

OutcomeLabelDict

An ordered dictionary of outcome labels, whose keys are tuple-valued outcome labels.

class pygsti.baseobjs.outcomelabeldict.OutcomeLabelDict(items=[])

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

items (list or dict, optional) – Initial values. Should only be used as part of de-serialization.

_strict

Whether mapping from strings to 1-tuples is performed.

Type

bool

_strict = False
classmethod to_outcome(cls, 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

val (str or tuple) – The value to convert into an outcome label (i.e. a tuple)

Returns

tuple

__getitem__(self, key)

x.__getitem__(y) <==> x[y]

__setitem__(self, key, val)

Set self[key] to value.

getitem_unsafe(self, 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
  • key (object) – The key to retrieve

  • defaultval (object) – The default value to use (if the key is absent).

Returns

object

setitem_unsafe(self, 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
  • key (object) – The key to retrieve.

  • val (object) – the value to set.

Returns

None

__contains__(self, key)

True if the dictionary has the specified key, else False.

contains_unsafe(self, key)

Checks for key without ensuring that it 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

key (object) – The key to retrieve.

Returns

bool

copy(self)

Return a copy of this OutcomeLabelDict.

Returns

OutcomeLabelDict

__pygsti_reduce__(self)
__reduce__(self)

Helper for pickle.