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

Crash on "run_acme_agent.py" #17

Closed
ouya99 opened this issue Jun 22, 2021 · 13 comments
Closed

Crash on "run_acme_agent.py" #17

ouya99 opened this issue Jun 22, 2021 · 13 comments
Labels
good first issue Good for newcomers

Comments

@ouya99
Copy link

ouya99 commented Jun 22, 2021

Hello,

I did install all dependencies for acme and i am running it on python3.8 (linux) using the pong textproto and pong apk

python3 run_acme_agent.py --avd_name='Pixel_XL_API_30' --android_avd_home='/home/username/.android/avd' --android_sdk_root=/home/username/Android/Sdk/ --emulator_path=/home/username/Android/Sdk/emulator/emulator --adb_path=/home/username/Android/Sdk/platform-tools/adb --num_episodes=100 --task_path=/home/username/Dev/android_env/examples/pong_default.textproto

I am getting the following error

I0622 02:01:27.057457 139624755865408 environment.py:37] Action spec: {'action_type': DiscreteArray(shape=(), dtype=int32, name=action_type, minimum=0, maximum=2, num_values=3), 'touch_position': BoundedArray(shape=(2,), dtype=dtype('float32'), name='touch_position', minimum=[0. 0.], maximum=[1. 1.])} I0622 02:01:27.058849 139624755865408 environment.py:38] Observation spec: {'pixels': Array(shape=(2560, 1440, 3), dtype=dtype('uint8'), name='pixels'), 'timedelta': Array(shape=(), dtype=dtype('int64'), name='timedelta'), 'orientation': Array(shape=(4,), dtype=dtype('uint8'), name='orientation')} I0622 02:01:27.059457 139624755865408 environment.py:39] Task extras spec: {'ball': Array(shape=(4,), dtype=dtype('int32'), name='ball'), 'computer': Array(shape=(4,), dtype=dtype('int32'), name='computer'), 'human': Array(shape=(4,), dtype=dtype('int32'), name='human'), 'collision': Array(shape=(1,), dtype=dtype('int32'), name='collision'), 'state': Array(shape=(1,), dtype=dtype('int32'), name='state')} Traceback (most recent call last): File "run_acme_agent.py", line 88, in <module> app.run(main) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 312, in run _run_main(main, args) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 258, in _run_main sys.exit(main(argv)) File "run_acme_agent.py", line 73, in main num_actions=env_spec.actions.num_values), AttributeError: 'dict' object has no attribute 'num_values' I0622 02:01:27.711886 139624755865408 environment.py:127] Cleaning up AndroidEnv...

Thank you for any insights

@kenjitoyama
Copy link
Collaborator

Hello @ouya99, thanks for the report!
@a-gergely

I think we may have a bug in that script. The off-the-shelf Acme agent expects an action spec that's simply a DiscreteArray but we're passing a dict with a single entry action_id whose value is a DiscreteArray.

Can you try adding a FlatInterfaceWrapper to the wrappers applied to the environment before it's passed to the agent? If it works, feel free to send us a PR.

Thanks!

Daniel Toyama

@kenjitoyama kenjitoyama added the good first issue Good for newcomers label Jun 22, 2021
@ouya99
Copy link
Author

ouya99 commented Jun 22, 2021

Hello @kenjitoyama

fixed it applying the FlatInterfaceWrapper

def apply_wrappers(env): """Applies a series of wrappers to the environment.""" env = wrappers.DiscreteActionWrapper(env, action_grid=(10, 10)) env = wrappers.ImageRescaleWrapper(env, zoom_factors=(0.25, 0.25)) env = wrappers.FloatPixelsWrapper(env) env = acme_wrappers.SinglePrecisionWrapper(env) env = wrappers.FlatInterfaceWrapper(env) return env

Now having problems with the following line of code

Traceback (most recent call last): File "run_acme_agent.py", line 89, in <module> app.run(main) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 312, in run _run_main(main, args) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 258, in _run_main sys.exit(main(argv)) File "run_acme_agent.py", line 79, in main loop = acme.EnvironmentLoopV2(env, agent) AttributeError: module 'acme' has no attribute 'EnvironmentLoopV2'

Thanks

@a-gergely
Copy link
Collaborator

