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

Support different state size and fix exception in venv.__del__ #352

Merged
merged 8 commits into from
Apr 25, 2021

Conversation

Trinkle23897
Copy link
Collaborator

@Trinkle23897 Trinkle23897 commented Apr 24, 2021

close #351 and #346

I add a try...except ValueError block because of the following reason:

  • if the observation is a dict/other class: np.stack automatically converts to dtype=np.object
  • if the observation is a normal array (with the same shape): np.stack behaves normally as previous
  • if the observation is a list of array with different shape or classes like nx.Graph which rewrite __getitem__: we need to manually convert to np.object
  • if the observation is a list of list (e.g. np.array([[1], [2,3], [4,5,6]])): np.stack automatically converts this type of data to np.object
  • other things such as rew/done/info: their type are pre-determined, i.e., rew is a float, done is a boolean, info is a dict, and they can be handled by np.stack correctly. No need to change these logics.

Also there's workaround related to #147: do not raise error when it finds list of np.array with different shape[0].

As for #346, __del__ causes several bugs even before this issue, so just simply remove it and let the user decide whether or not to close the env instead of automatically closing in the end.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2021

Codecov Report

Merging #352 (2c1cc1d) into master (bbc3c3e) will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #352      +/-   ##
==========================================
+ Coverage   94.30%   94.46%   +0.15%     
==========================================
  Files          53       53              
  Lines        3406     3413       +7     
==========================================
+ Hits         3212     3224      +12     
+ Misses        194      189       -5     
Flag Coverage Δ
unittests 94.46% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tianshou/data/batch.py 99.74% <100.00%> (+<0.01%) ⬆️
tianshou/env/venvs.py 91.66% <100.00%> (+0.36%) ⬆️
tianshou/policy/modelfree/trpo.py 93.33% <100.00%> (-0.11%) ⬇️
tianshou/data/collector.py 95.35% <0.00%> (+0.42%) ⬆️
tianshou/env/worker/subproc.py 93.95% <0.00%> (+2.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbc3c3e...2c1cc1d. Read the comment docs.

@Trinkle23897 Trinkle23897 changed the title fix np.stack ValueError in VectorEnv Support different state size and fix exception in venv.__del__ Apr 24, 2021
@Trinkle23897 Trinkle23897 linked an issue Apr 24, 2021 that may be closed by this pull request
8 tasks
@Trinkle23897 Trinkle23897 requested a review from ChenDRAG April 24, 2021 14:04
@Trinkle23897 Trinkle23897 merged commit ff4d3cd into master Apr 25, 2021
@Trinkle23897 Trinkle23897 deleted the venv-obs-fix branch April 25, 2021 07:23
BFAnas pushed a commit to BFAnas/tianshou that referenced this pull request May 5, 2024
…l#352)

- Batch: do not raise error when it finds list of np.array with different shape[0].

- Venv's obs: add try...except block for np.stack(obs_list)

- remove venv.__del__ since it is buggy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants