pygsti.modelmembers.torchable
Defines the interface that ModelMembers must satisfy to be compatible with the PyTorch-backed forward simulator in pyGSTi/forwardsims/torchfwdsim.py.
Module Contents
Classes
Base class for Model member objects that possess a definite state space, parameters count, and evolution type. |
- class pygsti.modelmembers.torchable.Torchable(state_space, evotype, gpindices=None, parent=None)
Bases:
pygsti.modelmembers.modelmember.ModelMemberBase class for Model member objects that possess a definite state space, parameters count, and evolution type.
A ModelMember can be vectorized into/onto a portion of their parent Model’s (or other ModelMember’s) parameter vector. They therefore contain a gpindices reference to the global Model indices “owned” by this member. Note that GateSetMembers may contain other GateSetMembers (may be nested).
Parameters
- state_spaceStateSpace
The state space, which should match the parent model if/when one exists.
- evotypeEvoType or str
The evolution type, which should match the parent model if/when one exists.
- gpindicesslice or numpy.ndarray, optional
The indices of this member’s local parameters into the parent Model’s parameter vector.
- parentModel, optional
The parent model.
Attributes
- dirtybool
Whether this member’s local parameters may have been updated without its parent’s knowledge. The parent model can check this flag and perform re-synchronization of it’s parameter vector when needed.
- gpindicesslice or numpy.ndarray
The indices of this member’s local parameters into the parent Model’s parameter vector.
- parentModel, optional
The parent model.
Initialize a new ModelMember
- abstractmethod stateless_data() Tuple
Return this ModelMember’s data that is considered constant for purposes of model fitting.
Note: the word “stateless” here is used in the sense of object-oriented programming.
- abstractmethod static torch_base(sd: Tuple, t_param: torch.Tensor) torch.Tensor
Suppose “obj” is an instance of some Torchable subclass. If we compute
vec = obj.to_vector() t_param = torch.from_numpy(vec) sd = obj.stateless_data() t = type(obj).torch_base(sd, t_param)
then t will be a PyTorch Tensor that represents “obj” in a canonical numerical way.
The meaning of “canonical” is implementation dependent. If type(obj) implements the
.baseattribute, then a reasonable implementation will probably satisfynp.allclose(obj.base, t.numpy()).