Hi @ouya99, nice catch, thank you!
I've added the missing FlatInterfaceWrapper and replaced acme.EnvironmentLoopV2 with acme.EnvironmentLoop.
Let me know if there are any other issues.

@ouya99
Copy link
Author

ouya99 commented Jun 22, 2021

Hello @a-gergely

well, actually after line 78 has been fixed with FlatInterfaceWrapper and line 79 with acme.EnvironmentLoop, the next line 80 is returning the following...

I0622 03:25:05.458233 140354731657024 environment.py:79] Done resetting AndroidEnv. I0622 03:25:05.458609 140354731657024 environment.py:80] ************* NEW EPISODE ************* Traceback (most recent call last): File "run_acme_agent.py", line 89, in <module> app.run(main) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 312, in run _run_main(main, args) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 258, in _run_main sys.exit(main(argv)) File "run_acme_agent.py", line 80, in main loop.run(num_episodes=FLAGS.num_episodes) File "/home/username/.local/lib/python3.8/site-packages/acme/environment_loop.py", line 159, in run result = self.run_episode() File "/home/username/.local/lib/python3.8/site-packages/acme/environment_loop.py", line 87, in run_episode timestep = self._environment.reset() File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/flat_interface_wrapper.py", line 99, in reset timestep = self._env.reset() File "/home/username/.local/lib/python3.8/site-packages/acme/wrappers/single_precision.py", line 40, in reset return self._convert_timestep(self._environment.reset()) File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/float_pixels_wrapper.py", line 56, in reset return self._process_timestep(timestep) File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/float_pixels_wrapper.py", line 52, in _process_timestep observation=self._process_observation(observation)) File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/float_pixels_wrapper.py", line 39, in _process_observation float_pixels = utils.convert_int_to_float( AttributeError: module 'android_env.components.utils' has no attribute 'convert_int_to_float' [reverb/cc/platform/default/server.cc:63] Shutting down replay server

@a-gergely
Copy link
Collaborator

Fix landed!

@ouya99
Copy link
Author

ouya99 commented Jun 22, 2021

@a-gergely
crash landed on 663bf76

I0622 03:47:00.690374 140636814104384 environment.py:79] Done resetting AndroidEnv. I0622 03:47:00.690935 140636814104384 environment.py:80] ************* NEW EPISODE ************* Traceback (most recent call last): File "run_acme_agent.py", line 89, in <module> app.run(main) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 312, in run _run_main(main, args) File "/home/username/.local/lib/python3.8/site-packages/absl/app.py", line 258, in _run_main sys.exit(main(argv)) File "run_acme_agent.py", line 80, in main loop.run(num_episodes=FLAGS.num_episodes) File "/home/username/.local/lib/python3.8/site-packages/acme/environment_loop.py", line 159, in run result = self.run_episode() File "/home/username/.local/lib/python3.8/site-packages/acme/environment_loop.py", line 87, in run_episode timestep = self._environment.reset() File "/home/username/.local/lib/python3.8/site-packages/acme/wrappers/single_precision.py", line 40, in reset return self._convert_timestep(self._environment.reset()) File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/flat_interface_wrapper.py", line 99, in reset timestep = self._env.reset() File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/float_pixels_wrapper.py", line 56, in reset return self._process_timestep(timestep) File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/float_pixels_wrapper.py", line 52, in _process_timestep observation=self._process_observation(observation)) File "/home/username/.local/lib/python3.8/site-packages/android_env/wrappers/float_pixels_wrapper.py", line 39, in _process_observation float_pixels = utils.convert_int_to_float( AttributeError: module 'android_env.components.utils' has no attribute 'convert_int_to_float' [reverb/cc/platform/default/server.cc:63] Shutting down replay server

oh. maybe I need to re-install with "python3 setup.py install". I will try that

@ouya99
Copy link
Author

ouya99 commented Jun 22, 2021

Tested current version cf5f631

All problems fixed. Game with acme support is starting correctly.

After 10-20 seconds though the app crashes (System UI isn't responding)
In the console google-deepmind/reverb#34 occurs and process is killed

@kenjitoyama
Copy link
Collaborator

Right, I'm not sure exactly what's going on if it's an internal Android crash (i.e. not within AndroidEnv's code). Can you try other tasks? We have used 2048, vokram quite extensively internally, so they should be working well (maybe also try other AVDs with different configurations such as smaller resolution screens or higher memory).

