-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_noconstraints.py
More file actions
30 lines (26 loc) · 942 Bytes
/
test_noconstraints.py
File metadata and controls
30 lines (26 loc) · 942 Bytes
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
#Test if SAC is able to deal with the safety-gym environments when constraints are ignored.
import safety_gym
import gym
from spinup import sac_pytorch #sac_tf1 should work with tensorflow 1, if you prefer to use that instead
import sys
# Train an agent with SAC ignoring cost constraints
def main(alpha=0.2):
print(alpha)
# Create Safety-Gym environment instance
env = gym.make('Safexp-PointGoal1-v0')
env.stepb = env.step
def res_step(action):
if env.done:
env.reset()
return env.stepb(action)
env.step = res_step
#Start training
sac_pytorch(lambda: env,epochs=250,alpha=alpha)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--alpha', type=float, default=0.2)
args = parser.parse_args()
# Save logs to a file
sys.stdout = open("sac"+str(args.alpha).replace(".","_")+".txt", 'w')
main(args.alpha)