-
Notifications
You must be signed in to change notification settings - Fork 130
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
Fix to issue #648 #739
Fix to issue #648 #739
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||||||
# | ||||||||
# This source code is licensed under the MIT license found in the | ||||||||
# LICENSE file in the root directory of this source tree. | ||||||||
from typing import Optional | ||||||||
from typing import Iterable, Optional | ||||||||
|
||||||||
from compiler_gym.envs import CompilerEnv | ||||||||
from compiler_gym.util.gym_type_hints import ActionType | ||||||||
|
@@ -32,12 +32,23 @@ def __init__(self, env: CompilerEnv, max_episode_steps: Optional[int] = None): | |||||||
self._max_episode_steps = max_episode_steps | ||||||||
self._elapsed_steps = None | ||||||||
|
||||||||
def step(self, action: ActionType, **kwargs): | ||||||||
# def step(self, action: ActionType, **kwargs): | ||||||||
# assert ( | ||||||||
# self._elapsed_steps is not None | ||||||||
# ), "Cannot call env.step() before calling reset()" | ||||||||
# observation, reward, done, info = self.env.step(action, **kwargs) | ||||||||
# self._elapsed_steps += 1 | ||||||||
# if self._elapsed_steps >= self._max_episode_steps: | ||||||||
# info["TimeLimit.truncated"] = not done | ||||||||
# done = True | ||||||||
# return observation, reward, done, info | ||||||||
|
||||||||
def multistep(self, actions: Iterable[ActionType], **kwargs): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I would suggest forcing the conversion of actions to a list here, since there could be a subtle bug if actions is an iterator, as it would break the |
||||||||
assert ( | ||||||||
self._elapsed_steps is not None | ||||||||
), "Cannot call env.step() before calling reset()" | ||||||||
observation, reward, done, info = self.env.step(action, **kwargs) | ||||||||
self._elapsed_steps += 1 | ||||||||
observation, reward, done, info = self.env.multistep(actions, **kwargs) | ||||||||
self._elapsed_steps += len(actions) | ||||||||
if self._elapsed_steps >= self._max_episode_steps: | ||||||||
info["TimeLimit.truncated"] = not done | ||||||||
done = True | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||||
# LICENSE file in the root directory of this source tree. | ||||||||
"""Unit tests for //compiler_gym/wrappers.""" | ||||||||
from compiler_gym.envs.llvm import LlvmEnv | ||||||||
from compiler_gym.wrappers import TimeLimit | ||||||||
from compiler_gym.wrappers import CycleOverBenchmarks, TimeLimit | ||||||||
from tests.test_main import main | ||||||||
|
||||||||
pytest_plugins = ["tests.pytest_plugins.llvm"] | ||||||||
|
@@ -81,5 +81,21 @@ def test_time_limit_fork(env: LlvmEnv): | |||||||
fkd.close() | ||||||||
|
||||||||
|
||||||||
# @pytest.mark.xfail(strict=True, reason="https://github.com/facebookresearch/CompilerGym/issues/648") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't commit commented out code |
||||||||
def test_time_limit(env: LlvmEnv): | ||||||||
"""Check CycleOverBenchmarks does not break TimeLimit""" | ||||||||
env = TimeLimit(env, max_episode_steps=1) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest testing with |
||||||||
env = CycleOverBenchmarks( | ||||||||
env, | ||||||||
benchmarks=[ | ||||||||
"benchmark://cbench-v1/crc32", | ||||||||
], | ||||||||
) | ||||||||
env.reset() | ||||||||
_, _, done, _ = env.step(0) | ||||||||
|
||||||||
assert done | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Best to also test the reason why |
||||||||
|
||||||||
|
||||||||
if __name__ == "__main__": | ||||||||
main() |
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 can delete these lines. Don't submit commented-out code