def main(args): """Run experiment.""" set_random_seed(args.seed) env_config = parse_config_file(args.env_config_file) environment = GymEnvironment( env_config["name"], ctrl_cost_weight=env_config["action_cost"], seed=args.seed ) reward_model = environment.env.reward_model() if args.exploration == "optimistic": dynamical_model = HallucinatedModel.default(environment, beta=args.beta) environment.add_wrapper(HallucinationWrapper) else: dynamical_model = TransformedModel.default(environment) kwargs = parse_config_file(args.agent_config_file) agent = getattr( importlib.import_module("rllib.agent"), f"{args.agent}Agent" ).default( environment=environment, dynamical_model=dynamical_model, reward_model=reward_model, thompson_sampling=args.exploration == "thompson", **kwargs, ) train_agent( agent=agent, environment=environment, max_steps=env_config["max_steps"], num_episodes=args.train_episodes, render=args.render, print_frequency=1, ) evaluate_agent( agent=agent, environment=environment, max_steps=env_config["max_steps"], num_episodes=args.test_episodes, )
"""Python Script Template.""" from rllib.environment import GymEnvironment from rllib.util.utilities import set_random_seed from qreps.environment.random_action_wrapper import RandomActionWrapper import os from exps.utilities import parse_arguments, run_experiment from exps.environments.utilities import get_saddle_agents, get_benchmark_agents args = parse_arguments() args.env_name = "RiverSwim-v0" args.lr = 0.01 args.eta = 5.0 set_random_seed(args.seed) env = GymEnvironment(args.env_name, seed=args.seed) env.add_wrapper(RandomActionWrapper, p=args.random_action_p) agents = get_saddle_agents(env, **vars(args)) agents.update(get_benchmark_agents(env, **vars(args))) df = run_experiment(agents, env, args) df.to_pickle(f"river_swim_results_{args.seed}.pkl") os.system("python river_swim_plot.py")