Return recording to user. :param var: State variable recording to return. :return: Tensor of shape ``[time, n_1, ..., n_k]``, where ``[n_1, ..., n_k]`` is the shape of the recorded state variable. Note, if time == `None`, get return the logs and empty the mo
(self, var: str)
| 73 | self.reset_state_variables() |
| 74 | |
| 75 | def get(self, var: str) -> torch.Tensor: |
| 76 | # language=rst |
| 77 | """ |
| 78 | Return recording to user. |
| 79 | |
| 80 | :param var: State variable recording to return. |
| 81 | :return: Tensor of shape ``[time, n_1, ..., n_k]``, where ``[n_1, ..., n_k]`` is the shape of the recorded state |
| 82 | variable. |
| 83 | Note, if time == `None`, get return the logs and empty the monitor variable |
| 84 | |
| 85 | """ |
| 86 | if self.clean: |
| 87 | return_logs = torch.empty(0, device=self.device) |
| 88 | else: |
| 89 | # If the actual run length is shorter than the preallocated time, |
| 90 | # some placeholders remain and break torch.cat, so we drop them. |
| 91 | entries = [e for e in self.recording[var] if torch.is_tensor(e)] |
| 92 | if len(entries) == 0: |
| 93 | return_logs = torch.empty(0, device=self.device) |
| 94 | else: |
| 95 | return_logs = torch.cat(entries, 0) |
| 96 | if self.time is None: |
| 97 | self.recording[var] = [] |
| 98 | return return_logs |
| 99 | |
| 100 | def record(self) -> None: |
| 101 | # language=rst |
no outgoing calls