:py:mod:`pygsti.modelmembers.torchable` ======================================= .. py:module:: pygsti.modelmembers.torchable .. autoapi-nested-parse:: Defines the interface that ModelMembers must satisfy to be compatible with the PyTorch-backed forward simulator in pyGSTi/forwardsims/torchfwdsim.py. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pygsti.modelmembers.torchable.Torchable .. py:class:: Torchable(state_space, evotype, gpindices=None, parent=None) Bases: :py:obj:`pygsti.modelmembers.modelmember.ModelMember` Base 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_space : StateSpace The state space, which should match the parent model if/when one exists. evotype : EvoType or str The evolution type, which should match the parent model if/when one exists. gpindices : slice or numpy.ndarray, optional The indices of this member's local parameters into the parent Model's parameter vector. parent : Model, optional The parent model. Attributes ---------- dirty : bool 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. gpindices : slice or numpy.ndarray The indices of this member's local parameters into the parent Model's parameter vector. parent : Model, optional The parent model. Initialize a new ModelMember .. py:method:: stateless_data() -> Tuple :abstractmethod: 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. .. py:method:: torch_base(sd: Tuple, t_param: torch.Tensor) -> torch.Tensor :staticmethod: :abstractmethod: 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 ``.base`` attribute, then a reasonable implementation will probably satisfy np.allclose(obj.base, t.numpy()).