chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
from ray.rllib.algorithms.ppo import PPOConfig
|
||||
from ray.rllib.connectors.env_to_module import MeanStdFilter
|
||||
from ray.rllib.core.rl_module.default_model_config import DefaultModelConfig
|
||||
from ray.rllib.examples.envs.classes.multi_agent import MultiAgentPendulum
|
||||
from ray.rllib.examples.utils import (
|
||||
add_rllib_example_script_args,
|
||||
run_rllib_example_script_experiment,
|
||||
)
|
||||
from ray.rllib.utils.metrics import (
|
||||
ENV_RUNNER_RESULTS,
|
||||
EPISODE_RETURN_MEAN,
|
||||
NUM_ENV_STEPS_SAMPLED_LIFETIME,
|
||||
)
|
||||
from ray.tune.registry import register_env
|
||||
|
||||
parser = add_rllib_example_script_args(default_timesteps=500000)
|
||||
parser.set_defaults(
|
||||
num_agents=2,
|
||||
)
|
||||
# Use `parser` to add your own custom command line options to this script
|
||||
# and (if needed) use their values to set up `config` below.
|
||||
args = parser.parse_args()
|
||||
|
||||
register_env("multi_agent_pendulum", lambda cfg: MultiAgentPendulum(config=cfg))
|
||||
|
||||
config = (
|
||||
PPOConfig()
|
||||
.environment("multi_agent_pendulum", env_config={"num_agents": args.num_agents})
|
||||
.env_runners(
|
||||
env_to_module_connector=lambda env, spaces, device: MeanStdFilter(
|
||||
multi_agent=True
|
||||
),
|
||||
)
|
||||
.training(
|
||||
train_batch_size_per_learner=1024,
|
||||
minibatch_size=128,
|
||||
lr=0.0002 * (args.num_learners or 1) ** 0.5,
|
||||
gamma=0.95,
|
||||
lambda_=0.5,
|
||||
)
|
||||
.rl_module(
|
||||
model_config=DefaultModelConfig(fcnet_activation="relu"),
|
||||
)
|
||||
.multi_agent(
|
||||
policy_mapping_fn=lambda aid, *arg, **kw: f"p{aid}",
|
||||
policies={f"p{i}" for i in range(args.num_agents)},
|
||||
)
|
||||
)
|
||||
|
||||
stop = {
|
||||
NUM_ENV_STEPS_SAMPLED_LIFETIME: args.stop_timesteps,
|
||||
# Divide by num_agents to get actual return per agent.
|
||||
f"{ENV_RUNNER_RESULTS}/{EPISODE_RETURN_MEAN}": -300.0 * (args.num_agents or 1),
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_rllib_example_script_experiment(config, args, stop=stop)
|
||||
Reference in New Issue
Block a user