Skip to content
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

Split CompilerEnv.step() into two methods for singular or lists of actions (take 2) #627

Merged
merged 8 commits into from
Mar 17, 2022

Conversation

sogartar
Copy link

This MR supersedes #611. It is the same thing except the source branch is different.

@sogartar sogartar force-pushed the feature/deprecate-action-list branch from d0d464a to 6acd592 Compare March 16, 2022 15:06
@sogartar sogartar changed the title Split CompilerEnv.step() into two methods for singular or lists of actions Split CompilerEnv.step() into two methods for singular or lists of actions 2 Mar 16, 2022
@sogartar sogartar changed the title Split CompilerEnv.step() into two methods for singular or lists of actions 2 Split CompilerEnv.step() into two methods for singular or lists of actions (take 2) Mar 16, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 16, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #627 (6acd592) into development (e20ba1c) will decrease coverage by 8.84%.
The diff coverage is 80.50%.

@@               Coverage Diff               @@
##           development     #627      +/-   ##
===============================================
- Coverage        88.61%   79.76%   -8.85%     
===============================================
  Files              115      115              
  Lines             7019     7058      +39     
===============================================
- Hits              6220     5630     -590     
- Misses             799     1428     +629     
Impacted Files Coverage Δ
compiler_gym/random_replay.py 0.00% <0.00%> (ø)
compiler_gym/views/observation.py 91.89% <ø> (-5.41%) ⬇️
compiler_gym/wrappers/core.py 82.50% <69.69%> (-11.35%) ⬇️
compiler_gym/envs/compiler_env.py 82.03% <71.42%> (-9.33%) ⬇️
compiler_gym/bin/service.py 77.04% <100.00%> (+0.77%) ⬆️
compiler_gym/envs/llvm/llvm_rewards.py 100.00% <100.00%> (ø)
compiler_gym/random_search.py 91.93% <100.00%> (+0.04%) ⬆️
compiler_gym/spaces/named_discrete.py 85.00% <100.00%> (-9.45%) ⬇️
compiler_gym/spaces/reward.py 63.15% <100.00%> (-10.53%) ⬇️
compiler_gym/util/gym_type_hints.py 100.00% <100.00%> (ø)
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e20ba1c...6acd592. Read the comment docs.

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2022

Codecov Report

Merging #627 (8cd9679) into development (c5b9289) will decrease coverage by 0.52%.
The diff coverage is 80.70%.

@@               Coverage Diff               @@
##           development     #627      +/-   ##
===============================================
- Coverage        88.75%   88.23%   -0.53%     
===============================================
  Files              115      115              
  Lines             7019     7061      +42     
===============================================
  Hits              6230     6230              
- Misses             789      831      +42     
Impacted Files Coverage Δ
compiler_gym/random_replay.py 0.00% <0.00%> (ø)
compiler_gym/views/observation.py 97.29% <ø> (-2.71%) ⬇️
compiler_gym/wrappers/core.py 83.33% <68.75%> (-10.52%) ⬇️
compiler_gym/envs/compiler_env.py 89.31% <73.68%> (-3.04%) ⬇️
compiler_gym/bin/service.py 75.80% <80.00%> (-0.47%) ⬇️
compiler_gym/envs/llvm/llvm_rewards.py 100.00% <100.00%> (ø)
compiler_gym/random_search.py 91.93% <100.00%> (+0.04%) ⬆️
compiler_gym/spaces/named_discrete.py 95.00% <100.00%> (+0.55%) ⬆️
compiler_gym/spaces/reward.py 73.68% <100.00%> (ø)
compiler_gym/util/gym_type_hints.py 100.00% <100.00%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5b9289...8cd9679. Read the comment docs.

@sogartar
Copy link
Author

@ChrisCummins, I think I fixed the tests and examples. It should be ready for a review.

Copy link
Contributor

@ChrisCummins ChrisCummins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sogartar, thanks for pushing ahead with this. I think overloading multistep() makes total sense.

A few small changes requested, otherwise, LGTM!

Comment on lines 129 to 138
# Undo the episode_reward update and reapply it once we have transformed
# the reward.
#
# TODO(cummins): Refactor step() so that we don't have to do this
# recalculation of episode_reward, as this is prone to errors if, say,
# the base reward returns NaN or an invalid type.
if reward is not None and self.episode_reward is not None:
self.unwrapped.episode_reward -= reward
reward = self.reward(reward)
self.unwrapped.episode_reward += reward
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this workaround needs to be included, because multistep() runs the update to self.episode_reward.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should really be a unit test to cover this (not saying you need to add it 🙂 , just note to self)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it back.

Comment on lines +35 to +36
observation_spaces=None,
reward_spaces=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to accept observations and rewards arguments for backwards compatibility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -5,6 +5,8 @@

cg_add_all_subdirs()

return()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be in here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May bad. I removed it.

@@ -264,11 +272,9 @@ def reward(self, reward):
env.reset()
_, reward, _, _ = env.step(0)
assert reward == -5
assert env.episode_reward == -5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two deleted lines can be restored now that you're overloading multistep() rather than raw_step()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ChrisCummins
Copy link
Contributor

Heads up that CI/www-build failure is unrelated and not merge blocking. See #626.

ChrisCummins and others added 8 commits March 17, 2022 08:57
CompilerEnv.step() currently accepts two types for the "action"
argument: a scalar action, or an iterable of actions. This kind of
type overloading does not work for list types.

This adds a new method, CompilerEnv.multistep(), that explicitly takes
takes an iterable sequence of actions. If you want to run multiple
actions in a single step, call this new method. Calling
CompilerEnv.step() with a list of actions still works, though with a
deprecation warning. In the v0.2.4 release support for lists of
actions in CompilerEnv.step() will be removed.

Fixes #610.
This makes the following changes:

- Changes env.step() `action` to accept only a single action, with a
deprecation warning if a list of actions are provided.

- Renames env.step() `observations` to `observation_spaces`. The old
parameter name is still accepted with a deprecation warning.

- Renames env.step() `rewards` to `reward_spaces`. The old parameter
name is still accepted with a deprecation warning.
@sogartar sogartar force-pushed the feature/deprecate-action-list branch from 4360737 to 8cd9679 Compare March 17, 2022 15:58
@sogartar
Copy link
Author

sogartar commented Mar 17, 2022

@ChrisCummins, I addressed your comments. If your OK with them I think it is ready to merge after the CI tests have passed.

@ChrisCummins
Copy link
Contributor

Brill, thanks! Merging 🎉

@ChrisCummins ChrisCummins merged commit 6bf0209 into development Mar 17, 2022
@ChrisCummins ChrisCummins deleted the feature/deprecate-action-list branch March 17, 2022 23:44
This was referenced Mar 18, 2022
ChrisCummins added a commit that referenced this pull request May 24, 2022
This release adds a new compiler environment, new APIs, and a suite of backend
improvements to improve the flexibility of CompilerGym environments. Many thanks
to code contributors: @sogartar, @KyleHerndon, @SoumyajitKarmakar@uduse, and
@anthony0727!

Highlights of this release include:

