I wonder if it is possible to change the init value of Environment class declared as actor in MainEnvironment.py in main.py.
What I want is to modify the code in main.py to change self.num_steps in Trainer.py.
#Trainer.py
class TrainerParams:
def __init__(self):
self.num_steps = 1e5
class Trainer:
def __init__(self, params: TrainerParams):
self.params = params
#MainEnvironment.py
from Environment import BaseEnvironment, BaseEnvironmentParams
from Trainer import TrainerParams, Trainer
class EnvironmentParams(BaseEnvironmentParams):
def __init__(self):
super().__init__()
self.trainer_params = TrainerParams()
@ray.remote
class Environment(BaseEnvironment):
def __init__(self, params: EnvironmentParams):
super().__init__(params)
self.trainer = Trainer(params.trainer_params)
If I can not consider ray, the code can be written as below.
#main.py
from MainEnvironment import Environment
env = Environment(params)
env.trainer.params.num_steps *= 0.4
But I have to consider ray.
#main.py
import ray
from MainEnvironment import Environment
ray.init()
env = [Environment.remote(params) for i in range(2)]
ray.actor.exit_actor()
for i in range(2):
env[i].trainer.params.num_steps *= 0.4
I guess I need to access the init value after terminating ray.init().
But it doesn’t work. I also suspect that accessing the actor without .remote()
is one cause of the error, but I can’t find a solution.