pygsti.models.memberdict

Defines OrderedDict-derived classes used to store specific pyGSTi objects

Module Contents

Classes

_PrefixOrderedDict

Base class ordered dictionaries whose keys must be strings which begin with a given prefix.

OrderedMemberDict

An ordered dictionary whose keys must begin with a given prefix.

class pygsti.models.memberdict._PrefixOrderedDict(prefix, items=[])

Bases: collections.OrderedDict

Base class ordered dictionaries whose keys must be strings which begin with a given prefix.

Parameters
  • prefix (str) – The required prefix.

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

__setitem__(self, key, val)

Assumes key is a Label object

class pygsti.models.memberdict.OrderedMemberDict(parent, default_param, prefix, flags, items=[])

Bases: _PrefixOrderedDict, pygsti.modelmembers.modelmember.ModelChild

An ordered dictionary whose keys must begin with a given prefix.

This class also ensure that every value is an object of the appropriate Model member type (e.g. State- or LinearOperator-derived object) by converting any values into that type upon assignment and raising an error if this is not possible.

Parameters
  • parent (Model) – The parent model, needed to obtain the dimension and handle updates to parameters.

  • default_param ({"TP","full",...}) – The default parameterization used when creating an object from a key assignment.

  • prefix (str) – The required prefix of all keys (which must be strings).

  • flags (dict) –

    A dictionary of flags adjusting the behavior of the created object. Allowed keys are:

    • ’cast_to_type’: {“operation”,`”state”,`None} – whether (or not) to automatically convert assigned values to a particular type of ModelMember object. (default is None)

    • ’auto_embed’ : bool – whether or not to automatically embed objects with a lower dimension than this OrderedMemberDict’s parent model. (default is False).

    • ’match_parent_statespace’ : bool – whether or not to require that all contained objects match the parent Model’s state space (perhaps after embedding). (default is False)

    • ’match_parent_evotype’ : bool – whether or not to require that all contained objects match the parent Model’s evolution type. (default is False).

  • items (list, optional) – Used by pickle and other serializations to initialize elements.

_check_state_space(self, obj)
_check_evotype(self, evotype)
__contains__(self, key)

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

__getitem__(self, key)

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

_auto_embed(self, key_label, value)
cast_to_model_member(self, value)

Cast value to an object with the default parameterization if it’s not a ModelMember.

Creates an object from value with a type given by the default parameterization if value isn’t a ModelMember.

Parameters

value (object) – The object to act on.

Returns

object

__setitem__(self, key, value)

Assumes key is a Label object

__delitem__(self, key)

Implements del self[key]

copy(self, parent=None, memo=None)

Returns a copy of this OrderedMemberDict.

Parameters

parent (Model) – The new parent Model, if one exists. Typically, when copying an OrderedMemberDict you want to reset the parent.

Returns

OrderedMemberDict

__reduce__(self)

Helper for pickle.

__pygsti_reduce__(self)