- [mlir] Began work on a new environment for matrix multiplication using MLIR
  ([#652](#652), thanks
  @KyleHerndon and @sogartar!). Note this environment is not yet included in the
  pypi package and must be [compiled from
  source](https://github.com/facebookresearch/CompilerGym/blob/development/INSTALL.md#building-from-source-with-cmake).
- [llvm] Added a new `env.benchmark_from_clang_invocation()` method ([#577](#577)) that can be used for constructing LLVM environment automatically from C/C++ compiler invocations. This makes it much easier to integrate CompilerGym with your existing build scripts.
- Added three new wrapper classes: `Counter`, that provides op counts for
  analysis ([#683](#683));
  `SynchronousSqliteLogger`, that provides logging of environment interactions
  to a relational database
  ([#679](#679)), and
  `ForkOnStep` that provides an `undo()` operation
  ([#682](#682)).
- Added `reward_space` and `observation_space` parameters to `env.reset()`
  ([#659](#659), thanks
  @SoumyajitKarmakar!)

This release includes a number of improvements to the backend APIs that make it
easier to write new CompilerGym environments:

- Refactored the backend to make `CompilerEnv` an abstract interface, and
  `ClientServiceCompilerEnv` the concrete implementation of this interface. This
  enables new environments to be implemented without using gRPC
  ([#633](#633), thanks
  @sogartar!).
- Extended the support for different types of action and observation spaces
  ([#641](#641),
  [#643](#643), thanks
  @sogartar!), including new `Permutation` and `SpaceSequence` spaces
  ([#645](#645), thanks
  @sogartar!)..
- Added a new `disk/` subdirectory to compiler service's working directories,
  which is symlinked to an on-disk location for devices which support in-memory
  working directories. This fixes a bug with leftover temporary directories from
  LLVM ([#672](#672)).

This release also includes numerous bug fixes and improvements, many of which
were reported or fixed by the community. For example, fixing a bug in cache file
locations ([#656](#656),
thanks @uduse!), and a missing flag definition in example code
([#684](#684), thanks
@anthony0727!).

**Full Changelog**:
v0.2.3...v0.2.4

This release brings in deprecating changes to the core `env.step()` routine, and
lays the groundwork for enabling new types of compiler optimizations to be
exposed through CompilerGym. Many thanks to code contributors: @mostafaelhoushi,
@sogartar, @KyleHerndon, @uduse, @parthchadha, and @xtremey!

Highlights of this release include:

- Added a new `TextSizeInBytes` observation space for LLVM
  ([#575](#575)).
* Added a new PPO leaderboard entry
  ([#580](#580). Thanks
  @xtremey!
- Fixed a bug in which temporary directories created by the LLVM environment
  were not cleaned up
  ([#592](#592)).
- **[Backend]** The function `createAndRunCompilerGymService` now returns an
  int, which is the exit return code
  ([#592](#592)).
- Improvements to the examples documentation
  ([#548](#548)) and FAQ
  ([#586](#586))

Deprecations and breaking changes:

- `CompilerEnv.step` no longer accepts a list of actions
  ([#627](#627)). A new
  method, `CompilerEnv.multistep` provides this functionality. This is to
  provide compatibility with environments whose action spaces are lists. To
  update your code, replace any calls to `env.step()` which take a list of
  actions to use `env.multistep()`. Thanks @sogartar!
- The arguments `observations` and `rewards` to `step()` have been renamed
  `observation_spaces` and `reward_spaces`, respectively
  ([#627](#627)).
- `Reward.id` has been renamed `Reward.name`
  ([#565](#565),
  [#612](#612)). Thanks
  @parthchadha!
* The backend protocol buffer schema has been updated to natively support more
  types of observation and action, and to support nested spaces
  ([#531](#531)). Thanks
  @sogartar!
ChrisCummins added a commit that referenced this pull request May 24, 2022
This release adds a new compiler environment, new APIs, and a suite of backend
improvements to improve the flexibility of CompilerGym environments. Many thanks
to code contributors: @sogartar, @KyleHerndon, @SoumyajitKarmakar@uduse, and
@anthony0727!

Highlights of this release include:

- [mlir] Began work on a new environment for matrix multiplication using MLIR
  ([#652](#652), thanks
  @KyleHerndon and @sogartar!). Note this environment is not yet included in the
  pypi package and must be [compiled from
  source](https://github.com/facebookresearch/CompilerGym/blob/development/INSTALL.md#building-from-source-with-cmake).
- [llvm] Added a new `env.benchmark_from_clang_invocation()` method ([#577](#577)) that can be used for constructing LLVM environment automatically from C/C++ compiler invocations. This makes it much easier to integrate CompilerGym with your existing build scripts.
- Added three new wrapper classes: `Counter`, that provides op counts for
  analysis ([#683](#683));
  `SynchronousSqliteLogger`, that provides logging of environment interactions
  to a relational database
  ([#679](#679)), and
  `ForkOnStep` that provides an `undo()` operation
  ([#682](#682)).
- Added `reward_space` and `observation_space` parameters to `env.reset()`
  ([#659](#659), thanks
  @SoumyajitKarmakar!)

This release includes a number of improvements to the backend APIs that make it
easier to write new CompilerGym environments:

- Refactored the backend to make `CompilerEnv` an abstract interface, and
  `ClientServiceCompilerEnv` the concrete implementation of this interface. This
  enables new environments to be implemented without using gRPC
  ([#633](#633), thanks
  @sogartar!).
- Extended the support for different types of action and observation spaces
  ([#641](#641),
  [#643](#643), thanks
  @sogartar!), including new `Permutation` and `SpaceSequence` spaces
  ([#645](#645), thanks
  @sogartar!)..
- Added a new `disk/` subdirectory to compiler service's working directories,
  which is symlinked to an on-disk location for devices which support in-memory
  working directories. This fixes a bug with leftover temporary directories from
  LLVM ([#672](#672)).

This release also includes numerous bug fixes and improvements, many of which
were reported or fixed by the community. For example, fixing a bug in cache file
locations ([#656](#656),
thanks @uduse!), and a missing flag definition in example code
([#684](#684), thanks
@anthony0727!).

**Full Changelog**:
v0.2.3...v0.2.4

This release brings in deprecating changes to the core `env.step()` routine, and
lays the groundwork for enabling new types of compiler optimizations to be
exposed through CompilerGym. Many thanks to code contributors: @mostafaelhoushi,
@sogartar, @KyleHerndon, @uduse, @parthchadha, and @xtremey!

Highlights of this release include:

- Added a new `TextSizeInBytes` observation space for LLVM
  ([#575](#575)).
* Added a new PPO leaderboard entry
  ([#580](#580). Thanks
  @xtremey!
- Fixed a bug in which temporary directories created by the LLVM environment
  were not cleaned up
  ([#592](#592)).
- **[Backend]** The function `createAndRunCompilerGymService` now returns an
  int, which is the exit return code
  ([#592](#592)).
- Improvements to the examples documentation
  ([#548](#548)) and FAQ
  ([#586](#586))

Deprecations and breaking changes:

- `CompilerEnv.step` no longer accepts a list of actions
  ([#627](#627)). A new
  method, `CompilerEnv.multistep` provides this functionality. This is to
  provide compatibility with environments whose action spaces are lists. To
  update your code, replace any calls to `env.step()` which take a list of
  actions to use `env.multistep()`. Thanks @sogartar!
- The arguments `observations` and `rewards` to `step()` have been renamed
  `observation_spaces` and `reward_spaces`, respectively
  ([#627](#627)).
- `Reward.id` has been renamed `Reward.name`
  ([#565](#565),
  [#612](#612)). Thanks
  @parthchadha!
* The backend protocol buffer schema has been updated to natively support more
  types of observation and action, and to support nested spaces
  ([#531](#531)). Thanks
  @sogartar!
ChrisCummins added a commit that referenced this pull request May 24, 2022
This release adds a new compiler environment, new APIs, and a suite of backend
improvements to improve the flexibility of CompilerGym environments. Many thanks
to code contributors: @sogartar, @KyleHerndon, @SoumyajitKarmakar@uduse, and
@anthony0727!

Highlights of this release include:

- [mlir] Began work on a new environment for matrix multiplication using MLIR
  ([#652](#652), thanks
  @KyleHerndon and @sogartar!). Note this environment is not yet included in the
  pypi package and must be [compiled from
  source](https://github.com/facebookresearch/CompilerGym/blob/development/INSTALL.md#building-from-source-with-cmake).
- [llvm] Added a new `env.benchmark_from_clang_invocation()` method ([#577](#577)) that can be used for constructing LLVM environment automatically from C/C++ compiler invocations. This makes it much easier to integrate CompilerGym with your existing build scripts.
- Added three new wrapper classes: `Counter`, that provides op counts for
  analysis ([#683](#683));
  `SynchronousSqliteLogger`, that provides logging of environment interactions
  to a relational database
  ([#679](#679)), and
  `ForkOnStep` that provides an `undo()` operation
  ([#682](#682)).
- Added `reward_space` and `observation_space` parameters to `env.reset()`
  ([#659](#659), thanks
  @SoumyajitKarmakar!)

This release includes a number of improvements to the backend APIs that make it
easier to write new CompilerGym environments:

- Refactored the backend to make `CompilerEnv` an abstract interface, and
  `ClientServiceCompilerEnv` the concrete implementation of this interface. This
  enables new environments to be implemented without using gRPC
  ([#633](#633), thanks
  @sogartar!).
- Extended the support for different types of action and observation spaces
  ([#641](#641),
  [#643](#643), thanks
  @sogartar!), including new `Permutation` and `SpaceSequence` spaces
  ([#645](#645), thanks
  @sogartar!)..
- Added a new `disk/` subdirectory to compiler service's working directories,
  which is symlinked to an on-disk location for devices which support in-memory
  working directories. This fixes a bug with leftover temporary directories from
  LLVM ([#672](#672)).

This release also includes numerous bug fixes and improvements, many of which
were reported or fixed by the community. For example, fixing a bug in cache file
locations ([#656](#656),
thanks @uduse!), and a missing flag definition in example code
([#684](#684), thanks
@anthony0727!).

**Full Changelog**:
v0.2.3...v0.2.4

This release brings in deprecating changes to the core `env.step()` routine, and
lays the groundwork for enabling new types of compiler optimizations to be
exposed through CompilerGym. Many thanks to code contributors: @mostafaelhoushi,
@sogartar, @KyleHerndon, @uduse, @parthchadha, and @xtremey!

Highlights of this release include:

- Added a new `TextSizeInBytes` observation space for LLVM
  ([#575](#575)).
* Added a new PPO leaderboard entry
  ([#580](#580). Thanks
  @xtremey!
- Fixed a bug in which temporary directories created by the LLVM environment
  were not cleaned up
  ([#592](#592)).
- **[Backend]** The function `createAndRunCompilerGymService` now returns an
  int, which is the exit return code
  ([#592](#592)).
- Improvements to the examples documentation
  ([#548](#548)) and FAQ
  ([#586](#586))

Deprecations and breaking changes:

- `CompilerEnv.step` no longer accepts a list of actions
  ([#627](#627)). A new
  method, `CompilerEnv.multistep` provides this functionality. This is to
  provide compatibility with environments whose action spaces are lists. To
  update your code, replace any calls to `env.step()` which take a list of
  actions to use `env.multistep()`. Thanks @sogartar!
- The arguments `observations` and `rewards` to `step()` have been renamed
  `observation_spaces` and `reward_spaces`, respectively
  ([#627](#627)).
- `Reward.id` has been renamed `Reward.name`
  ([#565](#565),
  [#612](#612)). Thanks
  @parthchadha!
* The backend protocol buffer schema has been updated to natively support more
  types of observation and action, and to support nested spaces
  ([#531](#531)). Thanks
  @sogartar!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants