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

Enable and Fix Environment Examples in CMake CI #642

Conversation

mostafaelhoushi
Copy link
Contributor

@mostafaelhoushi mostafaelhoushi commented Mar 31, 2022

Fixes #631

  • ensured that the example scripts are invoked in CMake CI by creating example_without_bazel_test.py scripts
  • ensured that unit tests in env_tests.py are invoked in CMake CI by copying them into env_without_bazel_test.py
  • disabled the tests cases in Linux and MacOS bazel builds for now (hopefully will fix that with How to build and access with loop_unroller and opt_loops binaries in CI #707 )

@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 31, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2022

Codecov Report

Merging #642 (52f5d04) into development (71b1b77) will decrease coverage by 0.05%.
The diff coverage is n/a.

@@               Coverage Diff               @@
##           development     #642      +/-   ##
===============================================
- Coverage        88.68%   88.63%   -0.06%     
===============================================
  Files              131      131              
  Lines             7934     7934              
===============================================
- Hits              7036     7032       -4     
- Misses             898      902       +4     
Impacted Files Coverage Δ
compiler_gym/service/connection.py 77.66% <0.00%> (-0.67%) ⬇️
...ompiler_gym/service/client_service_compiler_env.py 90.43% <0.00%> (-0.42%) ⬇️

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 71b1b77...52f5d04. Read the comment docs.

@ChrisCummins
Copy link
Contributor

Looks like the CI is broken on this

@mostafaelhoushi
Copy link
Contributor Author

I am revisiting this pull request.
So the CI runs the tests by calling make -C example tests which in turn runs the Python tests without bazel.
The tests run fine if I use bazel, e.g.,

bazel test //examples/example_compiler_gym_service/...

but running the Python files direcrtly doesn't work.

So I had to follow the approach we did when we copied demo.py to demo_without_bazel.py, so here I am copying env_test.py to env_without_bazel_test.py and made some changes accordingly.

However, I am now stuck with this error:

$ cd examples
$ python example_compiler_gym_service/env_without_bazel_test.py                            
======================================================================= test session starts ========================================================================
platform darwin -- Python 3.8.11, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /Users/melhoushi/opt/anaconda3/envs/compiler_gym/bin/python
cachedir: .pytest_cache
rootdir: /Users/melhoushi/CompilerGym, configfile: tox.ini
plugins: flaky-3.7.0, hydra-core-1.1.0
collected 0 items / 1 error                                                                                                                                        
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/main.py", line 322, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/pluggy/_callers.py", line 55, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1210, in pytest_collection
INTERNALERROR>     self._validate_config_options()
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1233, in _validate_config_options
INTERNALERROR>     self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1269, in _warn_or_fail_if_strict
INTERNALERROR>     self.issue_config_time_warning(PytestConfigWarning(message), stacklevel=3)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1321, in issue_config_time_warning
INTERNALERROR>     warnings.warn(warning, stacklevel=stacklevel)
INTERNALERROR> pytest.PytestConfigWarning: Unknown config option: timeout

========================================================================= 1 error in 0.16s =========================================================================

@ChrisCummins
Copy link
Contributor

That's a strange one. Looks like maybe a problem with missing / bad plugin?

If you disable env_without_bazel_test.py (by renaming it foo.py), does the problem go away?

@mostafaelhoushi
Copy link
Contributor Author

That's a strange one. Looks like maybe a problem with missing / bad plugin?

If you disable env_without_bazel_test.py (by renaming it foo.py), does the problem go away?

Got the same error :(

$ mv example_compiler_gym_service/env_without_bazel_test.py example_compiler_gym_service/foo.py
$ python example_compiler_gym_service/foo.py 

======================================================================= test session starts ========================================================================
platform darwin -- Python 3.8.11, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /Users/melhoushi/opt/anaconda3/envs/compiler_gym/bin/python
cachedir: .pytest_cache
rootdir: /Users/melhoushi/CompilerGym, configfile: tox.ini
plugins: flaky-3.7.0, hydra-core-1.1.0
collected 0 items / 1 error                                                                                                                                        
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/main.py", line 322, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/pluggy/_callers.py", line 55, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1210, in pytest_collection
INTERNALERROR>     self._validate_config_options()
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1233, in _validate_config_options
INTERNALERROR>     self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1269, in _warn_or_fail_if_strict
INTERNALERROR>     self.issue_config_time_warning(PytestConfigWarning(message), stacklevel=3)
INTERNALERROR>   File "/Users/melhoushi/opt/anaconda3/envs/compiler_gym/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1321, in issue_config_time_warning
INTERNALERROR>     warnings.warn(warning, stacklevel=stacklevel)
INTERNALERROR> pytest.PytestConfigWarning: Unknown config option: timeout

========================================================================= 1 error in 0.15s =========================================================================

@mostafaelhoushi
Copy link
Contributor Author

Never mind.. when I installed:

$ pip install pytest-timeout==1.4.2  

I no longer got the error....

Now fixing other errors :)

@mostafaelhoushi
Copy link
Contributor Author

@ChrisCummins : do you know why the pre-commit job is failing? It seems to be not related to this PR:
image

@ChrisCummins
Copy link
Contributor

ChrisCummins commented May 25, 2022

Copy the examples/sensitivity_analysis dir from latest development head

I broke it yesterday, should be fixed now 🙂

@ChrisCummins
Copy link
Contributor

Ah, sorry, I was confused! The development branch is still broken. I'll merge an update now so that you can rebase this branch on it. Stay tuned ...

@ChrisCummins
Copy link
Contributor

Okay, development is now un-broken. Off to the races!

@mostafaelhoushi
Copy link
Contributor Author

The CI is failing with WARNING: Overriding environment example-v0.
image

I was able to mitigate that on my local machine by adding those arguments when calling main (full context here):

if __name__ == "__main__":
    main(
        extra_pytest_args=[
            "-W",
            "ignore::UserWarning",
        ]
    )

I am not sure why it still fails on CI.

Any idea @ChrisCummins ?

@ChrisCummins
Copy link
Contributor

Hmm, not sure about this one. Will have to take a look on Tuesday.

Cheers,
Chris

@mostafaelhoushi
Copy link
Contributor Author

OK. I fixed it in this commit 0077632 by choosing a different name for the registered environment in env_without_bazel_test.py from example-v0 to example-v1.

(Perhaps the error is due to demo_without_bazel_test.py running before env_without_bazel_test.py creating an environment with the same name example-v0).

@ChrisCummins
Copy link
Contributor

Ah, that makes sense. Every environment you register must have a unique name. So if two tests register example-v0, one will clobber the other when all of the tests are run in a single python session.

Cheers,
Chris

try Path instead of runfiles_path to see if CI passes

add test without bazel

revert commits to bazel tests and update without_bazel test

revert name change

dont throw errors on UserWarning

enable import tests by adding __init__ file

avoid importing tests as it causes pytest to throw an error

rename env to example-v1 to avoid warning

fix test_observation_space

get example_unrolling_service to work without bazel

avoid 'WARNING: unrolling-v1 environment already exists' error

build loop_unroller from within python if it is not found

don't include the CMake for standalone build

mv clang-10 to clang

sometimes clang-10 doesn't exist so handle that
@mostafaelhoushi
Copy link
Contributor Author

@ChrisCummins , test-examples-macos failed with:

        if done:
            # Computing an observation should never cause a terminal state since
            # no action has been applied.
            msg = f"Failed to compute observation '{observation_space.id}'"
            if info.get("error_details"):
                msg += f": {info['error_details']}"
>           raise ServiceError(msg)
E           compiler_gym.errors.service_errors.ServiceError: Failed to compute observation 'runtime': RPC call returned status code StatusCode.INTERNAL and error `Compilation job failed with returncode 1 (SIGHUP)
E           Command: /Users/runner/.local/share/compiler_gym/llvm-v0/bin/clang /Users/runner/.local/cache/compiler_gym/s/0613T160607-720121-389c/benchmark.o -O3 -o /Users/runner/.local/cache/compiler_gym/s/0613T160607-720121-389c/benchmark.exe
E           Stderr: ld: library not found for -lSystem
E           clang: error: linker command failed with exit code 1 (use -v to see invocation)`

do you know a fix for that?

(Full log should be here: https:/facebookresearch/CompilerGym/runs/6865005685?check_suite_focus=true)

@ChrisCummins
Copy link
Contributor

Yep. The LLVM binaries we use for CompilerGym don't know about the system libraries, we need to figure them out ourselves. To do this, call compiler_gym.envs.llvm.get_system_library_flags() and append the list of flags it returns to your clang invocation(s).

Cheers,
Chris

@mostafaelhoushi mostafaelhoushi changed the title Enable and Fix Environment Examples in CI Enable and Fix Environment Examples in CMake CI Jun 13, 2022
@mostafaelhoushi
Copy link
Contributor Author

I have removed the explicit run of python examples in CI, and ensured that they run in pytest instead.

I have disabled the tests cases in Linux and MacOS bazel builds for now (hopefully will fix that with #707 ).

The Pull Request should be ready now for review @ChrisCummins

@ChrisCummins
Copy link
Contributor

LGTM. Many thanks for pushing on this @mostafaelhoushi.

Feel free to merge when you're happy with it.

Cheers,
Chris

@mostafaelhoushi mostafaelhoushi merged commit d67ce92 into facebookresearch:development Jun 13, 2022
This was referenced Nov 1, 2022
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.

examples/loop_optimizations_service/env_tests.py::test_default_autophase_dict_observation fails
4 participants