I’m working with a personalized gym environment that functions properly during RL model training. The issue is that when I add a custom property to my environment class, I can’t access it from another file.
Here’s my environment setup:
# my_env.py
class MyEnvironment(gym.Env):
"""Custom gym environment implementation"""
def __init__(self, data, **options):
# initialization code
pass
def reset(self):
self.tracking_data = {"score1": 0, "score2": 0}
return self._get_observation()
The tracking_data dictionary stores performance metrics during environment episodes.
In my training file:
# model_training.py
from my_env import MyEnvironment
# model training logic here
results = []
env_data = training_env.get_attr("tracking_data")
results.append(env_data["score1"]) # this line throws an error
I understand that accessing custom attributes requires the get_attr method, but I’m getting TypeError: list indices must be integers or slices, not str when trying to access env_data["score1"]. This suggests get_attr returns a list rather than the expected dictionary.
Should I be using set_attr somewhere in my code? What’s the correct approach to retrieve custom attributes from gym environments?