cuju-engine 0.3.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cuju/__init__.py +217 -0
- cuju/__main__.py +262 -0
- cuju/_batch/__init__.py +4 -0
- cuju/_batch/allocator.py +52 -0
- cuju/_batch/assets.py +68 -0
- cuju/_batch/environment.py +1890 -0
- cuju/_batch/frame_stack.py +114 -0
- cuju/_batch/library.py +190 -0
- cuju/_batch/log.py +103 -0
- cuju/_batch/memory.py +70 -0
- cuju/_batch/operators.py +55 -0
- cuju/_batch/pinned.py +39 -0
- cuju/_batch/pixels.py +207 -0
- cuju/_batch/state.py +77 -0
- cuju/_checksums.py +60 -0
- cuju/_cli_contract.py +244 -0
- cuju/_cli_parsers.py +191 -0
- cuju/_completion.py +277 -0
- cuju/_dump_to_txt.py +66 -0
- cuju/_grf_config.py +331 -0
- cuju/_library_path.py +141 -0
- cuju/_media.py +113 -0
- cuju/_pixels.py +276 -0
- cuju/_plugins.py +106 -0
- cuju/_python_players.py +224 -0
- cuju/_replay_command.py +109 -0
- cuju/_replay_player.py +42 -0
- cuju/_replays.py +414 -0
- cuju/_script_helpers.py +109 -0
- cuju/_version.py +6 -0
- cuju/action_log.py +371 -0
- cuju/check.py +596 -0
- cuju/cuju_cpu.dll +0 -0
- cuju/cuju_cuda.dll +0 -0
- cuju/cuju_render.dll +0 -0
- cuju/data/SHA256SUMS +20 -0
- cuju/data/animations.bin +0 -0
- cuju/data/assets/11_vs_11_competition_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_easy_stochastic_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_hard_stochastic_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_kaggle_l0_r0.cjb +0 -0
- cuju/data/assets/11_vs_11_stochastic_l0_r0.cjb +0 -0
- cuju/data/assets/1_vs_1_easy_l0_r0.cjb +0 -0
- cuju/data/assets/5_vs_5_l0_r0.cjb +0 -0
- cuju/data/assets/academy_3_vs_1_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_corner_l0_r0.cjb +0 -0
- cuju/data/assets/academy_counterattack_easy_l0_r0.cjb +0 -0
- cuju/data/assets/academy_counterattack_hard_l0_r0.cjb +0 -0
- cuju/data/assets/academy_empty_goal_close_l0_r0.cjb +0 -0
- cuju/data/assets/academy_empty_goal_l0_r0.cjb +0 -0
- cuju/data/assets/academy_pass_and_shoot_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_run_pass_and_shoot_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_run_to_score_l0_r0.cjb +0 -0
- cuju/data/assets/academy_run_to_score_with_keeper_l0_r0.cjb +0 -0
- cuju/data/assets/academy_single_goal_versus_lazy_l0_r0.cjb +0 -0
- cuju/data/assets/test_example_multiagent_l0_r0.cjb +0 -0
- cuju/data/digests.json +186 -0
- cuju/data/render_digests.json.z +0 -0
- cuju/data/scenarios/11_vs_11_competition.py +45 -0
- cuju/data/scenarios/11_vs_11_easy_stochastic.py +44 -0
- cuju/data/scenarios/11_vs_11_hard_stochastic.py +44 -0
- cuju/data/scenarios/11_vs_11_kaggle.py +46 -0
- cuju/data/scenarios/11_vs_11_stochastic.py +44 -0
- cuju/data/scenarios/1_vs_1_easy.py +25 -0
- cuju/data/scenarios/5_vs_5.py +33 -0
- cuju/data/scenarios/academy_3_vs_1_with_keeper.py +28 -0
- cuju/data/scenarios/academy_corner.py +45 -0
- cuju/data/scenarios/academy_counterattack_easy.py +45 -0
- cuju/data/scenarios/academy_counterattack_hard.py +45 -0
- cuju/data/scenarios/academy_empty_goal.py +25 -0
- cuju/data/scenarios/academy_empty_goal_close.py +25 -0
- cuju/data/scenarios/academy_pass_and_shoot_with_keeper.py +27 -0
- cuju/data/scenarios/academy_run_pass_and_shoot_with_keeper.py +27 -0
- cuju/data/scenarios/academy_run_to_score.py +30 -0
- cuju/data/scenarios/academy_run_to_score_with_keeper.py +30 -0
- cuju/data/scenarios/academy_single_goal_versus_lazy.py +49 -0
- cuju/data/scenarios/test_example_multiagent.py +28 -0
- cuju/dumps.py +942 -0
- cuju/engine_status.py +106 -0
- cuju/env.py +1168 -0
- cuju/errors.py +108 -0
- cuju/gfootball/GRF_SOURCES +86 -0
- cuju/gfootball/__init__.py +60 -0
- cuju/gfootball/_cv2.py +43 -0
- cuju/gfootball/_gym/__init__.py +88 -0
- cuju/gfootball/_gym/_vendored/GYM_SOURCES +22 -0
- cuju/gfootball/_gym/_vendored/__init__.py +43 -0
- cuju/gfootball/_gym/_vendored/core.py +361 -0
- cuju/gfootball/_gym/_vendored/envs/__init__.py +19 -0
- cuju/gfootball/_gym/_vendored/envs/registration.py +284 -0
- cuju/gfootball/_gym/_vendored/error.py +230 -0
- cuju/gfootball/_gym/_vendored/logger.py +56 -0
- cuju/gfootball/_gym/_vendored/spaces/__init__.py +30 -0
- cuju/gfootball/_gym/_vendored/spaces/box.py +171 -0
- cuju/gfootball/_gym/_vendored/spaces/dict.py +162 -0
- cuju/gfootball/_gym/_vendored/spaces/discrete.py +41 -0
- cuju/gfootball/_gym/_vendored/spaces/multi_binary.py +61 -0
- cuju/gfootball/_gym/_vendored/spaces/multi_discrete.py +77 -0
- cuju/gfootball/_gym/_vendored/spaces/space.py +94 -0
- cuju/gfootball/_gym/_vendored/spaces/tuple.py +96 -0
- cuju/gfootball/_gym/_vendored/spaces/utils.py +228 -0
- cuju/gfootball/_gym/_vendored/utils/__init__.py +13 -0
- cuju/gfootball/_gym/_vendored/utils/closer.py +72 -0
- cuju/gfootball/_gym/_vendored/utils/colorize.py +36 -0
- cuju/gfootball/_gym/_vendored/utils/ezpickle.py +37 -0
- cuju/gfootball/_gym/_vendored/utils/json_utils.py +27 -0
- cuju/gfootball/_gym/_vendored/utils/seeding.py +101 -0
- cuju/gfootball/_gym/_vendored/version.py +5 -0
- cuju/gfootball/_gym/_vendored/wrappers/__init__.py +8 -0
- cuju/gfootball/_gym/_vendored/wrappers/order_enforcing.py +20 -0
- cuju/gfootball/_gym/_vendored/wrappers/time_limit.py +31 -0
- cuju/gfootball/dump_to_txt.py +49 -0
- cuju/gfootball/dump_to_video.py +33 -0
- cuju/gfootball/env/__init__.py +271 -0
- cuju/gfootball/env/config.py +163 -0
- cuju/gfootball/env/constants.py +33 -0
- cuju/gfootball/env/controller_base.py +114 -0
- cuju/gfootball/env/event_queue.py +54 -0
- cuju/gfootball/env/football_action_set.py +220 -0
- cuju/gfootball/env/football_action_set_test.py +76 -0
- cuju/gfootball/env/football_env.py +225 -0
- cuju/gfootball/env/football_env_core.py +447 -0
- cuju/gfootball/env/football_env_test.py +692 -0
- cuju/gfootball/env/gym_test.py +47 -0
- cuju/gfootball/env/observation_preprocessing.py +94 -0
- cuju/gfootball/env/observation_processor.py +526 -0
- cuju/gfootball/env/observation_rotation.py +163 -0
- cuju/gfootball/env/observation_rotation_test.py +84 -0
- cuju/gfootball/env/player_base.py +46 -0
- cuju/gfootball/env/players/__init__.py +16 -0
- cuju/gfootball/env/players/agent.py +39 -0
- cuju/gfootball/env/players/bot.py +217 -0
- cuju/gfootball/env/players/gamepad.py +81 -0
- cuju/gfootball/env/players/keyboard.py +72 -0
- cuju/gfootball/env/players/lazy.py +31 -0
- cuju/gfootball/env/players/ppo2_cnn.py +119 -0
- cuju/gfootball/env/players/replay.py +40 -0
- cuju/gfootball/env/remote_football_env.py +189 -0
- cuju/gfootball/env/scenario_builder.py +125 -0
- cuju/gfootball/env/script_helpers.py +130 -0
- cuju/gfootball/env/script_helpers_test.py +107 -0
- cuju/gfootball/env/wrappers.py +440 -0
- cuju/gfootball/env/wrappers_test.py +150 -0
- cuju/gfootball/eval_server/__init__.py +17 -0
- cuju/gfootball/eval_server/config.py +30 -0
- cuju/gfootball/eval_server/example_client.py +107 -0
- cuju/gfootball/eval_server/proto/game_server.proto +62 -0
- cuju/gfootball/eval_server/proto/game_server_pb2.py +501 -0
- cuju/gfootball/eval_server/proto/game_server_pb2_grpc.py +113 -0
- cuju/gfootball/eval_server/proto/master.proto +25 -0
- cuju/gfootball/eval_server/proto/master_pb2.py +184 -0
- cuju/gfootball/eval_server/proto/master_pb2_grpc.py +62 -0
- cuju/gfootball/eval_server/utils.py +52 -0
- cuju/gfootball/examples/__init__.py +16 -0
- cuju/gfootball/examples/models.py +66 -0
- cuju/gfootball/examples/run_multiagent_rllib.py +140 -0
- cuju/gfootball/examples/run_ppo2.py +123 -0
- cuju/gfootball/play_game.py +73 -0
- cuju/gfootball/replay.py +43 -0
- cuju/gfootball/scenarios/11_vs_11_competition.py +59 -0
- cuju/gfootball/scenarios/11_vs_11_easy_stochastic.py +57 -0
- cuju/gfootball/scenarios/11_vs_11_hard_stochastic.py +57 -0
- cuju/gfootball/scenarios/11_vs_11_kaggle.py +60 -0
- cuju/gfootball/scenarios/11_vs_11_stochastic.py +57 -0
- cuju/gfootball/scenarios/1_vs_1_easy.py +39 -0
- cuju/gfootball/scenarios/5_vs_5.py +46 -0
- cuju/gfootball/scenarios/__init__.py +31 -0
- cuju/gfootball/scenarios/academy_3_vs_1_with_keeper.py +42 -0
- cuju/gfootball/scenarios/academy_corner.py +59 -0
- cuju/gfootball/scenarios/academy_counterattack_easy.py +59 -0
- cuju/gfootball/scenarios/academy_counterattack_hard.py +59 -0
- cuju/gfootball/scenarios/academy_empty_goal.py +39 -0
- cuju/gfootball/scenarios/academy_empty_goal_close.py +39 -0
- cuju/gfootball/scenarios/academy_pass_and_shoot_with_keeper.py +41 -0
- cuju/gfootball/scenarios/academy_run_pass_and_shoot_with_keeper.py +41 -0
- cuju/gfootball/scenarios/academy_run_to_score.py +44 -0
- cuju/gfootball/scenarios/academy_run_to_score_with_keeper.py +44 -0
- cuju/gfootball/scenarios/academy_single_goal_versus_lazy.py +63 -0
- cuju/gfootball/scenarios/test_example_multiagent.py +42 -0
- cuju/gfootball/scenarios/tests/11_vs_11_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_easy_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_hard_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_single_goal_deterministic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_11_single_goal_stochastic.py +58 -0
- cuju/gfootball/scenarios/tests/11_vs_4_offence_deterministic.py +47 -0
- cuju/gfootball/scenarios/tests/11_vs_4_offence_stochastic.py +47 -0
- cuju/gfootball/scenarios/tests/__init__.py +31 -0
- cuju/gfootball/scenarios/tests/corner_test.py +38 -0
- cuju/gfootball/scenarios/tests/goal_test.py +35 -0
- cuju/gfootball/scenarios/tests/keeper_test.py +38 -0
- cuju/gfootball/scenarios/tests/kickoff_for_goal_loosing_team_test.py +34 -0
- cuju/gfootball/scenarios/tests/multiagent_wrapper.py +60 -0
- cuju/gfootball/scenarios/tests/offside_test.py +39 -0
- cuju/gfootball/scenarios/tests/penalty.py +34 -0
- cuju/gfootball/scenarios/tests/second_half.py +33 -0
- cuju/gfootball/scenarios/tests/symmetric.py +53 -0
- cuju/gfootball_engine/__init__.py +31 -0
- cuju/gfootball_engine/_gameplayfootball.py +1624 -0
- cuju/gfootball_engine/_native.py +193 -0
- cuju/gfootball_engine/_pickle_names.py +114 -0
- cuju/gfootball_engine/_render_hooks.py +156 -0
- cuju/kaggle.py +425 -0
- cuju/multi_device.py +401 -0
- cuju/players.py +260 -0
- cuju/raw.py +93 -0
- cuju/scenarios.py +661 -0
- cuju/state.py +211 -0
- cuju/wrappers.py +325 -0
- cuju_engine-0.3.0.dist-info/METADATA +325 -0
- cuju_engine-0.3.0.dist-info/RECORD +222 -0
- cuju_engine-0.3.0.dist-info/WHEEL +5 -0
- cuju_engine-0.3.0.dist-info/entry_points.txt +4 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSE +202 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +31 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/BSL-1.0.txt +23 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/LGPL-2.1-or-later.txt +502 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT-Mesa.txt +26 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT-gym.txt +23 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/MIT.txt +23 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/SunPro.txt +8 -0
- cuju_engine-0.3.0.dist-info/licenses/LICENSES/Zlib.txt +20 -0
- cuju_engine-0.3.0.dist-info/licenses/NOTICE +56 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
# -*- coding: utf-8 -*-
|
|
18
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
19
|
+
# source: gfootball/eval_server/proto/master.proto
|
|
20
|
+
|
|
21
|
+
import sys
|
|
22
|
+
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
|
23
|
+
from google.protobuf import descriptor as _descriptor
|
|
24
|
+
from google.protobuf import message as _message
|
|
25
|
+
from google.protobuf import reflection as _reflection
|
|
26
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
27
|
+
# @@protoc_insertion_point(imports)
|
|
28
|
+
|
|
29
|
+
_sym_db = _symbol_database.Default()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
DESCRIPTOR = _descriptor.FileDescriptor(
|
|
35
|
+
name='gfootball/eval_server/proto/master.proto',
|
|
36
|
+
package='gfootball.eval_server',
|
|
37
|
+
syntax='proto3',
|
|
38
|
+
serialized_options=None,
|
|
39
|
+
serialized_pb=_b('\n(gfootball/eval_server/proto/master.proto\x12\x15gfootball.eval_server\"x\n\x10StartGameRequest\x12\x14\n\x0cgame_version\x18\x01 \x01(\t\x12\x10\n\x08username\x18\x02 \x01(\t\x12\r\n\x05token\x18\x03 \x01(\t\x12\x12\n\nmodel_name\x18\x04 \x01(\t\x12\x19\n\x11include_rendering\x18\x05 \x01(\x08\"A\n\x11StartGameResponse\x12\x1b\n\x13game_server_address\x18\x01 \x01(\t\x12\x0f\n\x07game_id\x18\x02 \x01(\t2j\n\x06Master\x12`\n\tStartGame\x12\'.gfootball.eval_server.StartGameRequest\x1a(.gfootball.eval_server.StartGameResponse\"\x00\x62\x06proto3')
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_STARTGAMEREQUEST = _descriptor.Descriptor(
|
|
46
|
+
name='StartGameRequest',
|
|
47
|
+
full_name='gfootball.eval_server.StartGameRequest',
|
|
48
|
+
filename=None,
|
|
49
|
+
file=DESCRIPTOR,
|
|
50
|
+
containing_type=None,
|
|
51
|
+
fields=[
|
|
52
|
+
_descriptor.FieldDescriptor(
|
|
53
|
+
name='game_version', full_name='gfootball.eval_server.StartGameRequest.game_version', index=0,
|
|
54
|
+
number=1, type=9, cpp_type=9, label=1,
|
|
55
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
56
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
57
|
+
is_extension=False, extension_scope=None,
|
|
58
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
59
|
+
_descriptor.FieldDescriptor(
|
|
60
|
+
name='username', full_name='gfootball.eval_server.StartGameRequest.username', index=1,
|
|
61
|
+
number=2, type=9, cpp_type=9, label=1,
|
|
62
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
63
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
64
|
+
is_extension=False, extension_scope=None,
|
|
65
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
66
|
+
_descriptor.FieldDescriptor(
|
|
67
|
+
name='token', full_name='gfootball.eval_server.StartGameRequest.token', index=2,
|
|
68
|
+
number=3, type=9, cpp_type=9, label=1,
|
|
69
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
70
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
71
|
+
is_extension=False, extension_scope=None,
|
|
72
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
73
|
+
_descriptor.FieldDescriptor(
|
|
74
|
+
name='model_name', full_name='gfootball.eval_server.StartGameRequest.model_name', index=3,
|
|
75
|
+
number=4, type=9, cpp_type=9, label=1,
|
|
76
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
77
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
78
|
+
is_extension=False, extension_scope=None,
|
|
79
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
80
|
+
_descriptor.FieldDescriptor(
|
|
81
|
+
name='include_rendering', full_name='gfootball.eval_server.StartGameRequest.include_rendering', index=4,
|
|
82
|
+
number=5, type=8, cpp_type=7, label=1,
|
|
83
|
+
has_default_value=False, default_value=False,
|
|
84
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
85
|
+
is_extension=False, extension_scope=None,
|
|
86
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
87
|
+
],
|
|
88
|
+
extensions=[
|
|
89
|
+
],
|
|
90
|
+
nested_types=[],
|
|
91
|
+
enum_types=[
|
|
92
|
+
],
|
|
93
|
+
serialized_options=None,
|
|
94
|
+
is_extendable=False,
|
|
95
|
+
syntax='proto3',
|
|
96
|
+
extension_ranges=[],
|
|
97
|
+
oneofs=[
|
|
98
|
+
],
|
|
99
|
+
serialized_start=67,
|
|
100
|
+
serialized_end=187,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
_STARTGAMERESPONSE = _descriptor.Descriptor(
|
|
105
|
+
name='StartGameResponse',
|
|
106
|
+
full_name='gfootball.eval_server.StartGameResponse',
|
|
107
|
+
filename=None,
|
|
108
|
+
file=DESCRIPTOR,
|
|
109
|
+
containing_type=None,
|
|
110
|
+
fields=[
|
|
111
|
+
_descriptor.FieldDescriptor(
|
|
112
|
+
name='game_server_address', full_name='gfootball.eval_server.StartGameResponse.game_server_address', index=0,
|
|
113
|
+
number=1, type=9, cpp_type=9, label=1,
|
|
114
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
115
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
116
|
+
is_extension=False, extension_scope=None,
|
|
117
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
118
|
+
_descriptor.FieldDescriptor(
|
|
119
|
+
name='game_id', full_name='gfootball.eval_server.StartGameResponse.game_id', index=1,
|
|
120
|
+
number=2, type=9, cpp_type=9, label=1,
|
|
121
|
+
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
122
|
+
message_type=None, enum_type=None, containing_type=None,
|
|
123
|
+
is_extension=False, extension_scope=None,
|
|
124
|
+
serialized_options=None, file=DESCRIPTOR),
|
|
125
|
+
],
|
|
126
|
+
extensions=[
|
|
127
|
+
],
|
|
128
|
+
nested_types=[],
|
|
129
|
+
enum_types=[
|
|
130
|
+
],
|
|
131
|
+
serialized_options=None,
|
|
132
|
+
is_extendable=False,
|
|
133
|
+
syntax='proto3',
|
|
134
|
+
extension_ranges=[],
|
|
135
|
+
oneofs=[
|
|
136
|
+
],
|
|
137
|
+
serialized_start=189,
|
|
138
|
+
serialized_end=254,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
DESCRIPTOR.message_types_by_name['StartGameRequest'] = _STARTGAMEREQUEST
|
|
142
|
+
DESCRIPTOR.message_types_by_name['StartGameResponse'] = _STARTGAMERESPONSE
|
|
143
|
+
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
|
144
|
+
|
|
145
|
+
StartGameRequest = _reflection.GeneratedProtocolMessageType('StartGameRequest', (_message.Message,), {
|
|
146
|
+
'DESCRIPTOR' : _STARTGAMEREQUEST,
|
|
147
|
+
'__module__' : 'cuju.gfootball.eval_server.proto.master_pb2'
|
|
148
|
+
# @@protoc_insertion_point(class_scope:gfootball.eval_server.StartGameRequest)
|
|
149
|
+
})
|
|
150
|
+
_sym_db.RegisterMessage(StartGameRequest)
|
|
151
|
+
|
|
152
|
+
StartGameResponse = _reflection.GeneratedProtocolMessageType('StartGameResponse', (_message.Message,), {
|
|
153
|
+
'DESCRIPTOR' : _STARTGAMERESPONSE,
|
|
154
|
+
'__module__' : 'cuju.gfootball.eval_server.proto.master_pb2'
|
|
155
|
+
# @@protoc_insertion_point(class_scope:gfootball.eval_server.StartGameResponse)
|
|
156
|
+
})
|
|
157
|
+
_sym_db.RegisterMessage(StartGameResponse)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
_MASTER = _descriptor.ServiceDescriptor(
|
|
162
|
+
name='Master',
|
|
163
|
+
full_name='gfootball.eval_server.Master',
|
|
164
|
+
file=DESCRIPTOR,
|
|
165
|
+
index=0,
|
|
166
|
+
serialized_options=None,
|
|
167
|
+
serialized_start=256,
|
|
168
|
+
serialized_end=362,
|
|
169
|
+
methods=[
|
|
170
|
+
_descriptor.MethodDescriptor(
|
|
171
|
+
name='StartGame',
|
|
172
|
+
full_name='gfootball.eval_server.Master.StartGame',
|
|
173
|
+
index=0,
|
|
174
|
+
containing_service=None,
|
|
175
|
+
input_type=_STARTGAMEREQUEST,
|
|
176
|
+
output_type=_STARTGAMERESPONSE,
|
|
177
|
+
serialized_options=None,
|
|
178
|
+
),
|
|
179
|
+
])
|
|
180
|
+
_sym_db.RegisterServiceDescriptor(_MASTER)
|
|
181
|
+
|
|
182
|
+
DESCRIPTOR.services_by_name['Master'] = _MASTER
|
|
183
|
+
|
|
184
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
|
18
|
+
import grpc
|
|
19
|
+
|
|
20
|
+
from cuju.gfootball.eval_server.proto import master_pb2 as gfootball_dot_eval__server_dot_proto_dot_master__pb2
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class MasterStub(object):
|
|
24
|
+
# missing associated documentation comment in .proto file
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
def __init__(self, channel):
|
|
28
|
+
"""Constructor.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
channel: A grpc.Channel.
|
|
32
|
+
"""
|
|
33
|
+
self.StartGame = channel.unary_unary(
|
|
34
|
+
'/gfootball.eval_server.Master/StartGame',
|
|
35
|
+
request_serializer=gfootball_dot_eval__server_dot_proto_dot_master__pb2.StartGameRequest.SerializeToString,
|
|
36
|
+
response_deserializer=gfootball_dot_eval__server_dot_proto_dot_master__pb2.StartGameResponse.FromString,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MasterServicer(object):
|
|
41
|
+
# missing associated documentation comment in .proto file
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
def StartGame(self, request, context):
|
|
45
|
+
"""Starts a game, returns side id and game server address.
|
|
46
|
+
"""
|
|
47
|
+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
|
48
|
+
context.set_details('Method not implemented!')
|
|
49
|
+
raise NotImplementedError('Method not implemented!')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def add_MasterServicer_to_server(servicer, server):
|
|
53
|
+
rpc_method_handlers = {
|
|
54
|
+
'StartGame': grpc.unary_unary_rpc_method_handler(
|
|
55
|
+
servicer.StartGame,
|
|
56
|
+
request_deserializer=gfootball_dot_eval__server_dot_proto_dot_master__pb2.StartGameRequest.FromString,
|
|
57
|
+
response_serializer=gfootball_dot_eval__server_dot_proto_dot_master__pb2.StartGameResponse.SerializeToString,
|
|
58
|
+
),
|
|
59
|
+
}
|
|
60
|
+
generic_handler = grpc.method_handlers_generic_handler(
|
|
61
|
+
'gfootball.eval_server.Master', rpc_method_handlers)
|
|
62
|
+
server.add_generic_rpc_handlers((generic_handler,))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""General utils."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import random
|
|
21
|
+
import string
|
|
22
|
+
import time
|
|
23
|
+
import urllib.request
|
|
24
|
+
from cuju.gfootball.eval_server import config
|
|
25
|
+
import grpc
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_random_string(length=10, append_timestamp=True):
|
|
29
|
+
characters = string.ascii_lowercase + string.ascii_uppercase + string.digits
|
|
30
|
+
res = ''.join(random.choice(characters) for i in range(length))
|
|
31
|
+
if append_timestamp:
|
|
32
|
+
res += '_{}'.format(int(time.time()))
|
|
33
|
+
return res
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_grpc_channel(server):
|
|
37
|
+
# send keepalive ping every 10 second
|
|
38
|
+
# allow unlimited amount of keepalive pings
|
|
39
|
+
options = (('grpc.keepalive_time_ms', 10000),
|
|
40
|
+
('grpc.http2.max_pings_without_data', 0))
|
|
41
|
+
return grpc.insecure_channel(server, options=options)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_master_address(track='default'):
|
|
45
|
+
# We add ''?' + get_random_string()' to avoid caching. Somehow even with
|
|
46
|
+
# disabled server side caching on the file we were still getting the old
|
|
47
|
+
# content of the file.
|
|
48
|
+
response = urllib.request.urlopen(
|
|
49
|
+
config.master_address_public_path + '_' + track + '?' +
|
|
50
|
+
get_random_string())
|
|
51
|
+
ip = response.read().decode('utf-8').strip()
|
|
52
|
+
return '{}:{}'.format(ip, config.grpc_port)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Additional models, not available in OpenAI baselines.
|
|
18
|
+
|
|
19
|
+
gfootball_impala_cnn is architecture used in the paper
|
|
20
|
+
(https://arxiv.org/pdf/1907.11180.pdf).
|
|
21
|
+
It is illustrated in the appendix. It is similar to Large architecture
|
|
22
|
+
from IMPALA paper; we use 4 big blocks instead of 3 though.
|
|
23
|
+
"""
|
|
24
|
+
from baselines.common.models import register
|
|
25
|
+
import sonnet as snt
|
|
26
|
+
import tensorflow.compat.v1 as tf
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@register('gfootball_impala_cnn')
|
|
30
|
+
def gfootball_impala_cnn():
|
|
31
|
+
def network_fn(frame):
|
|
32
|
+
# Convert to floats.
|
|
33
|
+
frame = tf.to_float(frame)
|
|
34
|
+
frame /= 255
|
|
35
|
+
with tf.variable_scope('convnet'):
|
|
36
|
+
conv_out = frame
|
|
37
|
+
conv_layers = [(16, 2), (32, 2), (32, 2), (32, 2)]
|
|
38
|
+
for i, (num_ch, num_blocks) in enumerate(conv_layers):
|
|
39
|
+
# Downscale.
|
|
40
|
+
conv_out = snt.Conv2D(num_ch, 3, stride=1, padding='SAME')(conv_out)
|
|
41
|
+
conv_out = tf.nn.pool(
|
|
42
|
+
conv_out,
|
|
43
|
+
window_shape=[3, 3],
|
|
44
|
+
pooling_type='MAX',
|
|
45
|
+
padding='SAME',
|
|
46
|
+
strides=[2, 2])
|
|
47
|
+
|
|
48
|
+
# Residual block(s).
|
|
49
|
+
for j in range(num_blocks):
|
|
50
|
+
with tf.variable_scope('residual_%d_%d' % (i, j)):
|
|
51
|
+
block_input = conv_out
|
|
52
|
+
conv_out = tf.nn.relu(conv_out)
|
|
53
|
+
conv_out = snt.Conv2D(num_ch, 3, stride=1, padding='SAME')(conv_out)
|
|
54
|
+
conv_out = tf.nn.relu(conv_out)
|
|
55
|
+
conv_out = snt.Conv2D(num_ch, 3, stride=1, padding='SAME')(conv_out)
|
|
56
|
+
conv_out += block_input
|
|
57
|
+
|
|
58
|
+
conv_out = tf.nn.relu(conv_out)
|
|
59
|
+
conv_out = snt.BatchFlatten()(conv_out)
|
|
60
|
+
|
|
61
|
+
conv_out = snt.Linear(256)(conv_out)
|
|
62
|
+
conv_out = tf.nn.relu(conv_out)
|
|
63
|
+
|
|
64
|
+
return conv_out
|
|
65
|
+
|
|
66
|
+
return network_fn
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""A simple example of setting up a multi-agent version of GFootball with rllib.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import absolute_import
|
|
21
|
+
from __future__ import division
|
|
22
|
+
from __future__ import print_function
|
|
23
|
+
|
|
24
|
+
import os
|
|
25
|
+
import tempfile
|
|
26
|
+
|
|
27
|
+
import argparse
|
|
28
|
+
import cuju.gfootball.env as football_env
|
|
29
|
+
from cuju.gfootball import _gym as gym
|
|
30
|
+
import ray
|
|
31
|
+
from ray import tune
|
|
32
|
+
from ray.rllib.env.multi_agent_env import MultiAgentEnv
|
|
33
|
+
from ray.tune.registry import register_env
|
|
34
|
+
|
|
35
|
+
parser = argparse.ArgumentParser()
|
|
36
|
+
|
|
37
|
+
parser.add_argument('--num-agents', type=int, default=3)
|
|
38
|
+
parser.add_argument('--num-policies', type=int, default=3)
|
|
39
|
+
parser.add_argument('--num-iters', type=int, default=100000)
|
|
40
|
+
parser.add_argument('--simple', action='store_true')
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class RllibGFootball(MultiAgentEnv):
|
|
44
|
+
"""An example of a wrapper for GFootball to make it compatible with rllib."""
|
|
45
|
+
|
|
46
|
+
def __init__(self, num_agents):
|
|
47
|
+
self.env = football_env.create_environment(
|
|
48
|
+
env_name='test_example_multiagent', stacked=False,
|
|
49
|
+
logdir=os.path.join(tempfile.gettempdir(), 'rllib_test'),
|
|
50
|
+
write_goal_dumps=False, write_full_episode_dumps=False, render=True,
|
|
51
|
+
dump_frequency=0,
|
|
52
|
+
number_of_left_players_agent_controls=num_agents,
|
|
53
|
+
channel_dimensions=(42, 42))
|
|
54
|
+
self.action_space = gym.spaces.Discrete(self.env.action_space.nvec[1])
|
|
55
|
+
self.observation_space = gym.spaces.Box(
|
|
56
|
+
low=self.env.observation_space.low[0],
|
|
57
|
+
high=self.env.observation_space.high[0],
|
|
58
|
+
dtype=self.env.observation_space.dtype)
|
|
59
|
+
self.num_agents = num_agents
|
|
60
|
+
|
|
61
|
+
def reset(self):
|
|
62
|
+
original_obs = self.env.reset()
|
|
63
|
+
obs = {}
|
|
64
|
+
for x in range(self.num_agents):
|
|
65
|
+
if self.num_agents > 1:
|
|
66
|
+
obs['agent_%d' % x] = original_obs[x]
|
|
67
|
+
else:
|
|
68
|
+
obs['agent_%d' % x] = original_obs
|
|
69
|
+
return obs
|
|
70
|
+
|
|
71
|
+
def step(self, action_dict):
|
|
72
|
+
actions = []
|
|
73
|
+
for key, value in sorted(action_dict.items()):
|
|
74
|
+
actions.append(value)
|
|
75
|
+
o, r, d, i = self.env.step(actions)
|
|
76
|
+
rewards = {}
|
|
77
|
+
obs = {}
|
|
78
|
+
infos = {}
|
|
79
|
+
for pos, key in enumerate(sorted(action_dict.keys())):
|
|
80
|
+
infos[key] = i
|
|
81
|
+
if self.num_agents > 1:
|
|
82
|
+
rewards[key] = r[pos]
|
|
83
|
+
obs[key] = o[pos]
|
|
84
|
+
else:
|
|
85
|
+
rewards[key] = r
|
|
86
|
+
obs[key] = o
|
|
87
|
+
dones = {'__all__': d}
|
|
88
|
+
return obs, rewards, dones, infos
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == '__main__':
|
|
92
|
+
args = parser.parse_args()
|
|
93
|
+
ray.init(num_gpus=1)
|
|
94
|
+
|
|
95
|
+
# Simple environment with `num_agents` independent players
|
|
96
|
+
register_env('gfootball', lambda _: RllibGFootball(args.num_agents))
|
|
97
|
+
single_env = RllibGFootball(args.num_agents)
|
|
98
|
+
obs_space = single_env.observation_space
|
|
99
|
+
act_space = single_env.action_space
|
|
100
|
+
|
|
101
|
+
def gen_policy(_):
|
|
102
|
+
return (None, obs_space, act_space, {})
|
|
103
|
+
|
|
104
|
+
# Setup PPO with an ensemble of `num_policies` different policies
|
|
105
|
+
policies = {
|
|
106
|
+
'policy_{}'.format(i): gen_policy(i) for i in range(args.num_policies)
|
|
107
|
+
}
|
|
108
|
+
policy_ids = list(policies.keys())
|
|
109
|
+
|
|
110
|
+
tune.run(
|
|
111
|
+
'PPO',
|
|
112
|
+
stop={'training_iteration': args.num_iters},
|
|
113
|
+
checkpoint_freq=50,
|
|
114
|
+
config={
|
|
115
|
+
'env': 'gfootball',
|
|
116
|
+
'lambda': 0.95,
|
|
117
|
+
'kl_coeff': 0.2,
|
|
118
|
+
'clip_rewards': False,
|
|
119
|
+
'vf_clip_param': 10.0,
|
|
120
|
+
'entropy_coeff': 0.01,
|
|
121
|
+
'train_batch_size': 2000,
|
|
122
|
+
'sample_batch_size': 100,
|
|
123
|
+
'sgd_minibatch_size': 500,
|
|
124
|
+
'num_sgd_iter': 10,
|
|
125
|
+
'num_workers': 10,
|
|
126
|
+
'num_envs_per_worker': 1,
|
|
127
|
+
'batch_mode': 'truncate_episodes',
|
|
128
|
+
'observation_filter': 'NoFilter',
|
|
129
|
+
'vf_share_layers': 'true',
|
|
130
|
+
'num_gpus': 1,
|
|
131
|
+
'lr': 2.5e-4,
|
|
132
|
+
'log_level': 'DEBUG',
|
|
133
|
+
'simple_optimizer': args.simple,
|
|
134
|
+
'multiagent': {
|
|
135
|
+
'policies': policies,
|
|
136
|
+
'policy_mapping_fn': tune.function(
|
|
137
|
+
lambda agent_id: policy_ids[int(agent_id[6:])]),
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2019 Google LLC
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# Modified by the cuju Authors in 2026, in the import lines that ci/port_gfootball.py lists.
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Runs football_env on OpenAI's ppo2."""
|
|
18
|
+
from __future__ import absolute_import
|
|
19
|
+
from __future__ import division
|
|
20
|
+
from __future__ import print_function
|
|
21
|
+
|
|
22
|
+
import multiprocessing
|
|
23
|
+
import os
|
|
24
|
+
from absl import app
|
|
25
|
+
from absl import flags
|
|
26
|
+
from baselines import logger
|
|
27
|
+
from baselines.bench import monitor
|
|
28
|
+
from baselines.common.vec_env.subproc_vec_env import SubprocVecEnv
|
|
29
|
+
from baselines.ppo2 import ppo2
|
|
30
|
+
import cuju.gfootball.env as football_env
|
|
31
|
+
from cuju.gfootball.examples import models
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
FLAGS = flags.FLAGS
|
|
35
|
+
|
|
36
|
+
flags.DEFINE_string('level', 'academy_empty_goal_close',
|
|
37
|
+
'Defines type of problem being solved')
|
|
38
|
+
flags.DEFINE_enum('state', 'extracted_stacked', ['extracted',
|
|
39
|
+
'extracted_stacked'],
|
|
40
|
+
'Observation to be used for training.')
|
|
41
|
+
flags.DEFINE_enum('reward_experiment', 'scoring',
|
|
42
|
+
['scoring', 'scoring,checkpoints'],
|
|
43
|
+
'Reward to be used for training.')
|
|
44
|
+
flags.DEFINE_enum('policy', 'cnn', ['cnn', 'lstm', 'mlp', 'impala_cnn',
|
|
45
|
+
'gfootball_impala_cnn'],
|
|
46
|
+
'Policy architecture')
|
|
47
|
+
flags.DEFINE_integer('num_timesteps', int(2e6),
|
|
48
|
+
'Number of timesteps to run for.')
|
|
49
|
+
flags.DEFINE_integer('num_envs', 8,
|
|
50
|
+
'Number of environments to run in parallel.')
|
|
51
|
+
flags.DEFINE_integer('nsteps', 128, 'Number of environment steps per epoch; '
|
|
52
|
+
'batch size is nsteps * nenv')
|
|
53
|
+
flags.DEFINE_integer('noptepochs', 4, 'Number of updates per epoch.')
|
|
54
|
+
flags.DEFINE_integer('nminibatches', 8,
|
|
55
|
+
'Number of minibatches to split one epoch to.')
|
|
56
|
+
flags.DEFINE_integer('save_interval', 100,
|
|
57
|
+
'How frequently checkpoints are saved.')
|
|
58
|
+
flags.DEFINE_integer('seed', 0, 'Random seed.')
|
|
59
|
+
flags.DEFINE_float('lr', 0.00008, 'Learning rate')
|
|
60
|
+
flags.DEFINE_float('ent_coef', 0.01, 'Entropy coeficient')
|
|
61
|
+
flags.DEFINE_float('gamma', 0.993, 'Discount factor')
|
|
62
|
+
flags.DEFINE_float('cliprange', 0.27, 'Clip range')
|
|
63
|
+
flags.DEFINE_float('max_grad_norm', 0.5, 'Max gradient norm (clipping)')
|
|
64
|
+
flags.DEFINE_bool('render', False, 'If True, environment rendering is enabled.')
|
|
65
|
+
flags.DEFINE_bool('dump_full_episodes', False,
|
|
66
|
+
'If True, trace is dumped after every episode.')
|
|
67
|
+
flags.DEFINE_bool('dump_scores', False,
|
|
68
|
+
'If True, sampled traces after scoring are dumped.')
|
|
69
|
+
flags.DEFINE_string('load_path', None, 'Path to load initial checkpoint from.')
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def create_single_football_env(iprocess):
|
|
73
|
+
"""Creates gfootball environment."""
|
|
74
|
+
env = football_env.create_environment(
|
|
75
|
+
env_name=FLAGS.level, stacked=('stacked' in FLAGS.state),
|
|
76
|
+
rewards=FLAGS.reward_experiment,
|
|
77
|
+
logdir=logger.get_dir(),
|
|
78
|
+
write_goal_dumps=FLAGS.dump_scores and (iprocess == 0),
|
|
79
|
+
write_full_episode_dumps=FLAGS.dump_full_episodes and (iprocess == 0),
|
|
80
|
+
render=FLAGS.render and (iprocess == 0),
|
|
81
|
+
dump_frequency=50 if FLAGS.render and iprocess == 0 else 0)
|
|
82
|
+
env = monitor.Monitor(env, logger.get_dir() and os.path.join(logger.get_dir(),
|
|
83
|
+
str(iprocess)))
|
|
84
|
+
return env
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def train(_):
|
|
88
|
+
"""Trains a PPO2 policy."""
|
|
89
|
+
vec_env = SubprocVecEnv([
|
|
90
|
+
(lambda _i=i: create_single_football_env(_i))
|
|
91
|
+
for i in range(FLAGS.num_envs)
|
|
92
|
+
], context=None)
|
|
93
|
+
|
|
94
|
+
# Import tensorflow after we create environments. TF is not fork sake, and
|
|
95
|
+
# we could be using TF as part of environment if one of the players is
|
|
96
|
+
# controlled by an already trained model.
|
|
97
|
+
import tensorflow.compat.v1 as tf
|
|
98
|
+
ncpu = multiprocessing.cpu_count()
|
|
99
|
+
config = tf.ConfigProto(allow_soft_placement=True,
|
|
100
|
+
intra_op_parallelism_threads=ncpu,
|
|
101
|
+
inter_op_parallelism_threads=ncpu)
|
|
102
|
+
config.gpu_options.allow_growth = True
|
|
103
|
+
tf.Session(config=config).__enter__()
|
|
104
|
+
|
|
105
|
+
ppo2.learn(network=FLAGS.policy,
|
|
106
|
+
total_timesteps=FLAGS.num_timesteps,
|
|
107
|
+
env=vec_env,
|
|
108
|
+
seed=FLAGS.seed,
|
|
109
|
+
nsteps=FLAGS.nsteps,
|
|
110
|
+
nminibatches=FLAGS.nminibatches,
|
|
111
|
+
noptepochs=FLAGS.noptepochs,
|
|
112
|
+
max_grad_norm=FLAGS.max_grad_norm,
|
|
113
|
+
gamma=FLAGS.gamma,
|
|
114
|
+
ent_coef=FLAGS.ent_coef,
|
|
115
|
+
lr=FLAGS.lr,
|
|
116
|
+
log_interval=1,
|
|
117
|
+
save_interval=FLAGS.save_interval,
|
|
118
|
+
cliprange=FLAGS.cliprange,
|
|
119
|
+
load_path=FLAGS.load_path)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if __name__ == '__main__':
|
|
123
|
+
app.run(train)
|