-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
55 lines (38 loc) · 1.39 KB
/
conftest.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
from __future__ import annotations
from typing import NamedTuple
import pytest
import jax
from jaxtyping import PRNGKeyArray
import jit_env
from jit_env import specs
class DummyState(NamedTuple):
key: PRNGKeyArray
class DummyEnv(jit_env.Environment):
def __init__(self):
super().__init__(renderer=lambda *_: jax.numpy.ones(()))
def reset(
self,
key: PRNGKeyArray,
*,
options: jit_env.EnvOptions = None
) -> tuple[DummyState, jit_env.TimeStep]:
return DummyState(key=key), jit_env.restart(jax.numpy.zeros(()))
def step(
self,
state: DummyState,
action: jit_env.Action
) -> tuple[DummyState, jit_env.TimeStep]:
if action is None:
return state, jit_env.termination(*jax.numpy.ones((2,)))
return state, jit_env.transition(*jax.numpy.ones((3,)))
def reward_spec(self) -> specs.Spec:
return specs.BoundedArray((), float, 0.0, 1.0, 'reward')
def discount_spec(self) -> specs.Spec:
return specs.BoundedArray((), float, 0.0, 1.0, 'discount')
def observation_spec(self) -> specs.Spec:
return specs.Array((), float, 'observation')
def action_spec(self) -> specs.Spec:
return specs.Array((), float, 'action')
@pytest.fixture
def dummy_env():
return DummyEnv()