Skip to content

Commit

Permalink
Deprecate the add_derived_space() API.
Browse files Browse the repository at this point in the history
Issue #461.
  • Loading branch information
ChrisCummins committed Nov 8, 2021
1 parent 619b06f commit 76584b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 9 additions & 0 deletions compiler_gym/views/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# LICENSE file in the root directory of this source tree.
from typing import Callable, Dict, List

from deprecated.sphinx import deprecated

from compiler_gym.service.connection import ServiceError
from compiler_gym.service.proto import ObservationSpace
from compiler_gym.util.gym_type_hints import (
Expand Down Expand Up @@ -93,6 +95,13 @@ def _add_space(self, space: ObservationSpaceSpec):
# env.observation.FooBar().
setattr(self, space.id, lambda: self[space.id])

@deprecated(
version="0.2.1",
reason=(
"Use the derived_observation_spaces argument to CompilerEnv constructor. "
"See <https://github.com/facebookresearch/CompilerGym/issues/461>."
),
)
def add_derived_space(
self,
id: str,
Expand Down
15 changes: 9 additions & 6 deletions tests/llvm/observation_spaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,12 +1379,15 @@ def test_is_buildable_observation_space_not_buildable(env: LlvmEnv):

def test_add_derived_space(env: LlvmEnv):
env.reset()
env.observation.add_derived_space(
id="IrLen",
base_id="Ir",
space=Box(name="IrLen", low=0, high=float("inf"), shape=(1,), dtype=int),
translate=lambda base: [15],
)
with pytest.deprecated_call(
match="Use the derived_observation_spaces argument to CompilerEnv constructor."
):
env.observation.add_derived_space(
id="IrLen",
base_id="Ir",
space=Box(name="IrLen", low=0, high=float("inf"), shape=(1,), dtype=int),
translate=lambda base: [15],
)

value = env.observation["IrLen"]
assert isinstance(value, list)
Expand Down

0 comments on commit 76584b3

Please sign in to comment.