-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_agent.py
62 lines (51 loc) · 1.81 KB
/
no_agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
from EnvironmentWrapper import CustomEnvWrapper
from helper import smooth
import wandb
import tqdm
# Set up wandb
project_name = "sharpening-ao-system-easy" # needs to change for each experiment
# options: sharpening-ao-system, sharpening-ao-system-easy, centering-ao-system, darkhole-ao-system
config = {
"env_name": "Sharpening_AO_system_easy", # needs to change for each experiment corresponding to project_name
# options: Sharpening_AO_system, Sharpening_AO_system_easy, Centering_AO_system, Darkhole_AO_system
}
api = wandb.Api()
def get_run_num(runs, group_name):
run_num = 0
for run in runs:
if group_name in run.name:
run_num += 1
return run_num
print("Testing the environment with no agent")
# run the environment with no actions
env = CustomEnvWrapper(name=config["env_name"])
group_name = f"no_agent-{env.env.wf_rms}rms-{env.action_space.shape[0]}act"
run_num = get_run_num(api.runs("adapt_opt/sharpening-ao-system-easy"), group_name)
n_runs = 3
n_steps = 200000
for run in range(n_runs):
print(f"Run {run+1}/{n_runs}")
run = wandb.init(
group=group_name,
name=f"{group_name}-{run_num}",
project=project_name,
entity="adapt_opt",
config=config,
sync_tensorboard=True
)
env.reset()
rewards = []
for _ in tqdm.tqdm(range(n_steps)):
action = np.zeros(env.action_space.shape)
observation, reward, done, info = env.step(action)
rewards.append(reward)
wandb.log({"reward": reward})
env.close()
wandb.finish()
run_num += 1
# get the average reward and the standard deviation
rewards = np.array(rewards)
print("Average reward: ", np.mean(rewards))
print("Standard deviation: ", np.std(rewards))
print("Min/Max reward: ", np.min(rewards), "/", np.max(rewards))