Skip to content

fix observation vector issue #324 - #325

Closed
omertarikbanus wants to merge 1 commit into
sail-sg:mainfrom
omertarikbanus:fix-obs-vector
Closed

fix observation vector issue #324#325
omertarikbanus wants to merge 1 commit into
sail-sg:mainfrom
omertarikbanus:fix-obs-vector

Conversation

@omertarikbanus

Copy link
Copy Markdown

Description

This PR fixes an issue where vectorized environments returned identical observations across all environments by explicitly specifying NumPy strides when constructing arrays from EnvPool buffers.

  • In envpool/core/py_envpool.h, replaced the default py::array constructor with one that passes a computed strides vector based on a.Shape() and sizeof(dtype).
  • This ensures the Python view matches the actual memory layout of the underlying buffer and preserves zero-copy behavior.
  • Added an inline comment explaining the stride calculation and rationale.

Key change:

  • From: py::array(a.Shape(), reinterpret_cast<dtype*>(a.Data()), capsule)
  • To: py::array(py::dtype::of(), a.Shape(), strides, reinterpret_cast<dtype*>(a.Data()), capsule)

Motivation and Context

close #324

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • [x ] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • New environment (non-breaking change which adds 3rd-party environment)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of example)

Implemented Tasks

  • Pass explicit strides in py_envpool.h NumPy array construction

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • [x ] I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have reformatted the code using make format (required)
  • I have checked the code using make lint (required)
  • I have ensured make bazel-test pass. (required)

@Trinkle23897
Trinkle23897 requested a review from mavenlin October 17, 2025 16:51
@omertarikbanus
omertarikbanus deleted the fix-obs-vector branch December 6, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]I initialized 8 environments and expected the reset function to return 8 different states, but I found they are exactly the same.

1 participant