-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(rjy): add discrete pendulum env #395
Conversation
@@ -11,7 +11,7 @@ | |||
@ENV_REGISTRY.register('pendulum') | |||
class PendulumEnv(BaseEnv): | |||
|
|||
def __init__(self, cfg: dict) -> None: | |||
def __init__(self, cfg: dict, is_continue=True) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use is_xxx
or use_xxx
, just continuous
is ok
if self._act_scale: | ||
action = affine_transform(action, min_val=self._env.action_space.low, max_val=self._env.action_space.high) | ||
obs, rew, done, info = self._env.step(action) | ||
self._final_eval_reward += rew | ||
obs = to_ndarray(obs).astype(np.float32) | ||
rew = to_ndarray([rew]).astype(np.float32) # wrapped to be transfered to a array with shape (1,) | ||
# rew = to_ndarray([rew]).astype(np.float32) # wrapped to be transfered to a array with shape (1,) | ||
rew = np.array([rew], dtype=np.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use this implementation, it has no difference with original version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I ran into such a problem when testing: AttributeError: 'list' object has no attribute 'shape'
. So I'm guessing if it's the problem here, and later I find out that it's the problem with the parameters passed in earlier.
@@ -24,6 +24,9 @@ def __init__(self, cfg: dict) -> None: | |||
self._reward_space = gym.spaces.Box( | |||
low=-1 * (3.14 * 3.14 + 0.1 * 8 * 8 + 0.001 * 2 * 2), high=0.0, shape=(1, ), dtype=np.float32 | |||
) | |||
# require discrete env | |||
self._is_continue=is_continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should modify self._action_space
when continuous=False
, so you can use consistent interface in other parts like random_action
method
@@ -58,12 +61,17 @@ def seed(self, seed: int, dynamic_seed: bool = True) -> None: | |||
|
|||
def step(self, action: np.ndarray) -> BaseEnvTimestep: | |||
assert isinstance(action, np.ndarray), type(action) | |||
# if require discrete env, convert actions to [-2 ~ 2] float actions | |||
if not self._is_continue: | |||
action=(action-(self._discrete_action_num-1)/2)/((self._discrete_action_num-1)/4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to transform it to [-1, 1] here, then affine_transform
will make it to [-2, 2]
@@ -58,12 +61,17 @@ def seed(self, seed: int, dynamic_seed: bool = True) -> None: | |||
|
|||
def step(self, action: np.ndarray) -> BaseEnvTimestep: | |||
assert isinstance(action, np.ndarray), type(action) | |||
# if require discrete env, convert actions to [-2 ~ 2] float actions | |||
if not self._is_continue: | |||
action=(action-(self._discrete_action_num-1)/2)/((self._discrete_action_num-1)/4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just (action / (self._discrete_action_num-1)) * 2 - 1
Codecov Report
@@ Coverage Diff @@
## main #395 +/- ##
==========================================
+ Coverage 85.61% 85.74% +0.13%
==========================================
Files 524 524
Lines 41108 41499 +391
==========================================
+ Hits 35195 35584 +389
- Misses 5913 5915 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Description
Related Issue
TODO
Check List