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

Improve interface of BasePolicy.compute_action #1169

Closed
2 of 9 tasks
opcode81 opened this issue Jul 8, 2024 · 1 comment
Closed
2 of 9 tasks

Improve interface of BasePolicy.compute_action #1169

opcode81 opened this issue Jul 8, 2024 · 1 comment
Assignees
Labels
typing Mainly improving types, no or very few functional changes

Comments

@opcode81
Copy link
Collaborator

opcode81 commented Jul 8, 2024

  • I have marked all applicable categories:
    • exception-raising bug
    • RL algorithm bug
    • documentation request (i.e. "X is missing from the documentation.")
    • new feature request
    • design request (i.e. "X should be changed to Y.")
  • I have visited the source website
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and environment, where applicable:
    import tianshou, gymnasium as gym, torch, numpy, sys
    print(tianshou.__version__, gym.__version__, torch.__version__, numpy.__version__, sys.version, sys.platform)

The interface is not optimal, because not all observations are indeed arrays. Observations can also be array-like only (numpy's ArrayLike type). In fact, this is the case for some of gymnasium's standard implementations (e.g. LazyFrames).

I am not sure how appropriate the current type annotation is (i.e. arr_type, which also includes Tensor).

Proposal:

  • Change type annotation of obs to numpy's ArrayLike
  • Add first line which ensures array representation: obs = np.array(obs). This will convert anything array-like to an actual array (e.g. using an implementation of __array__ if necessary).
opcode81 added a commit that referenced this issue Jul 8, 2024
opcode81 added a commit that referenced this issue Jul 8, 2024
@MischaPanch MischaPanch added the typing Mainly improving types, no or very few functional changes label Jul 18, 2024
@MischaPanch
Copy link
Collaborator

Closed by #1170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Mainly improving types, no or very few functional changes
Projects
None yet
Development

No branches or pull requests

2 participants