If the script is running, I think this bug is resolved. Other problems such as Reverb's error are probably out of the scope from this particular issue.

Cheers!

@ouya99 ouya99 closed this as completed Jun 22, 2021
@ouya99
Copy link
Author

ouya99 commented Jun 22, 2021

@kenjitoyama
Thank you very much. Yes increasing RAM for the AVD and reducing the screen dimensions helped to get it running. A standard Ram of 512 MB for the AVD and device resolution of about 2000x1000 does not seem to work.

Issue closed

@kenjitoyama
Copy link
Collaborator

Cool, glad it worked!

@cupGreek
Copy link

cupGreek commented Mar 3, 2022

I tried installing android_env via pip and followed along this thread. The game is starting but i am getting the following error. Any suggestions is highly appreciated.

Traceback (most recent call last):
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/classic_2048/run_acme_agent.py", line 87, in
app.run(main)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/absl/app.py", line 312, in run
_run_main(main, args)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/absl/app.py", line 258, in _run_main
sys.exit(main(argv))
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/classic_2048/run_acme_agent.py", line 80, in main
loop.run(num_episodes=FLAGS.num_episodes)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/environment_loop.py", line 176, in run
result = self.run_episode()
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/environment_loop.py", line 109, in run_episode
self._actor.observe(action, next_timestep=timestep)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/agents/agent.py", line 77, in observe
self._actor.observe(action, next_timestep)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/agents/tf/actors.py", line 90, in observe
self._adder.add(action, next_timestep)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/adders/reverb/transition.py", line 133, in add
super().add(*args, **kwargs)
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/adders/reverb/base.py", line 207, in add
self._write()
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/acme/adders/reverb/transition.py", line 205, in _write
self._writer.create_item(
File "/home/cupgreek/Projects/Virtusa/Automation-in-Game-Testing-main/Battle_Star/acme/lib/python3.9/site-packages/reverb/trajectory_writer.py", line 344, in create_item
self._writer.CreateItem(table, priority,
ValueError: Unable to create item in table 'priority_table' since the provided trajectory is inconsistent with the table signature. The table expects column 2 to be a double [] tensor but got a float [] tensor.

The table signature is:
0: Tensor<name: 'observation/observation', dtype: float, shape: [480,270,3]>, 1: Tensor<name: 'action/action', dtype: int32, shape: []>, 2: Tensor<name: 'reward/reward', dtype: double, shape: []>, 3: Tensor<name: 'discount/discount', dtype: double, shape: []>, 4: Tensor<name: 'next_observation/next_observation', dtype: float, shape: [480,270,3]>

The provided trajectory signature is:
0: Tensor<name: '0', dtype: float, shape: [480,270,3]>, 1: Tensor<name: '1', dtype: int32, shape: []>, 2: Tensor<name: '2', dtype: float, shape: []>, 3: Tensor<name: '3', dtype: float, shape: []>, 4: Tensor<name: '4', dtype: float, shape: [480,270,3]>.

[reverb/cc/platform/default/server.cc:84] Shutting down replay server
I0303 13:22:19.591461 140332790426624 environment.py:127] Cleaning up AndroidEnv...
I0303 13:22:19.592031 140332790426624 thread_function.py:88] Killing logcat thread
I0303 13:22:19.592403 140332790426624 thread_function.py:88] Killing dumpsys thread
I0303 13:22:19.592731 140332790426624 adb_controller.py:101] Closing ADB controller...
I0303 13:22:19.592979 140332790426624 adb_controller.py:107] Done closing ADB controller.
I0303 13:22:19.593255 140332790426624 environment.py:130] Done cleaning up AndroidEnv.

@kenjitoyama
Copy link
Collaborator

Hi @cupGreek, this error seems unrelated to AndroidEnv. It's crashing in Reverb.

From the little I see from the stack trace, it looks like there is a mismatch with the names of the tensors. Reverb is expecting named tensors like "observation" and "action", but it's getting names like "0" and "1". I'm not sure if they changed something in Acme that could be causing this.

On our side, we should probably use their JAX agents instead of TF, since JAX has received more love in the last few years.

@kenjitoyama
Copy link
Collaborator

I created #23 to track the migration from TF to JAX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants