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

Minimal Working Example of client.py #56

Closed
RylanSchaeffer opened this issue Jun 7, 2019 · 18 comments
Closed

Minimal Working Example of client.py #56

RylanSchaeffer opened this issue Jun 7, 2019 · 18 comments

Comments

@RylanSchaeffer
Copy link

RylanSchaeffer commented Jun 7, 2019

The example client.py script in the README.md (copied below) has a number of ambiguous and problematic aspects. Where should this script be located within the repo? Should protobuf be replaced with protos? Why does my IDS say Unresolved reference 'await'?

Could we have a minimal working example? I discovered this old example, but it appears to have been removed.

from grpclib.client import Channel
from protobuf.DotaService_grpc import DotaServiceStub
from protobuf.DotaService_pb2 import Action
from protobuf.DotaService_pb2 import Config

# Connect to the DotaService.
env = DotaServiceStub(Channel('127.0.0.1', 13337))

# Get the initial observation.
observation = await env.reset(Config())
for i in range(8):
    # Sample an action from the action protobuf
    action = Action.MoveToLocation(x=.., y=.., z=..)
    # Take an action, returning the resulting observation.
    observation = await env.step(action)
@TimZaman
Copy link
Owner

TimZaman commented Jun 7, 2019 via email

@TimZaman
Copy link
Owner

TimZaman commented Jun 7, 2019 via email

@RylanSchaeffer
Copy link
Author

I upgraded to Python 3.7 and tried compiling the protos, but received the following error:

/usr/bin/python3.7: Error while finding module specification for 'grpc_tools.protoc' (ModuleNotFoundError: No module named 'grpc_tools')

@RylanSchaeffer
Copy link
Author

We had to additionally run python -m pip install grpcio and python -m pip install grpcio-tools.

@TimZaman
Copy link
Owner

TimZaman commented Jun 8, 2019 via email

@joaquingx
Copy link

I got this error with old client.py :
ImportError: cannot import name 'Action' from 'dotaservice.protos.DotaService_pb2' (/home/user/.local/lib/python3.7/site-packages/dotaservice/protos/DotaService_pb2.py)

@bglick13
Copy link

@RylanSchaeffer did you ever get a minimal working example running?

I'm hoping to use this just to quickly spin up bot vs bot games. I'm sure it should be doable relatively easily. I runnable example I can play with would be extremely helpful though.

@RylanSchaeffer
Copy link
Author

Yeah, but it wasn't straightforward and I couldn't do what I subsequently wanted, so eventually I gave up :/

@bglick13
Copy link

Would you mind sharing what you had?

I'm getting this error:

Exception on env.reset: [Errno 61] Connect call failed ('127.0.0.1', 13337)

I'd love to just get a really basic toy example running

@TimZaman
Copy link
Owner

It's been a while since i looked at this sorry guys :(

@RylanSchaeffer
Copy link
Author

RylanSchaeffer commented Sep 25, 2019 via email

@Nostrademous
Copy link
Collaborator

what are you guys trying to do?

@bglick13
Copy link

bglick13 commented Oct 4, 2019

Nostrademous,

I'm working on an AI project specifically for draft strategy. All I want to be able to do is spin up bot vs bot games with specified heroes and record the outcome.

@Nostrademous
Copy link
Collaborator

@bglick13 what problems did you and @RylanSchaeffer have?

I have no issues running the code as currently checked in locally. Note, I do not run it via docker.

@bglick13
Copy link

@Nostrademous I appreciate you getting back to me!

I suppose my issues are in understanding how to actually start simulating games. I can clone the repo and run python3 -m dotaservice successfully, but it is unclear to me how to then spin up games from there.

Do you have an example client script you're using, or think you could explain how to write a client script that just starts bot games? I understand my use case is a bit strange, since I'm not actually implementing my own agent to act inside the environment, but I assume it should still be doable.

Thanks again!

@Nostrademous
Copy link
Collaborator

Nostrademous commented Oct 11, 2019

You need to run three separate python modules. They are spread across two repos: DotaService and DotaClient (both maintained by Tim and Cloned by me as I do some of my own tweaks).

  1. DotaService - python3 -m dotaservice after pip3 install -e . in the dotaservice directory to locally compile the pip module. This creates all the plumbing to communicate with the Dota2 Client itself and setups the game to launch and configures it to use protobuf sockets for Radiant and Dire to report world state messages at some frequency (specified in a configuration file)

  2. DotaClient optimizer - python3 optimizer.py --run-local 1 is what I use. This runs one instance locally on your machine. If you don't specify --run-local 1 it will check for a Google Cloud Platform API key in your environment so that it can use cloud storage for sharing model data between multiple cloud instances of the learned agent. Note the optimizer uses RabbitMQ which needs to be installed and default setup for it to check in properly. Directions are somewhere in the DotaClient repo.

  3. DotaClient Agent - python3 agent.py This creates an instance of the agent that waits for information about world state from DotaService on a socket and then parses it, interprets it, decides an action and does it.

@Nostrademous
Copy link
Collaborator

Nostrademous commented Oct 11, 2019

A lot of this was documented here by me:
TimZaman/dotaclient#2 (specially comment number 2)

All the code changes to remove GCP are un-needed as we added the run-local parameter after that so the client can run without GCP.

Note, that once you get it up and running and want to see the bots fight you need to change the mode from DEDICATED to GUI and then once you are logged in you need to type jointeam spec in the console in-game to remove fog of war. You can manually set the speed of the game too in the console using host_timescale <NUM> (1 to 10) is sufficient.

The mode setting is done by the agent (which writes the configuration file to launch Dota2 with)
Here: https://github.com/TimZaman/dotaclient/blob/master/agent.py#L59

@bglick13
Copy link

Works like a charm! I really appreciate you taking the time to provide such thorough responses

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

No branches or pull requests

5 participants