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

Add vector.HumanRendering wrapper #880

Closed
wants to merge 1 commit into from

Conversation

RogerJL
Copy link
Contributor

@RogerJL RogerJL commented Jan 13, 2024

Corrected code to pass tests, and tests to test code! Also corrected some bugs in vectorized Cartpole
Doctest: fixed comments
Documentation was missing for vector.HumanRendering
Relax 'render_mode' further, does not need to be correct until actual rendering starts (i.e. env.reset() is called)

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #872
Fixes #873
Related to #233

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Screenshots

Before After
N/A HumanVectorRender

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

…arama-Foundation#872, Farama-Foundation#233)

Corrected code to pass tests, and tests to test code!
Also corrected some bugs in vectorized Cartpole
Doctest: fixed comments
Documentation was missing for vector.HumanRendering
Relax 'render_mode' further, does not need to be correct
until actual rendering starts (i.e. env.reset() is called)
@RogerJL
Copy link
Contributor Author

RogerJL commented Jan 16, 2024

@pseudo-rnd-thoughts @Kallinteris-Andreas please please review

@RogerJL
Copy link
Contributor Author

RogerJL commented Jan 25, 2024

@pseudo-rnd-thoughts @Kallinteris-Andreas
Why do you let commits rot?
Two weeks and counting. Will this even apply cleanly now?

@@ -510,7 +510,7 @@ def render(self):
for _ in range(self.num_envs)
]
if self.clocks is None:
self.clock = [pygame.time.Clock() for _ in range(self.num_envs)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is cartpole.py being changed on a PR about adding a new wrapper? Shouldn't this be a separate PR?

Copy link
Contributor Author

@RogerJL RogerJL Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to, as cartpole.py had bugs making it impossible to add tests of vector rendering (and it was used in testing of the existing regular rendering)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make a separate PR with just those fixes, where it can be reviewed alone, (then after merging you can rebase this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is acceptable to do it without creating related tests, and let the tests arrive with the rendering commit.
I changed the tests and added quite a number of tests for both HumanRenderer.
(but in that case the CartPole commit will be so small that it is easy to review)

Note: the changed method in CartPoleVectorEnv is render() [and it can not have ever worked] so it is not unrelated to this commit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testing of VecCartPole's rgb_array render_mode, should be independent of human rendering testing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the name of the folder base_

Copy link
Contributor Author

@RogerJL RogerJL Jan 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is internal routines moved from both HumanRendering and the new vector.HumanRendering
should not be used directly (and _base was not possible to use at it gave errors)

As these routines are used in both HumanRendering and vector.HumanRendering they cannot be placed in HumanRendering - creates a circular dependency, could be placed in vector.HumanRendering but it would be strange for regular HumanRendering calling it - thus 'base_'

from gymnasium.error import DependencyNotInstalled


ALL_ACCEPTABLE_RENDER_MODES = ["rgb_array", "rgb_array_list"]
Copy link
Collaborator

@Kallinteris-Andreas Kallinteris-Andreas Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also support "depth_array" (edit: perhaps a separate PR)

Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I have taken so long to review this PR
As this implementation is for vector.HumanRendering, could you only modify the code related to the vector version (unless there is necessary changes for testing)

It seems to add complexity with the base_.rendering code, could you remove this for the wrappers.rendering and wrappers.vector.rendering
I understand this removes duplicated code but this breaks the project conventions

for state, screen, clock in zip(self.state, self.screens, self.clocks):
x = self.state.T

for state, screen, clock, x in zip(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will fail for num_envs>4 as zip uses the shortest iterate and self.state has shape (N, 4) so self.state.T is (4, N).
Could you confirm if this does is work for num_envs>4?

@pseudo-rnd-thoughts pseudo-rnd-thoughts changed the title HumanVectorRendering: based on VectorWrapper (#873, #872, #233) Add vector.HumanRendering wrapper Feb 28, 2024
@pseudo-rnd-thoughts
Copy link
Member

Closing in favor of #1013

@RogerJL RogerJL deleted the HumanRenderingPR6 branch June 10, 2024 16:01
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