|
a |
|
b/tests/test.restore.py |
|
|
1 |
from osim.env import ProstheticsEnv |
|
|
2 |
import numpy as np |
|
|
3 |
import unittest |
|
|
4 |
|
|
|
5 |
class SetStateTest(unittest.TestCase): |
|
|
6 |
def test_activations(self): |
|
|
7 |
env = ProstheticsEnv(visualize=False, integrator_accuracy=1e-1) # we quickly want to see what happens |
|
|
8 |
env.reset() |
|
|
9 |
state_checkpoint = env.osim_model.get_state() # store state |
|
|
10 |
|
|
|
11 |
for i in range(5): |
|
|
12 |
env.step(env.action_space.high) # execute step with static action |
|
|
13 |
obs1 = env.get_observation() |
|
|
14 |
|
|
|
15 |
env.osim_model.set_state(state_checkpoint) # restore state |
|
|
16 |
for i in range(5): |
|
|
17 |
env.step(env.action_space.high) |
|
|
18 |
obs2 = env.get_observation() |
|
|
19 |
|
|
|
20 |
dist = np.sum((np.array(obs1) - np.array(obs2))**2) |
|
|
21 |
self.assertTrue(dist < 0.05) |
|
|
22 |
|
|
|
23 |
if __name__ == '__main__': |
|
|
24 |
unittest.main() |