<jupyter_start><jupyter_text>Create environment<jupyter_code>env_name = "CartPole-v0"
env = gym.make(env_name)
env.seed(0)

state_size =  env.observation_space.shape[0]
action_size = env.action_space.n

print("State size:", state_size, "\nAction size:", action_size)<jupyter_output>State size: 4 
Action size: 2<jupyter_text>A2C Test<jupyter_code>env_name = "CartPole-v0"
env = gym.make(env_name)
env.seed(0)
state_size =  env.observation_space.shape[0]
action_size = env.action_space.n

tmax = 5
n_episodes = (20_000)//tmax
n_env = 16
a2c_model = models.ActorCriticMLP(state_size, action_size, env.action_space, H=256)
# init agent:
agent = A2C(a2c_model,
            env_name,
            n_env=n_env,
            use_gae=False
            )

max_score = 195.
model_name = "a2c_{}".format(env_name)
# train the agent
scores, losses = agent.train(tmax, n_episodes,  env, max_score, model_name)

# plot the training:
x = np.arange(len(scores))
scores = mean_filter(scores, 50)
plt.plot(x, scores, label = "scores")
plt.show()
env.close()<jupyter_output>../torch/csrc/utils/python_arg_parser.cpp:698: UserWarning: This overload of add_ is deprecated:
	add_(Number alpha, Tensor other)
Consider using one of the following signatures instead:
	add_(Tensor other, Number alpha)<jupyter_text>Trained Agent Demonstration<jupyter_code>agent.test(env, render=True, n_episodes=4)<jupyter_output><empty_output><jupyter_text>A2C Continuous Test<jupyter_code>env_name = "Pendulum-v0"
env = gym.make(env_name)
env.seed(0)
state_size =  env.observation_space.shape[0]
action_size = env.action_space.shape[0]

tmax = 5
n_episodes = 1000
n_env = 16
a2c_model = models.ActorCriticMLP(state_size, action_size, env.action_space, H=64)
lr = 1e-3
# init agent:
agent = A2C(a2c_model,
            env_name,
            n_env=n_env,
            lr=lr,
            critic_coef=0.1,
            )

max_score = -20.
model_name = "a2c_{}".format(env_name)
# train the agent
scores, losses = agent.train(tmax, n_episodes,  env, max_score, model_name, det_test=True)

# plot the training:
x = np.arange(len(scores))
scores = mean_filter(scores, 50)
plt.plot(x, scores, label = "scores")
plt.show()
env.close()<jupyter_output><empty_output><jupyter_text>Trained Agent Demonstration<jupyter_code>agent.test(env, render=True, n_episodes=4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12494651262302096, 'fraction_numerical': 0.025673940949935817, 'mean_word_length': 5.025773195876289, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '539521', 'license': 'MIT', 'n_tokens_mistral': 974, 'n_tokens_neox': 917, 'n_words': 167, 'path': 'tests/a2c_test.ipynb', 'repo_name': 'selim-karaduman/pytorch-drl-algs', 'size': '2337'}