leaspy.io.realizations
.PopulationRealization
- class PopulationRealization(name: str, shape: Tuple[int, ...], *, tensor: Tensor | None = None, tensor_copy: bool = True, **kwargs)
Bases:
AbstractRealization
Class for realizations of population variables.
- Parameters:
- nameParamType
The name of the variable associated with the realization.
- shapeTuple[int, …]
The shape of the tensor realization.
- tensortorch.Tensor, optional
If not None, the tensor realization to be stored.
- tensor_copybool (default True)
Whether the tensor provided is copied or not.
- **kwargsdict
Additional parameters.
- Attributes:
- tensor
Methods
initialize
(model, **kwargs)Initialize the realization from a model instance.
Set autograd for tensor of realizations.
set_tensor_realizations_element
(element, dim)Manually change the value (in-place) of tensor_realizations at dimension dim.
to_dict
()Return a serialized dictionary of realization attributes.
Unset autograd for tensor of realizations
- initialize(model: AbstractModel, **kwargs: KwargsType) None
Initialize the realization from a model instance.
- Parameters:
- modelAbstractModel
The model from which to initialize the realization.
- **kwargsKwargsType
Additional parameters for initialization.
- set_autograd() None
Set autograd for tensor of realizations.
TODO remove? only in legacy code
- Raises:
ValueError
if inconsistent internal request
See also
- set_tensor_realizations_element(element: Tensor, dim: tuple[int, ...]) None
Manually change the value (in-place) of tensor_realizations at dimension dim.
- Parameters:
- elementtorch.Tensor
The element to put in the tensor realization.
- dimTuple[int, …]
The dimension where to put the element.
- unset_autograd() None
Unset autograd for tensor of realizations
TODO remove? only in legacy code
- Raises:
ValueError
if inconsistent internal request
See also