@@ -1480,6 +1480,77 @@ def full_state_spec(self) -> Composite:
1480
1480
def full_state_spec (self , spec : Composite ) -> None :
1481
1481
self .state_spec = spec
1482
1482
1483
+ # Single-env specs can be used to remove the batch size from the spec
1484
+ @property
1485
+ def batch_dims (self ):
1486
+ return len (self .batch_size )
1487
+
1488
+ def _make_single_env_spec (self , spec : TensorSpec ) -> TensorSpec :
1489
+ if not self .batch_dims :
1490
+ return spec
1491
+ idx = tuple (0 for _ in range (self .batch_dims ))
1492
+ return spec [idx ]
1493
+
1494
+ @property
1495
+ def single_full_action_spec (self ) -> Composite :
1496
+ """Returns the action spec of the env as if it had no batch dimensions."""
1497
+ return self ._make_single_env_spec (self .full_action_spec )
1498
+
1499
+ @property
1500
+ def single_action_spec (self ) -> TensorSpec :
1501
+ """Returns the action spec of the env as if it had no batch dimensions."""
1502
+ return self ._make_single_env_spec (self .action_spec )
1503
+
1504
+ @property
1505
+ def single_full_observation_spec (self ) -> Composite :
1506
+ """Returns the observation spec of the env as if it had no batch dimensions."""
1507
+ return self ._make_single_env_spec (self .full_action_spec )
1508
+
1509
+ @property
1510
+ def single_observation_spec (self ) -> Composite :
1511
+ """Returns the observation spec of the env as if it had no batch dimensions."""
1512
+ return self ._make_single_env_spec (self .observation_spec )
1513
+
1514
+ @property
1515
+ def single_full_reward_spec (self ) -> Composite :
1516
+ """Returns the reward spec of the env as if it had no batch dimensions."""
1517
+ return self ._make_single_env_spec (self .full_action_spec )
1518
+
1519
+ @property
1520
+ def single_reward_spec (self ) -> TensorSpec :
1521
+ """Returns the reward spec of the env as if it had no batch dimensions."""
1522
+ return self ._make_single_env_spec (self .reward_spec )
1523
+
1524
+ @property
1525
+ def single_full_done_spec (self ) -> Composite :
1526
+ """Returns the done spec of the env as if it had no batch dimensions."""
1527
+ return self ._make_single_env_spec (self .full_action_spec )
1528
+
1529
+ @property
1530
+ def single_done_spec (self ) -> TensorSpec :
1531
+ """Returns the done spec of the env as if it had no batch dimensions."""
1532
+ return self ._make_single_env_spec (self .done_spec )
1533
+
1534
+ @property
1535
+ def single_output_spec (self ) -> Composite :
1536
+ """Returns the output spec of the env as if it had no batch dimensions."""
1537
+ return self ._make_single_env_spec (self .output_spec )
1538
+
1539
+ @property
1540
+ def single_input_spec (self ) -> Composite :
1541
+ """Returns the input spec of the env as if it had no batch dimensions."""
1542
+ return self ._make_single_env_spec (self .input_spec )
1543
+
1544
+ @property
1545
+ def single_full_state_spec (self ) -> Composite :
1546
+ """Returns the state spec of the env as if it had no batch dimensions."""
1547
+ return self ._make_single_env_spec (self .full_state_spec )
1548
+
1549
+ @property
1550
+ def single_state_spec (self ) -> TensorSpec :
1551
+ """Returns the state spec of the env as if it had no batch dimensions."""
1552
+ return self ._make_single_env_spec (self .state_spec )
1553
+
1483
1554
def step (self , tensordict : TensorDictBase ) -> TensorDictBase :
1484
1555
"""Makes a step in the environment.
1485
1556
0 commit comments