Runtime Gym Space Validation

Data Pipelines, Monitoring & Reliability DS practice problem on Onlearn.

Difficulty: easy.

Topics: Runtime Gym Space Validation, Schema Enforcement, Unit Test Coverage, Container Memory Limits, Outlier Detection, Log Aggregation, Data Engineering, Software Testing, Distributed Systems, Statistical Analysis, System Observability, Data Validation Pipelines, Integration Testing Frameworks, Resource Orchestration, Anomaly Detection, Telemetry Instrumentation.

In reinforcement learning, environments define spaces that describe the valid structure of observations and actions. At runtime, it is important to verify that data produced by agents or environments actually conforms to the expected space specification. Implement a function validate space that takes a space definition (as a dictionary) and a list of candidate samples, and returns a list of booleans indicating whether each sample is valid for the given space. The space dictionary always contains a type key. The supported space types and their additional keys are: Discrete: has key n (int). Valid samples are integers in the range [0, n). Box: has keys low (list of floats), high (list of floats), and shape (list of ints). Valid samples are numeric arrays whose shape matches the specified shape and whose elements all lie within the inclusive bounds [low, high]. MultiBinary: has key n (int). Valid samples are arrays of length n where every element is either 0 or 1. MultiDiscrete: has key nvec (list of ints). Valid samples are arrays with the same length as nvec where the element at position i satisfies 0 <= element < nvec[i]. For Discrete spaces, non integer types (e.g., floats, booleans) should be rejected. For array based spaces, samples with incorrect shapes should be rejected. Return a list of Python booleans, one per sample.