MCPcopy Create free account
hub / github.com/pytorch/tutorials / _reset

Function _reset

advanced_source/pendulum.py:312–345  ·  view source on GitHub ↗
(self, tensordict)

Source from the content-addressed store, hash-verified

310
311
312def _reset(self, tensordict):
313 if tensordict is None or tensordict.is_empty():
314 # if no ``tensordict`` is passed, we generate a single set of hyperparameters
315 # Otherwise, we assume that the input ``tensordict`` contains all the relevant
316 # parameters to get started.
317 tensordict = self.gen_params(batch_size=self.batch_size)
318
319 high_th = torch.tensor(DEFAULT_X, device=self.device)
320 high_thdot = torch.tensor(DEFAULT_Y, device=self.device)
321 low_th = -high_th
322 low_thdot = -high_thdot
323
324 # for non batch-locked environments, the input ``tensordict`` shape dictates the number
325 # of simulators run simultaneously. In other contexts, the initial
326 # random state's shape will depend upon the environment batch-size instead.
327 th = (
328 torch.rand(tensordict.shape, generator=self.rng, device=self.device)
329 * (high_th - low_th)
330 + low_th
331 )
332 thdot = (
333 torch.rand(tensordict.shape, generator=self.rng, device=self.device)
334 * (high_thdot - low_thdot)
335 + low_thdot
336 )
337 out = TensorDict(
338 {
339 "th": th,
340 "thdot": thdot,
341 "params": tensordict["params"],
342 },
343 batch_size=tensordict.shape,
344 )
345 return out
346
347
348######################################################################

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected