Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Dynamic specs #2143

Merged
merged 27 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
amend
  • Loading branch information
vmoens committed May 27, 2024
commit c13549f685ad92cd347f68ac888b72ed4e52b90b
15 changes: 10 additions & 5 deletions test/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def env_fn(seed):
total_frames=20000,
device="cpu",
)
assert collector._use_buffers
for i, d in enumerate(collector):
if i == 0:
b1 = d
Expand Down Expand Up @@ -587,14 +588,18 @@ def env_fn(seed):
b2c = d
else:
break
assert ccollector._use_buffers
assert d.names[-1] == "time"
with pytest.raises(AssertionError):
assert_allclose_td(b1c, b2c)

assert_allclose_td(b1c, b1)
assert_allclose_td(b2c, b2)
try:
with pytest.raises(AssertionError):
assert_allclose_td(b1c, b2c)

ccollector.shutdown()
assert_allclose_td(b1c, b1)
assert_allclose_td(b2c, b2)
finally:
ccollector.shutdown()
del ccollector


@pytest.mark.skipif(not _has_gym, reason="gym library is not installed")
Expand Down
4 changes: 2 additions & 2 deletions torchrl/collectors/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2424,10 +2424,10 @@ def _get_from_queue(self, timeout=None) -> Tuple[int, int, TensorDictBase]:
data, idx = new_data
self.out_tensordicts[idx] = data
if use_buffers is None and j > 0:
self._use_buffers = False
use_buffers = self._use_buffers = False
except TypeError:
if use_buffers is None:
self._use_buffers = True
use_buffers = self._use_buffers = True
idx = new_data
else:
raise
Expand Down
Loading