-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Required prerequisites
- I have read the documentation https://safety-gymnasium.readthedocs.io.
- I have searched the Issue Tracker and Discussions that this hasn't already been reported. (+1 or comment there if it has.)
- Consider asking first in a Discussion.
What version of Safety-Gymnasium are you using?
1.0.0
System information
$ python -c """import sys, safety_gymnasium
print(sys.version, sys.platform)
print(safety_gymnasium.version)"""
3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0] linux
1.0.0
Problem description
When I am printing observation:
import safety_gymnasium
env = safety_gymnasium.vector.make("SafetyCarGoal0-v0", render_mode="human", num_envs=1)
observation, info = env.reset(seed=0)
for _ in range(1000):
action = env.action_space.sample() # this is where you would insert your policy
observation, reward, cost, terminated, truncated, info = env.step(action)
print(observation)
if any(terminated) or any(truncated):
observation, info = env.reset()
env.close()
The observation comes as a: 40 dimensional vector as opposed to what is stated in documentation:
After running few other environments i have come to a hypothesis that the observation of navigation stack matches that of concatenated observation dictionary from Safe Vision except the 'vision' key (i.e. the image)
How did I conclude this, I ran the following code:
`import safety_gymnasium
import cv2
import numpy as np
import time
env = safety_gymnasium.make('SafetyCarGoal0Vision-v0')
obs, info = env.reset()
window_name = 'Vision Observation (OpenCV Feed)'
print(f"Starting live visualization (Close the '{window_name}' window to stop)...")
for i in range(1000): # Run for 100 steps
act = env.action_space.sample()
obs, reward, cost, terminated, truncated, info = env.step(act)
total_obs_count = 0
# Iterate through every key-value pair in the observation dictionary
for key, value in obs.items():
if key == 'vision':
pass
else:
# Check if the value is a NumPy array (which all numerical obs should be)
if isinstance(value, np.ndarray):
# Add the total number of elements in the array to the count
total_obs_count += value.size
# For non-array values (e.g., a single float/int if present):
elif isinstance(value, (int, float)):
total_obs_count += 1
# Handle dicts of observations if they existed, but Safety Gym usually returns
# a flat dict of arrays, so the above should cover it.
print(f"--- Step {i} ---")
print(f"Total Observation Count (Total number of numerical values except vision): {total_obs_count}")
if terminated or truncated:
obs, info = env.reset()
`
Reproducible example code
The Python snippets:
import safety_gymnasium
env = safety_gymnasium.vector.make("SafetyCarGoal0-v0", render_mode="human", num_envs=1)
observation, info = env.reset(seed=0)
for _ in range(1000):
action = env.action_space.sample() # this is where you would insert your policy
observation, reward, cost, terminated, truncated, info = env.step(action)
print(observation)
if any(terminated) or any(truncated):
observation, info = env.reset()
env.close()
import safety_gymnasium
import cv2
import numpy as np
import time
env = safety_gymnasium.make('SafetyCarGoal0Vision-v0')
obs, info = env.reset()
window_name = 'Vision Observation (OpenCV Feed)'
print(f"Starting live visualization (Close the '{window_name}' window to stop)...")
for i in range(1000): # Run for 100 steps
act = env.action_space.sample()
obs, reward, cost, terminated, truncated, info = env.step(act)
total_obs_count = 0
# Iterate through every key-value pair in the observation dictionary
for key, value in obs.items():
if key == 'vision':
pass
else:
# Check if the value is a NumPy array (which all numerical obs should be)
if isinstance(value, np.ndarray):
# Add the total number of elements in the array to the count
total_obs_count += value.size
# For non-array values (e.g., a single float/int if present):
elif isinstance(value, (int, float)):
total_obs_count += 1
# Handle dicts of observations if they existed, but Safety Gym usually returns
# a flat dict of arrays, so the above should cover it.
print(f"--- Step {i} ---")
print(f"Total Observation Count (Total number of numerical values except vision): {total_obs_count}")
if terminated or truncated:
obs, info = env.reset()Command lines:
Extra dependencies:
Steps to reproduce:
Traceback
Expected behavior
No response
Additional context
No response