Skip to content

Commit 91ac0df

Browse files
authored
add selfplay test
add selfplay test
2 parents ceae61a + 714a9ec commit 91ac0df

11 files changed

Lines changed: 162 additions & 592 deletions

File tree

.github/workflows/unit_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: do_unittest
3232
timeout-minutes: 40
3333
run: |
34-
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
34+
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
3535
- name: Upload coverage reports to Codecov with GitHub Action
3636
uses: codecov/codecov-action@v3
3737
with:

examples/selfplay/selfplay.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
globals:
22
selfplay_api_host: 127.0.0.1
3-
selfplay_api_port: 10086
3+
selfplay_api_port: 13486
44

55
seed: 0
66
selfplay_api:

openrl/selfplay/callbacks/selfplay_api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ def _init_callback(self) -> None:
5050
)
5151

5252
self.bind = SelfplayAPIServer.bind()
53-
serve.run(self.bind)
53+
serve.run(self.bind, route_prefix="/selfplay")
5454
success = False
5555
try_time = 10
5656
while not success:
5757
success = self.api_client.set_sample_strategy(self.sample_strategy)
5858
try_time -= 1
5959
if try_time <= 0:
60-
raise RuntimeError("Failed to set sample strategy.")
60+
raise RuntimeError(
61+
f"Failed to set sample strategy: {self.sample_strategy}. host:"
62+
f" {self.host}, port: {self.port}"
63+
)
6164

6265
def _on_step(self) -> bool:
6366
# print("To send request to API server.")
@@ -72,5 +75,6 @@ def _on_training_end(self) -> None:
7275
print(f"deleting {application_name}")
7376
serve.delete(application_name)
7477
del self.bind
78+
serve.shutdown()
7579
if self.verbose >= 2:
7680
print(f"delete {application_name} done!")

openrl/selfplay/opponents/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929

3030
def check_opponent_template(opponent_template: Union[str, Path]):
31+
assert isinstance(opponent_template, Path) or isinstance(
32+
opponent_template, str
33+
), f"opponent_template {opponent_template} must be a Path or str"
3134
if isinstance(opponent_template, str):
3235
opponent_template = Path(opponent_template)
3336
assert (

openrl/selfplay/selfplay_api/selfplay_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from openrl.selfplay.selfplay_api.opponent_model import BattleResult
3434

3535

36-
@serve.deployment(route_prefix="/selfplay")
36+
@serve.deployment()
3737
@serve.ingress(app)
3838
class SelfplayAPIServer(BaseSelfplayAPIServer):
3939
@app.post("/set_sample_strategy")

openrl/selfplay/strategies/__init__.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

openrl/selfplay/strategies/base_strategy.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)