Bug when creating AgentManagers
See original GitHub issueHello, I was recently working with the agent checks on rlberry/utils/check_agent.py
and I was encountering the following error:
fatal: not a git repository (or any of the parent directories): .git Traceback (most recent call last): File “./examples/demo_examples/demo_sb_agent.py”, line 30, in <module> stats = AgentManager( File “/Users/mmcenta/miniconda3/envs/rlb/lib/python3.8/site-packages/rlberry/manager/agent_manager.py”, line 386, in init self.rlberry_version = get_rlberry_version() File “/Users/mmcenta/miniconda3/envs/rlb/lib/python3.8/site-packages/rlberry/utils/hash_utils.py”, line 25, in get_rlberry_version subprocess.check_output( File “/Users/mmcenta/miniconda3/envs/rlb/lib/python3.8/subprocess.py”, line 415, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File “/Users/mmcenta/miniconda3/envs/rlb/lib/python3.8/subprocess.py”, line 516, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command ‘[‘git’, ‘rev-parse’, ‘HEAD’]’ returned non-zero exit status 128.
It is caused by the get_rlberry_version()
function introduced recently (in PR #126), which requires the current directory (or its parent) to be a git repository. As it turns out, after installing the library with pip install .
, this function is called from inside the library (somewhere in ~/miniconda3/envs/rlb/lib/python3.8/site-packages/rlberry/utils
, in my case). The result is the error above because the other directory is not part of a git repository.
Reproducing
The code below reproduces the bug:
from rlberry.agents.torch import A2CAgent
from rlberry.envs import gym_make
from rlberry.manager import AgentManager
if __name__ == "__main__":
env_ctor = gym_make
env_kwargs = {'id': 'CartPole-v0'}
stats = AgentManager(
A2CAgent,
(env_ctor, env_kwargs),
agent_name="A2C",
init_kwargs=dict(batch_size=16),
fit_budget=100,
)
Running this code produces the same error from above. Do NOT run the code from the rlberry
main directory, because in that case it will import the local code which runs in a git directory. I run this code from a subdirectory rlberry/test_bug/bug.py
, which forces Python to load the installed version of rlberry.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (2 by maintainers)
Top GitHub Comments
This is now entirely solved.
The version is now in a static file
rlberry/_version.py
and this file definerlberry.__version__
that is automatically recorder in AgentManager and also it is recorded in the doc and setup.py. The _version.py file is automatically updated by a workflow that activate at each PR merge. This creates a commit that changes the version.Typical version is
__version__ = "v0.2.1.post82.dev0+feb610b "
which means v0.2.1 (from the tag) after which we did 82 commits on main branch, the last of which has hash feb610b. This indicate precisely which version of rlberry was used and because it is in the github workflow, there is no need to change the version locally, so no dependency on git or anything of the sort.
The thing is that tests are run from rlberry main directory which is why it was not spotted. I actually don’t really understand why you had the error because on my PC, with pip install . -e it works, maybe a difference with windows or other ? Anyway I am working on a cleaner solution in the PR. I don’t think I could do a regression test for this, I would have to run the tests from outside rlberry folder, but pytest automatically runs tests from inside rlberry folder I think.