We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Manual env fails without helpful error when no benchmarks are loaded.
## 🐛 Bug

compiler_gym.bin.manual_env fails with stacktrace if no benchmarks are loaded.

## To Reproduce
```
> python -m compiler_gym.bin.manual_env --env=llvm-autophase-ic-v0 --benchmark=npb-v0/50
Initialized environment in 264.7ms
Benchmark: [0] random >>> random
> 0
Traceback (most recent call last):
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/bin/manual_env.py", line 179, in <module>
    main(sys.argv)
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/bin/manual_env.py", line 175, in main
    run_manual_env(env)
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/bin/manual_env.py", line 60, in run_manual_env
    eager_observation = env.reset(benchmark=benchmark)
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/envs/llvm/llvm_env.py", line 162, in reset
    return super().reset(*args, **kwargs)
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/envs/compiler_env.py", line 466, in reset
    reply = self.service(
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/service/connection.py", line 547, in __call__
    return self.connection(
  File "/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/service/connection.py", line 143, in __call__
    raise ValueError(e.details()) from None
ValueError: Unknown benchmark "npb-v0/50"
```
## Expected behavior
Something like:
```
> python -m compiler_gym.bin.manual_env --env=llvm-autophase-ic-v0 --benchmark=npb-v0/50
Initialized environment in 264.7ms
No benchmarks available see https://facebookresearch.github.io/CompilerGym/getting_started.html#installing-benchmarks
Exiting...
```

## Environment

Please fill in this checklist:

- CompilerGym:
- How you installed CompilerGym (conda, pip, source): source
- OS: MacOs 10.15.7
- Python version: 3.8.4
- Build command you used (if compiling from source): make install
- GCC/clang version (if compiling from source): Apple clang version 12.0.0 (clang-1200.0.31.1)
- Bazel version (if compiling from source): 3.1.0- (@non-git)
- Versions of any other relevant libraries:

