Skip to content

Add random sampling to dm_env array specifications - #24

Open
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:masterfrom
sylvesterkaczmarek:feat/14-sample-specifications
Open

sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:masterfrom
sylvesterkaczmarek:feat/14-sample-specifications

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Addresses #14 by adding sample(rng=None) to dm_env array specs for random values consistent with each spec, analogous to sampling Gym spaces. generate_value() remains unchanged and deterministic.

  • Array.sample(): dtype-aware random sampling for boolean, integer (including full uint64 range), floating and complex arrays, at scalar or multidimensional shapes.
  • BoundedArray.sample(): uniformly sample integer bounds inclusively, with scalar or elementwise broadcasting; uniformly sample finite floating bounds, and sample valid values when one or both bounds are infinite.
  • DiscreteArray inherits inclusive integer sampling, producing a valid action index.
  • StringArray.sample() generates short random ASCII str or bytes strings in the declared shape.
  • Accept an optional numpy.random.Generator to make sample sequences reproducible; without one, create a new generator. Reject unsupported nonnumeric plain Array dtypes rather than silently returning invalid values.
  • Document usage, distributions and the existing generate_value() behavior in the API guide.

Verification

  • 185 tests and 17 subtests passed across the entire dm_env test directory, including the new randomized shape, dtype, bound, seeded reproducibility, discrete, empty-shape, string-type and infinity edge cases.
  • Checked Python compilation, focused Ruff lint, Pyink formatting and Git whitespace checks.
  • Tested on Python 3.12 and NumPy 2.5.3, without environment or network requests. Other Python/NumPy combinations have not been validated locally.

This is an additive API; no existing sampling or environment behavior is replaced.

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.

1 participant