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

add selfplay test #275

Merged
merged 8 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: do_unittest
timeout-minutes: 40
run: |
xvfb-run -s "-screen 0 1400x900x24" python3 -m pytest tests --cov=openrl --cov-report=xml -m unittest --cov-report=term-missing --durations=0 -v --color=yes
xvfb-run -s "-screen 0 1400x900x24" python3 -m pytest tests --cov=openrl --cov-report=xml -m unittest --cov-report=term-missing --durations=0 -v --color=yes -s
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion examples/selfplay/selfplay.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
globals:
selfplay_api_host: 127.0.0.1
selfplay_api_port: 10086
selfplay_api_port: 13486

seed: 0
selfplay_api:
Expand Down
8 changes: 6 additions & 2 deletions openrl/selfplay/callbacks/selfplay_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@
)

self.bind = SelfplayAPIServer.bind()
serve.run(self.bind)
serve.run(self.bind, route_prefix="/selfplay")
success = False
try_time = 10
while not success:
success = self.api_client.set_sample_strategy(self.sample_strategy)
try_time -= 1
if try_time <= 0:
raise RuntimeError("Failed to set sample strategy.")
raise RuntimeError(

Check warning on line 60 in openrl/selfplay/callbacks/selfplay_api.py

View check run for this annotation

Codecov / codecov/patch

openrl/selfplay/callbacks/selfplay_api.py#L60

Added line #L60 was not covered by tests
f"Failed to set sample strategy: {self.sample_strategy}. host:"
f" {self.host}, port: {self.port}"
)

def _on_step(self) -> bool:
# print("To send request to API server.")
Expand All @@ -72,5 +75,6 @@
print(f"deleting {application_name}")
serve.delete(application_name)
del self.bind
serve.shutdown()
if self.verbose >= 2:
print(f"delete {application_name} done!")
3 changes: 3 additions & 0 deletions openrl/selfplay/opponents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@


def check_opponent_template(opponent_template: Union[str, Path]):
assert isinstance(opponent_template, Path) or isinstance(
opponent_template, str
), f"opponent_template {opponent_template} must be a Path or str"
if isinstance(opponent_template, str):
opponent_template = Path(opponent_template)
assert (
Expand Down
2 changes: 1 addition & 1 deletion openrl/selfplay/selfplay_api/selfplay_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from openrl.selfplay.selfplay_api.opponent_model import BattleResult


@serve.deployment(route_prefix="/selfplay")
@serve.deployment()
@serve.ingress(app)
class SelfplayAPIServer(BaseSelfplayAPIServer):
@app.post("/set_sample_strategy")
Expand Down
41 changes: 0 additions & 41 deletions openrl/selfplay/strategies/__init__.py

This file was deleted.

39 changes: 0 additions & 39 deletions openrl/selfplay/strategies/base_strategy.py

This file was deleted.

Loading