forked from StanfordVL/OmniGibson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dump_load_states.py
79 lines (58 loc) · 2.58 KB
/
test_dump_load_states.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pytest
from utils import SYSTEM_EXAMPLES, og_test
import omnigibson as og
from omnigibson.object_states import Covered
from omnigibson.systems import *
@og_test
def test_dump_load(env):
breakfast_table = env.scene.object_registry("name", "breakfast_table")
for system_name, system_class in SYSTEM_EXAMPLES.items():
system = env.scene.get_system(system_name)
assert isinstance(system, system_class)
if issubclass(system_class, VisualParticleSystem):
assert breakfast_table.states[Covered].set_value(system, True)
else:
system.generate_particles(positions=th.tensor([[0, 0, 1]]))
assert system.n_particles > 0
system.remove_all_particles()
state = og.sim.dump_state()
og.sim.load_state(state)
for system_name, system_class in SYSTEM_EXAMPLES.items():
env.scene.clear_system(system_name)
@og_test
def test_dump_load_serialized(env):
breakfast_table = env.scene.object_registry("name", "breakfast_table")
for system_name, system_class in SYSTEM_EXAMPLES.items():
system = env.scene.get_system(system_name)
assert isinstance(system, system_class)
if issubclass(system_class, VisualParticleSystem):
assert breakfast_table.states[Covered].set_value(system, True)
else:
system.generate_particles(positions=th.tensor([[0, 0, 1]]))
assert system.n_particles > 0
state = og.sim.dump_state(serialized=True)
og.sim.load_state(state, serialized=True)
for system_name, system_class in SYSTEM_EXAMPLES.items():
env.scene.clear_system(system_name)
@og_test
def test_save_restore_partial(env):
breakfast_table = env.scene.object_registry("name", "breakfast_table")
decrypted_fd, tmp_json_path = tempfile.mkstemp("test_save_restore.json", dir=og.tempdir)
og.sim.save([tmp_json_path])
# Delete the breakfast table
env.scene.remove_object(breakfast_table)
og.sim.step()
# Restore the saved environment
og.sim.restore([tmp_json_path])
# Make sure we still have an object that existed beforehand
assert og.sim.scenes[0].object_registry("name", "breakfast_table") is not None
@og_test
def test_save_restore_full(env):
decrypted_fd, tmp_json_path = tempfile.mkstemp("test_save_restore.json", dir=og.tempdir)
og.sim.save([tmp_json_path])
# Clear the simulator
og.clear()
# Restore the saved environment
og.sim.restore([tmp_json_path])
# Make sure we still have an object that existed beforehand
assert og.sim.scenes[0].object_registry("name", "breakfast_table") is not None