compiler_gym.views
The CompilerEnv exposes the
available observation spaces and reward spaces through view
objects. These views provide a flexible interface into lazily computed
values. At any point during the lifetime of an environment, any of the
available observation and reward spaces can be queried through the
observation and
reward attributes,
respectively.
Document contents:
ObservationView
- class compiler_gym.views.ObservationView(raw_step: Callable[[List[ActionType], List[ObservationType], List[float]], Tuple[Optional[Union[ObservationType, List[ObservationType]]], Optional[Union[float, List[float]]], bool, Dict[str, Any]]], spaces: List[ObservationSpace])[source]
 A view into the available observation spaces of a service.
Example usage:
>>> env = gym.make("llvm-v0") >>> env.reset() >>> env.observation.spaces.keys() ["Autophase", "Ir"] >>> env.observation.spaces["Autophase"].space Box(56,) >>> env.observation["Autophase"] [0, 1, ..., 2] >>> observation["Ir"] int main() {...}
- __getitem__(observation_space: str) ObservationType[source]
 Request an observation from the given space.
- Parameters
 observation_space – The observation space to query.
- Returns
 An observation.
- Raises
 KeyError – If the requested observation space does not exist.
SessionNotFound – If
env.reset()has not been called.ServiceError – If the backend service fails to compute the observation, or reports that a terminal state has been reached.
ObservationSpaceSpec
- class compiler_gym.views.ObservationSpaceSpec(id: str, index: int, space: Space, translate: Callable[[Union[ObservationType, Event]], ObservationType], to_string: Callable[[ObservationType], str], deterministic: bool, platform_dependent: bool, default_value: ObservationType)[source]
 Specification of an observation space.
- Variables
 id (str) – The name of the observation space.
index (int) – The index into the list of observation spaces that the service supports.
space (Space) – The space.
deterministic (bool) – Whether the observation space is deterministic.
platform_dependent (bool) – Whether the observation values depend on the execution environment of the service.
default_value – A default observation. This value will be returned by
CompilerEnv.step()ifCompilerEnv.observation_spaceis set and the service terminates.
- make_derived_space(id: str, translate: Callable[[ObservationType], ObservationType], space: Optional[Space] = None, deterministic: Optional[bool] = None, default_value: Optional[ObservationType] = None, platform_dependent: Optional[bool] = None, to_string: Optional[Callable[[ObservationType], str]] = None) ObservationSpaceSpec[source]
 Create a derived observation space.
- Parameters
 id – The name of the derived observation space.
translate – A callback function to compute a derived observation from the base observation.
space – The
gym.Spacedescribing the observation space.deterministic – Whether the observation space is deterministic. If not provided, the value is inherited from the base observation space.
default_value – The default value for the observation space. If not provided, the value is derived from the default value of the base observation space.
platform_dependent – Whether the derived observation space is platform-dependent. If not provided, the value is inherited from the base observation space.
to_string – A callback to convert and observation to a string representation. If not provided, the callback is inherited from the base observation space.
- Returns
 A new ObservationSpaceSpec.
RewardView
- class compiler_gym.views.RewardView(spaces: List[Reward], observation_view: ObservationView)[source]
 A view into a set of reward spaces.
Example usage:
>>> env = gym.make("llvm-v0") >>> env.reset() >>> env.reward.spaces["codesize"].range (-np.inf, 0) >>> env.reward["codesize"] -1243
- __getitem__(reward_space: str) float[source]
 Request an observation from the given space.
- Parameters
 reward_space – The reward space to query.
- Returns
 A reward.
- Raises
 KeyError – If the requested reward space does not exist.
SessionNotFound – If
env.reset()has not been called.
- add_space(space: Reward) None[source]
 Register a new
Rewardspace.- Parameters
 space – The reward space to be added.
- reset(benchmark: Benchmark, observation_view: ObservationView) None[source]
 Reset the rewards space view. This is called on
env.reset().- Parameters
 benchmark – The benchmark that is used for this episode.