MCPcopy Create free account
hub / github.com/MINT-SJTU/Evo-RL / test_basic_functionality

Function test_basic_functionality

tests/processor/test_device_processor.py:27–50  ·  view source on GitHub ↗

Test basic device processor functionality on CPU.

()

Source from the content-addressed store, hash-verified

25
26
27def test_basic_functionality():
28 """Test basic device processor functionality on CPU."""
29 processor = DeviceProcessorStep(device="cpu")
30
31 # Create a transition with CPU tensors
32 observation = {OBS_STATE: torch.randn(10), OBS_IMAGE: torch.randn(3, 224, 224)}
33 action = torch.randn(5)
34 reward = torch.tensor(1.0)
35 done = torch.tensor(False)
36 truncated = torch.tensor(False)
37
38 transition = create_transition(
39 observation=observation, action=action, reward=reward, done=done, truncated=truncated
40 )
41
42 result = processor(transition)
43
44 # Check that all tensors are on CPU
45 assert result[TransitionKey.OBSERVATION][OBS_STATE].device.type == "cpu"
46 assert result[TransitionKey.OBSERVATION][OBS_IMAGE].device.type == "cpu"
47 assert result[TransitionKey.ACTION].device.type == "cpu"
48 assert result[TransitionKey.REWARD].device.type == "cpu"
49 assert result[TransitionKey.DONE].device.type == "cpu"
50 assert result[TransitionKey.TRUNCATED].device.type == "cpu"
51
52
53@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available")

Callers

nothing calls this directly

Calls 2

DeviceProcessorStepClass · 0.90
create_transitionFunction · 0.90

Tested by

no test coverage detected