-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_custom.py
53 lines (42 loc) · 1.66 KB
/
test_custom.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
import gym
import surrol.gym
import time
import numpy as np
def test_environment():
try:
env = gym.make('SutureThreadManagement-v0', render_mode='human')
print(f"Action space: {env.action_space}")
print(f"Observation space: {env.observation_space}")
for episode in range(3):
print(f"\nEpisode {episode + 1}")
obs = env.reset()
episode_reward = 0
for step in range(100):
action = np.zeros(env.action_space.shape[0])
if step < 30:
action[0:3] = np.random.uniform(-0.1, 0.1, 3)
elif step < 60:
action[4] = 1.0
action[9] = 1.0
else:
action[0:3] = np.random.uniform(-0.05, 0.05, 3)
action[5:8] = np.random.uniform(-0.05, 0.05, 3)
obs, reward, done, info = env.step(action)
episode_reward += reward
time.sleep(0.01)
if done:
print(f"Episode finished after {step} steps")
print(f"Thread positions: {obs['achieved_goal']}")
break
print(f"Episode reward: {episode_reward:.2f}")
if 'is_success' in info:
print(f"Success: {info['is_success']}")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
finally:
if 'env' in locals():
env.close()
if __name__ == "__main__":
test_environment()