pygsti.models.memberdict.OrderedMemberDict#

class OrderedMemberDict(parent, default_param, prefix, flags, items=None)#

Bases: _PrefixOrderedDict, 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.

Creates a new OrderedMemberDict.

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.

Methods

__init__(parent, default_param, prefix, flags)

Creates a new OrderedMemberDict.

cast_to_model_member(value)

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

clear()

copy([parent, memo])

Returns a copy of this OrderedMemberDict.

fromkeys([value])

Create a new ordered dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

move_to_end(key[, last])

Move an existing element to the end (or beginning if last is false).

pop(key[,default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem([last])

Remove and return a (key, value) pair from the dictionary.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

Attributes

parent

Gets the parent of this object.

cast_to_model_member(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.

Return type:

object

clear() None.  Remove all items from od.#
copy(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.

Return type:

OrderedMemberDict

fromkeys(value=None)#

Create a new ordered dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
move_to_end(key, last=True)#

Move an existing element to the end (or beginning if last is false).

Raise KeyError if the element does not exist.

pop(key[, default]) v, remove specified key and return the corresponding value.#

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(last=True)#

Remove and return a (key, value) pair from the dictionary.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(key, default=None)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#
property parent: Model#

Gets the parent of this object.

Return type:

Model