-
Notifications
You must be signed in to change notification settings - Fork 92
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
[BC] Add an interactive only mode for env.py #377
Changes from 24 commits
a06d452
15876f7
9bc8c05
86e4d12
27dee69
47f5efc
bf12cee
f5b6b6f
35d9e8c
5d6783d
7997f14
59d3677
6d8c0c7
3b0cefd
78460ce
5b5d67b
6be7186
6342dda
3082ae7
2e26243
56fa72a
463d813
5568aaf
0c20688
ac307fc
07a77ce
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 |
---|---|---|
|
@@ -290,18 +290,22 @@ def _get_scores() -> dict[str, float]: | |
def _get_clang_generator( | ||
clang_path: str, | ||
task_type: Type[MLGOTask], | ||
interactive_only: bool = False, | ||
) -> Generator[Optional[Tuple[ClangProcess, InteractiveClang]], | ||
Optional[corpus.LoadedModuleSpec], None]: | ||
"""Returns a generator for creating InteractiveClang objects. | ||
|
||
TODO: fix this docstring | ||
"""Returns a tuple of generators for creating InteractiveClang objects. | ||
|
||
Args: | ||
clang_path: Path to the clang binary to use within InteractiveClang. | ||
task_type: Type of the MLGO task to use. | ||
interactive_only: If set to true the returned tuple of generators is | ||
iclang, iclang instead of iclang, clang | ||
|
||
Returns: | ||
The generator for InteractiveClang objects. | ||
A tuple of generators created with clang_session. First argument of | ||
the tuple is always an interactive clang session. The second argumnet | ||
is a default clang session if interactive_only is False and otherwise | ||
the exact same interactive clang session object as the first argument. | ||
""" | ||
while True: | ||
# The following line should be type-hinted as follows: | ||
|
@@ -311,9 +315,12 @@ def _get_clang_generator( | |
module = yield | ||
with clang_session( | ||
clang_path, module, task_type, interactive=True) as iclang: | ||
with clang_session( | ||
clang_path, module, task_type, interactive=False) as clang: | ||
yield iclang, clang | ||
if interactive_only: | ||
yield iclang, iclang | ||
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. Could we return iclang here, i.e. not a tuple, and detect that on the receiving end? or (iclang, None)? 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. The relative reward is computed, that is, the compute_relative_rewards function of env.py always expects two scores. I found this to be the cleanest change. Returning only iclang and None will end up being identical but would require multiple changes and I didn't want to break anything. 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. OK - can you update the documentation string explaining this, too? (i.e. it's not quite " |
||
else: | ||
with clang_session( | ||
clang_path, module, task_type, interactive=False) as clang: | ||
yield iclang, clang | ||
|
||
|
||
class MLGOEnvironmentBase: | ||
|
@@ -332,8 +339,10 @@ def __init__( | |
task_type: Type[MLGOTask], | ||
obs_spec, | ||
action_spec, | ||
interactive_only: bool = False, | ||
): | ||
self._clang_generator = _get_clang_generator(clang_path, task_type) | ||
self._clang_generator = _get_clang_generator( | ||
clang_path, task_type, interactive_only=interactive_only) | ||
self._obs_spec = obs_spec | ||
self._action_spec = action_spec | ||
|
||
|
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.
nit: I think the return is a generator of tuples.