You may use the PyTorch
N/A


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `compiler_gym/bin/manual_env.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates.
2 #
3 # This source code is licensed under the MIT license found in the
4 # LICENSE file in the root directory of this source tree.
5 """Run a CompilerGym environment with text interface controls.
6 
7 .. code-block::
8 
9     $ python -m compiler_gym.bin.manual_env --env=<env> [--benchmark=<name>] [--observation=<space>] [--reward=<space>]
10 
11 The benchmark to use can be specified using :code:`--benchmark=<name>`. If not
12 provided, you be presented with a list of benchmarks to choose from on launch.
13 Select :code:`random` to select a benchmark randomly.
14 """
15 import sys
16 from typing import Optional
17 
18 from absl import app, flags
19 
20 import compiler_gym.util.flags.ls_benchmark  # Flag definition.
21 from compiler_gym.envs import CompilerEnv
22 from compiler_gym.util import user_input
23 from compiler_gym.util.flags.benchmark_from_flags import benchmark_from_flags
24 from compiler_gym.util.flags.env_from_flags import env_from_flags
25 from compiler_gym.util.shell_format import emph
26 from compiler_gym.util.timer import Timer
27 
28 FLAGS = flags.FLAGS
29 
30 
31 def run_manual_env(env: CompilerEnv):
32     """Run an environment manually.
33 
34     The manual environment allows the user to step through the environment,
35     selection observations, rewards, and actions to run as they see fit. This is
36     useful for debugging.
37 
38     :param env: The environment to run.
39     """
40     benchmark = None
41     if not env.benchmark:
42         # Allow the user to choose a benchmark, with the first choice being
43         # to select randomly.
44         benchmarks = sorted(env.benchmarks)
45         # Strip default benchmark:// protocol.
46         for i, benchmark in enumerate(benchmarks):
47             if benchmark.startswith("benchmark://"):
48                 benchmarks[i] = benchmark[len("benchmark://") :]
49 
50         benchmark_index = user_input.read_list_index(
51             "Benchmark", ["random"] + benchmarks
52         )
53         if benchmark_index:
54             benchmark = benchmarks[benchmark_index - 1]
55         else:
56             benchmark = None
57 
58     with Timer() as timer:
59         eager_observation = env.reset(benchmark=benchmark)
60 
61     print(f"Reset {env.benchmark} environment in {timer}")
62     if env.observation_space and eager_observation is not None:
63         print(f"Observation: {env.observation_space.to_string(eager_observation)}")
64 
65     observation_names = sorted(env.observation.spaces.keys())
66     reward_names = sorted(env.reward.spaces.keys())
67     last_eager_reward: Optional[float] = None
68     step_count = 1
69 
70     while True:
71         print(
72             f"\nStep {step_count}. Select: [{emph('a')}]ction "
73             f"[{emph('o')}]bservation [{emph('r')}]eward "
74             f"[{emph('c')}]ommandline [{emph('e')}]nd >>> ",
75             end="",
76             flush=True,
77         )
78         while True:
79             c = user_input.read_char()
80             if c == "a":
81                 print("action", flush=True)
82                 index = user_input.read_list_index(
83                     "Actions", ["random"] + env.action_space.names
84                 )
85                 step_count += 1
86                 with Timer() as t:
87                     if index == 0:
88                         # User selected "random" action.
89                         index = env.action_space.sample()
90                     else:
91                         # Offset to remove "random" action from index.
92                         index -= 1
93                     eager_observation, eager_reward, done, info = env.step(index)
94 
95                 # Print the eager observation, if available.
96                 if env.observation_space and eager_observation is not None:
97                     print(
98                         f"Observation: {env.observation_space.to_string(eager_observation)}"
99                     )
100 
101                 # Print the eager reward and the diff, if available.
102                 if env.reward_space and eager_reward is not None:
103                     reward_diff = ""
104                     if last_eager_reward is not None and eager_reward is not None:
105                         reward_diff = (
106                             f" (change: {eager_reward - last_eager_reward:.6f})"
107                         )
108                     print(f"Reward: {eager_reward:.6f}{reward_diff}")
109                     last_eager_reward = eager_reward
110 
111                 print(
112                     f"Action {env.action_space.names[index]} in {t}.",
113                     " No effect." if info.get("action_had_no_effect") else "",
114                     flush=True,
115                 )
116                 if done:
117                     print("Episode ended by environment: ", info["error_details"])
118                     env.close()
119                     return
120                 break
121             if c == "o":
122                 print("observation", flush=True)
123                 observation_name = user_input.read_list_value(
124                     "Observable values", observation_names
125                 )
126                 with Timer() as timer:
127                     value = env.observation[observation_name]
128                 print(env.observation.spaces[observation_name].to_string(value))
129                 print(f"Observation {observation_name} in {timer}")
130                 break
131             elif c == "r":
132                 print("reward", flush=True)
133                 reward_name = user_input.read_list_value("Rewards", reward_names)
134                 with Timer(f"Reward {reward_name}"):
135                     print(f"{env.reward[reward_name]:.6f}")
136                 break
137             elif c == "c":
138                 print("commandline")
139                 print("$", env.commandline(), flush=True)
140                 break
141             elif c == "e":
142                 print("end", flush=True)
143                 with Timer("Closed environment"):
144                     env.close()
145                 print("Have a nice day!")
146                 return
147 
148 
149 def main(argv):
150     """Main entry point."""
151     argv = FLAGS(argv)
152     if len(argv) != 1:
153         raise app.UsageError(f"Unknown command line arguments: {argv[1:]}")
154 
155     if FLAGS.ls_benchmark:
156         benchmark = benchmark_from_flags()
157         env = env_from_flags(benchmark)
158         print("\n".join(sorted(env.benchmarks)))
159         env.close()
160         return
161 
162     with Timer("Initialized environment"):
163         benchmark = benchmark_from_flags()
164         env = env_from_flags(benchmark)
165 
166     run_manual_env(env)
167 
168 
169 if __name__ == "__main__":
170     main(sys.argv)
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/compiler_gym/bin/manual_env.py b/compiler_gym/bin/manual_env.py
--- a/compiler_gym/bin/manual_env.py
+++ b/compiler_gym/bin/manual_env.py
@@ -43,10 +43,16 @@
         # Allow the user to choose a benchmark, with the first choice being
         # to select randomly.
         benchmarks = sorted(env.benchmarks)
+        if not benchmarks:
+            print("No benchmarks available see https://facebookresearch.github.io/CompilerGym/getting_started.html#installing-benchmarks")
+            print("Exiting...")
+            env.close()
+            return
+
         # Strip default benchmark:// protocol.
         for i, benchmark in enumerate(benchmarks):
             if benchmark.startswith("benchmark://"):
-                benchmarks[i] = benchmark[len("benchmark://") :]
+                benchmarks[i] = benchmark[len("benchmark://"):]
 
         benchmark_index = user_input.read_list_index(
             "Benchmark", ["random"] + benchmarks

{"golden_diff": "diff --git a/compiler_gym/bin/manual_env.py b/compiler_gym/bin/manual_env.py\n--- a/compiler_gym/bin/manual_env.py\n+++ b/compiler_gym/bin/manual_env.py\n@@ -43,10 +43,16 @@\n         # Allow the user to choose a benchmark, with the first choice being\n         # to select randomly.\n         benchmarks = sorted(env.benchmarks)\n+        if not benchmarks:\n+            print(\"No benchmarks available see https://facebookresearch.github.io/CompilerGym/getting_started.html#installing-benchmarks\")\n+            print(\"Exiting...\")\n+            env.close()\n+            return\n+\n         # Strip default benchmark:// protocol.\n         for i, benchmark in enumerate(benchmarks):\n             if benchmark.startswith(\"benchmark://\"):\n-                benchmarks[i] = benchmark[len(\"benchmark://\") :]\n+                benchmarks[i] = benchmark[len(\"benchmark://\"):]\n \n         benchmark_index = user_input.read_list_index(\n             \"Benchmark\", [\"random\"] + benchmarks\n", "issue": "Manual env fails without helpful error when no benchmarks are loaded.\n## \ud83d\udc1b Bug\r\n\r\ncompiler_gym.bin.manual_env fails with stacktrace if no benchmarks are loaded.\r\n\r\n## To Reproduce\r\n```\r\n> python -m compiler_gym.bin.manual_env --env=llvm-autophase-ic-v0 --benchmark=npb-v0/50\r\nInitialized environment in 264.7ms\r\nBenchmark: [0] random >>> random\r\n> 0\r\nTraceback (most recent call last):\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/runpy.py\", line 194, in _run_module_as_main\r\n    return _run_code(code, main_globals, None,\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/bin/manual_env.py\", line 179, in <module>\r\n    main(sys.argv)\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/bin/manual_env.py\", line 175, in main\r\n    run_manual_env(env)\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/bin/manual_env.py\", line 60, in run_manual_env\r\n    eager_observation = env.reset(benchmark=benchmark)\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/envs/llvm/llvm_env.py\", line 162, in reset\r\n    return super().reset(*args, **kwargs)\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/envs/compiler_env.py\", line 466, in reset\r\n    reply = self.service(\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/service/connection.py\", line 547, in __call__\r\n    return self.connection(\r\n  File \"/Users/hleather/opt/miniconda3/envs/compiler_gym/lib/python3.8/site-packages/compiler_gym-0.1.1-py3.8.egg/compiler_gym/service/connection.py\", line 143, in __call__\r\n    raise ValueError(e.details()) from None\r\nValueError: Unknown benchmark \"npb-v0/50\"\r\n```\r\n## Expected behavior\r\nSomething like:\r\n```\r\n> python -m compiler_gym.bin.manual_env --env=llvm-autophase-ic-v0 --benchmark=npb-v0/50\r\nInitialized environment in 264.7ms\r\nNo benchmarks available see https://facebookresearch.github.io/CompilerGym/getting_started.html#installing-benchmarks\r\nExiting...\r\n```\r\n\r\n## Environment\r\n\r\nPlease fill in this checklist:\r\n\r\n- CompilerGym:\r\n- How you installed CompilerGym (conda, pip, source): source\r\n- OS: MacOs 10.15.7\r\n- Python version: 3.8.4\r\n- Build command you used (if compiling from source): make install\r\n- GCC/clang version (if compiling from source): Apple clang version 12.0.0 (clang-1200.0.31.1)\r\n- Bazel version (if compiling from source): 3.1.0- (@non-git)\r\n- Versions of any other relevant libraries:\r\n\r\nYou may use the PyTorch\r\nN/A\r\n\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\"\"\"Run a CompilerGym environment with text interface controls.\n\n.. code-block::\n\n    $ python -m compiler_gym.bin.manual_env --env=<env> [--benchmark=<name>] [--observation=<space>] [--reward=<space>]\n\nThe benchmark to use can be specified using :code:`--benchmark=<name>`. If not\nprovided, you be presented with a list of benchmarks to choose from on launch.\nSelect :code:`random` to select a benchmark randomly.\n\"\"\"\nimport sys\nfrom typing import Optional\n\nfrom absl import app, flags\n\nimport compiler_gym.util.flags.ls_benchmark  # Flag definition.\nfrom compiler_gym.envs import CompilerEnv\nfrom compiler_gym.util import user_input\nfrom compiler_gym.util.flags.benchmark_from_flags import benchmark_from_flags\nfrom compiler_gym.util.flags.env_from_flags import env_from_flags\nfrom compiler_gym.util.shell_format import emph\nfrom compiler_gym.util.timer import Timer\n\nFLAGS = flags.FLAGS\n\n\ndef run_manual_env(env: CompilerEnv):\n    \"\"\"Run an environment manually.\n\n    The manual environment allows the user to step through the environment,\n    selection observations, rewards, and actions to run as they see fit. This is\n    useful for debugging.\n\n    :param env: The environment to run.\n    \"\"\"\n    benchmark = None\n    if not env.benchmark:\n        # Allow the user to choose a benchmark, with the first choice being\n        # to select randomly.\n        benchmarks = sorted(env.benchmarks)\n        # Strip default benchmark:// protocol.\n        for i, benchmark in enumerate(benchmarks):\n            if benchmark.startswith(\"benchmark://\"):\n                benchmarks[i] = benchmark[len(\"benchmark://\") :]\n\n        benchmark_index = user_input.read_list_index(\n            \"Benchmark\", [\"random\"] + benchmarks\n        )\n        if benchmark_index:\n            benchmark = benchmarks[benchmark_index - 1]\n        else:\n            benchmark = None\n\n    with Timer() as timer:\n        eager_observation = env.reset(benchmark=benchmark)\n\n    print(f\"Reset {env.benchmark} environment in {timer}\")\n    if env.observation_space and eager_observation is not None:\n        print(f\"Observation: {env.observation_space.to_string(eager_observation)}\")\n\n    observation_names = sorted(env.observation.spaces.keys())\n    reward_names = sorted(env.reward.spaces.keys())\n    last_eager_reward: Optional[float] = None\n    step_count = 1\n\n    while True:\n        print(\n            f\"\\nStep {step_count}. Select: [{emph('a')}]ction \"\n            f\"[{emph('o')}]bservation [{emph('r')}]eward \"\n            f\"[{emph('c')}]ommandline [{emph('e')}]nd >>> \",\n            end=\"\",\n            flush=True,\n        )\n        while True:\n            c = user_input.read_char()\n            if c == \"a\":\n                print(\"action\", flush=True)\n                index = user_input.read_list_index(\n                    \"Actions\", [\"random\"] + env.action_space.names\n                )\n                step_count += 1\n                with Timer() as t:\n                    if index == 0:\n                        # User selected \"random\" action.\n                        index = env.action_space.sample()\n                    else:\n                        # Offset to remove \"random\" action from index.\n                        index -= 1\n                    eager_observation, eager_reward, done, info = env.step(index)\n\n                # Print the eager observation, if available.\n                if env.observation_space and eager_observation is not None:\n                    print(\n                        f\"Observation: {env.observation_space.to_string(eager_observation)}\"\n                    )\n\n                # Print the eager reward and the diff, if available.\n                if env.reward_space and eager_reward is not None:\n                    reward_diff = \"\"\n                    if last_eager_reward is not None and eager_reward is not None:\n                        reward_diff = (\n                            f\" (change: {eager_reward - last_eager_reward:.6f})\"\n                        )\n                    print(f\"Reward: {eager_reward:.6f}{reward_diff}\")\n                    last_eager_reward = eager_reward\n\n                print(\n                    f\"Action {env.action_space.names[index]} in {t}.\",\n                    \" No effect.\" if info.get(\"action_had_no_effect\") else \"\",\n                    flush=True,\n                )\n                if done:\n                    print(\"Episode ended by environment: \", info[\"error_details\"])\n                    env.close()\n                    return\n                break\n            if c == \"o\":\n                print(\"observation\", flush=True)\n                observation_name = user_input.read_list_value(\n                    \"Observable values\", observation_names\n                )\n                with Timer() as timer:\n                    value = env.observation[observation_name]\n                print(env.observation.spaces[observation_name].to_string(value))\n                print(f\"Observation {observation_name} in {timer}\")\n                break\n            elif c == \"r\":\n                print(\"reward\", flush=True)\n                reward_name = user_input.read_list_value(\"Rewards\", reward_names)\n                with Timer(f\"Reward {reward_name}\"):\n                    print(f\"{env.reward[reward_name]:.6f}\")\n                break\n            elif c == \"c\":\n                print(\"commandline\")\n                print(\"$\", env.commandline(), flush=True)\n                break\n            elif c == \"e\":\n                print(\"end\", flush=True)\n                with Timer(\"Closed environment\"):\n                    env.close()\n                print(\"Have a nice day!\")\n                return\n\n\ndef main(argv):\n    \"\"\"Main entry point.\"\"\"\n    argv = FLAGS(argv)\n    if len(argv) != 1:\n        raise app.UsageError(f\"Unknown command line arguments: {argv[1:]}\")\n\n    if FLAGS.ls_benchmark:\n        benchmark = benchmark_from_flags()\n        env = env_from_flags(benchmark)\n        print(\"\\n\".join(sorted(env.benchmarks)))\n        env.close()\n        return\n\n    with Timer(\"Initialized environment\"):\n        benchmark = benchmark_from_flags()\n        env = env_from_flags(benchmark)\n\n    run_manual_env(env)\n\n\nif __name__ == \"__main__\":\n    main(sys.argv)\n", "path": "compiler_gym/bin/manual_env.py"}], "after_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\"\"\"Run a CompilerGym environment with text interface controls.\n\n.. code-block::\n\n    $ python -m compiler_gym.bin.manual_env --env=<env> [--benchmark=<name>] [--observation=<space>] [--reward=<space>]\n\nThe benchmark to use can be specified using :code:`--benchmark=<name>`. If not\nprovided, you be presented with a list of benchmarks to choose from on launch.\nSelect :code:`random` to select a benchmark randomly.\n\"\"\"\nimport sys\nfrom typing import Optional\n\nfrom absl import app, flags\n\nimport compiler_gym.util.flags.ls_benchmark  # Flag definition.\nfrom compiler_gym.envs import CompilerEnv\nfrom compiler_gym.service import observation2str\nfrom compiler_gym.util import user_input\nfrom compiler_gym.util.flags.benchmark_from_flags import benchmark_from_flags\nfrom compiler_gym.util.flags.env_from_flags import env_from_flags\nfrom compiler_gym.util.shell_format import emph\nfrom compiler_gym.util.timer import Timer\n\nFLAGS = flags.FLAGS\n\n\ndef run_manual_env(env: CompilerEnv):\n    \"\"\"Run an environment manually.\n\n    The manual environment allows the user to step through the environment,\n    selection observations, rewards, and actions to run as they see fit. This is\n    useful for debugging.\n\n    :param env: The environment to run.\n    \"\"\"\n    benchmark = None\n    if not env.benchmark:\n        # Allow the user to choose a benchmark, with the first choice being\n        # to select randomly.\n        benchmarks = sorted(env.benchmarks)\n        if not benchmarks:\n            print(\"No benchmarks available see https://facebookresearch.github.io/CompilerGym/getting_started.html#installing-benchmarks\")\n            print(\"Exiting...\")\n            env.close()\n            return\n\n        # Strip default benchmark:// protocol.\n        for i, benchmark in enumerate(benchmarks):\n            if benchmark.startswith(\"benchmark://\"):\n                benchmarks[i] = benchmark[len(\"benchmark://\"):]\n\n        benchmark_index = user_input.read_list_index(\n            \"Benchmark\", [\"random\"] + benchmarks\n        )\n        if benchmark_index:\n            benchmark = benchmarks[benchmark_index - 1]\n        else:\n            benchmark = None\n\n    with Timer() as timer:\n        eager_observation = env.reset(benchmark=benchmark)\n\n    print(f\"Reset {env.benchmark} environment in {timer}\")\n    if env.observation_space and eager_observation is not None:\n        print(\n            f\"Observation: {observation2str(env.observation_space, eager_observation)}\"\n        )\n\n    observation_names = sorted(env.observation.spaces.keys())\n    reward_names = sorted(env.reward.spaces.keys())\n    last_eager_reward: Optional[float] = None\n    step_count = 1\n\n    while True:\n        print(\n            f\"\\nStep {step_count}. Select: [{emph('a')}]ction \"\n            f\"[{emph('o')}]bservation [{emph('r')}]eward \"\n            f\"[{emph('c')}]ommandline [{emph('e')}]nd >>> \",\n            end=\"\",\n            flush=True,\n        )\n        while True:\n            c = user_input.read_char()\n            if c == \"a\":\n                print(\"action\", flush=True)\n                index = user_input.read_list_index(\n                    \"Actions\", [\"random\"] + env.action_space.names\n                )\n                step_count += 1\n                with Timer() as t:\n                    if index == 0:\n                        # User selected \"random\" action.\n                        index = env.action_space.sample()\n                    else:\n                        # Offset to remove \"random\" action from index.\n                        index -= 1\n                    eager_observation, eager_reward, done, info = env.step(index)\n\n                # Print the eager observation, if available.\n                if env.observation_space and eager_observation is not None:\n                    print(\n                        f\"Observation: {observation2str(env.observation_space, eager_observation)}\"\n                    )\n\n                # Print the eager reward and the diff, if available.\n                if env.reward_space and eager_reward is not None:\n                    reward_diff = \"\"\n                    if last_eager_reward is not None and eager_reward is not None:\n                        reward_diff = (\n                            f\" (change: {eager_reward - last_eager_reward:.6f})\"\n                        )\n                    print(f\"Reward: {eager_reward:.6f}{reward_diff}\")\n                    last_eager_reward = eager_reward\n\n                print(\n                    f\"Action {env.action_space.names[index]} in {t}.\",\n                    \" No effect.\" if info.get(\"action_had_no_effect\") else \"\",\n                    flush=True,\n                )\n                if done:\n                    print(\"Episode ended by environment: \", info[\"error_details\"])\n                    env.close()\n                    return\n                break\n            if c == \"o\":\n                print(\"observation\", flush=True)\n                observation_name = user_input.read_list_value(\n                    \"Observable values\", observation_names\n                )\n                with Timer() as timer:\n                    value = env.observation[observation_name]\n                print(\n                    observation2str(env.observation.spaces[observation_name].id, value)\n                )\n                print(f\"Observation {observation_name} in {timer}\")\n                break\n            elif c == \"r\":\n                print(\"reward\", flush=True)\n                reward_name = user_input.read_list_value(\"Rewards\", reward_names)\n                with Timer(f\"Reward {reward_name}\"):\n                    print(f\"{env.reward[reward_name]:.6f}\")\n                break\n            elif c == \"c\":\n                print(\"commandline\")\n                print(\"$\", env.commandline(), flush=True)\n                break\n            elif c == \"e\":\n                print(\"end\", flush=True)\n                with Timer(\"Closed environment\"):\n                    env.close()\n                print(\"Have a nice day!\")\n                return\n\n\ndef main(argv):\n    \"\"\"Main entry point.\"\"\"\n    argv = FLAGS(argv)\n    if len(argv) != 1:\n        raise app.UsageError(f\"Unknown command line arguments: {argv[1:]}\")\n\n    if FLAGS.ls_benchmark:\n        benchmark = benchmark_from_flags()\n        env = env_from_flags(benchmark)\n        print(\"\\n\".join(sorted(env.benchmarks)))\n        env.close()\n        return\n\n    with Timer(\"Initialized environment\"):\n        benchmark = benchmark_from_flags()\n        env = env_from_flags(benchmark)\n\n    run_manual_env(env)\n\n\nif __name__ == \"__main__\":\n    main(sys.argv)\n", "path": "compiler_gym/bin/manual_env.py"}]}