langfun 0.1.2.dev202509210803__py3-none-any.whl → 0.1.2.dev202509230805__py3-none-any.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.
Potentially problematic release.
This version of langfun might be problematic. Click here for more details.
- langfun/env/__init__.py +0 -1
- langfun/env/base_environment.py +126 -66
- langfun/env/base_feature.py +79 -40
- langfun/env/base_sandbox.py +630 -124
- langfun/env/base_test.py +1283 -474
- langfun/env/interface.py +462 -334
- langfun/env/load_balancers.py +4 -4
- langfun/env/load_balancers_test.py +32 -57
- {langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/RECORD +13 -13
- {langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/top_level.txt +0 -0
langfun/env/load_balancers.py
CHANGED
|
@@ -51,9 +51,9 @@ class RoundRobin(LoadBalancer):
|
|
|
51
51
|
for _ in range(len(sandbox_pool)):
|
|
52
52
|
sandbox = sandbox_pool[self._counter % len(sandbox_pool)]
|
|
53
53
|
self._counter = self._counter + 1
|
|
54
|
-
if sandbox.
|
|
55
|
-
# Mark the sandbox as
|
|
56
|
-
# threads.
|
|
57
|
-
sandbox.
|
|
54
|
+
if sandbox.status == interface.Sandbox.Status.READY:
|
|
55
|
+
# Mark the sandbox as acquired to prevent it from being acquired by
|
|
56
|
+
# other threads.
|
|
57
|
+
sandbox.set_acquired()
|
|
58
58
|
return sandbox
|
|
59
59
|
raise IndexError('No free sandbox in the pool.')
|
|
@@ -21,9 +21,7 @@ from langfun.env import load_balancers
|
|
|
21
21
|
|
|
22
22
|
class TestingSandbox(interface.Sandbox):
|
|
23
23
|
sandbox_id: str
|
|
24
|
-
|
|
25
|
-
is_pending: bool = False
|
|
26
|
-
is_busy: bool = False
|
|
24
|
+
status: interface.Sandbox.Status = interface.Sandbox.Status.READY
|
|
27
25
|
|
|
28
26
|
def _on_bound(self) -> None:
|
|
29
27
|
super()._on_bound()
|
|
@@ -44,20 +42,27 @@ class TestingSandbox(interface.Sandbox):
|
|
|
44
42
|
def features(self) -> dict[str, interface.Feature]:
|
|
45
43
|
raise NotImplementedError()
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
45
|
+
@property
|
|
46
|
+
def state_errors(self) -> list[interface.SandboxStateError]:
|
|
47
|
+
return []
|
|
51
48
|
|
|
52
|
-
def
|
|
53
|
-
self.rebind(
|
|
54
|
-
is_busy=busy, skip_notification=True, raise_on_no_change=False
|
|
55
|
-
)
|
|
49
|
+
def set_status(self, status: interface.Sandbox.Status) -> None:
|
|
50
|
+
self.rebind(status=status, skip_notification=True)
|
|
56
51
|
|
|
57
|
-
def
|
|
58
|
-
self.
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
def set_acquired(self) -> None:
|
|
53
|
+
self.set_status(self.Status.ACQUIRED)
|
|
54
|
+
|
|
55
|
+
def add_event_handler(
|
|
56
|
+
self,
|
|
57
|
+
event_handler: interface.EnvironmentEventHandler
|
|
58
|
+
) -> None:
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
def remove_event_handler(
|
|
62
|
+
self,
|
|
63
|
+
event_handler: interface.EnvironmentEventHandler
|
|
64
|
+
) -> None:
|
|
65
|
+
pass
|
|
61
66
|
|
|
62
67
|
def start(self) -> None:
|
|
63
68
|
self.set_alive()
|
|
@@ -65,9 +70,6 @@ class TestingSandbox(interface.Sandbox):
|
|
|
65
70
|
def shutdown(self) -> None:
|
|
66
71
|
self.set_alive(False)
|
|
67
72
|
|
|
68
|
-
def ping(self) -> None:
|
|
69
|
-
pass
|
|
70
|
-
|
|
71
73
|
def start_session(self, session_id: str) -> None:
|
|
72
74
|
self._session_id = session_id
|
|
73
75
|
|
|
@@ -83,50 +85,25 @@ class RoundRobinTest(unittest.TestCase):
|
|
|
83
85
|
|
|
84
86
|
def test_basic(self):
|
|
85
87
|
sandbox_pool = [
|
|
86
|
-
TestingSandbox(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
),
|
|
92
|
-
TestingSandbox(
|
|
93
|
-
'1',
|
|
94
|
-
is_alive=True,
|
|
95
|
-
is_pending=True,
|
|
96
|
-
is_busy=False,
|
|
97
|
-
),
|
|
98
|
-
TestingSandbox(
|
|
99
|
-
'2',
|
|
100
|
-
is_alive=True,
|
|
101
|
-
is_pending=False,
|
|
102
|
-
is_busy=True,
|
|
103
|
-
),
|
|
104
|
-
TestingSandbox(
|
|
105
|
-
'3',
|
|
106
|
-
is_alive=True,
|
|
107
|
-
is_pending=False,
|
|
108
|
-
is_busy=False,
|
|
109
|
-
),
|
|
110
|
-
TestingSandbox(
|
|
111
|
-
'4',
|
|
112
|
-
is_alive=True,
|
|
113
|
-
is_pending=False,
|
|
114
|
-
is_busy=False,
|
|
115
|
-
),
|
|
88
|
+
TestingSandbox('0', interface.Sandbox.Status.OFFLINE),
|
|
89
|
+
TestingSandbox('1', interface.Sandbox.Status.SETTING_UP),
|
|
90
|
+
TestingSandbox('2', interface.Sandbox.Status.IN_SESSION),
|
|
91
|
+
TestingSandbox('3', status=interface.Sandbox.Status.READY),
|
|
92
|
+
TestingSandbox('4', status=interface.Sandbox.Status.READY),
|
|
116
93
|
]
|
|
117
94
|
lb = load_balancers.RoundRobin()
|
|
118
95
|
sandbox = lb.acquire(sandbox_pool)
|
|
119
96
|
self.assertIs(sandbox, sandbox_pool[3])
|
|
120
|
-
self.
|
|
97
|
+
self.assertEqual(sandbox.status, interface.Sandbox.Status.ACQUIRED)
|
|
121
98
|
|
|
122
99
|
sandbox = lb.acquire(sandbox_pool)
|
|
123
100
|
self.assertIs(sandbox, sandbox_pool[4])
|
|
124
|
-
self.
|
|
101
|
+
self.assertEqual(sandbox.status, interface.Sandbox.Status.ACQUIRED)
|
|
125
102
|
|
|
126
|
-
sandbox_pool[0].
|
|
103
|
+
sandbox_pool[0].set_status(interface.Sandbox.Status.READY)
|
|
127
104
|
sandbox = lb.acquire(sandbox_pool)
|
|
128
105
|
self.assertIs(sandbox, sandbox_pool[0])
|
|
129
|
-
self.
|
|
106
|
+
self.assertEqual(sandbox.status, interface.Sandbox.Status.ACQUIRED)
|
|
130
107
|
|
|
131
108
|
with self.assertRaisesRegex(IndexError, 'No free sandbox in the pool.'):
|
|
132
109
|
lb.acquire(sandbox_pool)
|
|
@@ -139,13 +116,11 @@ class RoundRobinTest(unittest.TestCase):
|
|
|
139
116
|
def _thread_func(i):
|
|
140
117
|
sandbox = lb.acquire(sandbox_pool)
|
|
141
118
|
time.sleep(0.1)
|
|
142
|
-
sandbox.
|
|
143
|
-
sandbox.set_pending(False)
|
|
119
|
+
sandbox.set_status(interface.Sandbox.Status.IN_SESSION)
|
|
144
120
|
time.sleep(0.1)
|
|
145
|
-
sandbox.
|
|
146
|
-
sandbox.set_alive(False)
|
|
121
|
+
sandbox.set_status(interface.Sandbox.Status.OFFLINE)
|
|
147
122
|
time.sleep(0.1)
|
|
148
|
-
sandbox.
|
|
123
|
+
sandbox.set_status(interface.Sandbox.Status.READY)
|
|
149
124
|
return i
|
|
150
125
|
|
|
151
126
|
with concurrent.futures.ThreadPoolExecutor(max_workers=64) as executor:
|
|
@@ -165,17 +165,17 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
|
165
165
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
|
166
166
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
|
167
167
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
|
168
|
-
langfun/env/__init__.py,sha256=
|
|
169
|
-
langfun/env/base_environment.py,sha256=
|
|
170
|
-
langfun/env/base_feature.py,sha256=
|
|
171
|
-
langfun/env/base_sandbox.py,sha256=
|
|
172
|
-
langfun/env/base_test.py,sha256=
|
|
173
|
-
langfun/env/interface.py,sha256=
|
|
168
|
+
langfun/env/__init__.py,sha256=WOht-DaYtVmO8U-viQbWmCUCCPcJwBELBiQYUfGAG5w,1532
|
|
169
|
+
langfun/env/base_environment.py,sha256=73d6hs2XhJd2IK--H7Pfs-1PG5TfJ89x_yk94doq0G0,16465
|
|
170
|
+
langfun/env/base_feature.py,sha256=lphS2GmwCYR-ypPGIzn0KcLzxUcO2l9R2ZbJqcqOkOI,5794
|
|
171
|
+
langfun/env/base_sandbox.py,sha256=c-HskeubKOH-P2ZrQG3HFKkhtX3ZADYj4QIMemQNGbo,32202
|
|
172
|
+
langfun/env/base_test.py,sha256=CIzZjfSkZEDsHARF4aoOZfq5T8DN8i8AW-swFsFw0Gk,60328
|
|
173
|
+
langfun/env/interface.py,sha256=wOu_yQO8uEt5lU88FeqqaInBLg7WgYYtVeGtPsanE90,29031
|
|
174
174
|
langfun/env/interface_test.py,sha256=nrqFLtpHd0vnOjoIX9cjV5WD1c-7J3WW29aogNu_94A,1395
|
|
175
|
-
langfun/env/load_balancers.py,sha256=
|
|
176
|
-
langfun/env/load_balancers_test.py,sha256=
|
|
177
|
-
langfun-0.1.2.
|
|
178
|
-
langfun-0.1.2.
|
|
179
|
-
langfun-0.1.2.
|
|
180
|
-
langfun-0.1.2.
|
|
181
|
-
langfun-0.1.2.
|
|
175
|
+
langfun/env/load_balancers.py,sha256=qRhCthqzjZIQBwta8qC1C0s0J-VQAVomJQqI7Nqv-r4,1948
|
|
176
|
+
langfun/env/load_balancers_test.py,sha256=gJKJ3K5_WS7hsz9Jv3nPEjlb04Z6MmrZpfCu86siYKU,3967
|
|
177
|
+
langfun-0.1.2.dev202509230805.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
178
|
+
langfun-0.1.2.dev202509230805.dist-info/METADATA,sha256=8CisrxNc9tgTL4Ols2b5jK4H9vEwTokwFuDNipS1X9s,7380
|
|
179
|
+
langfun-0.1.2.dev202509230805.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
180
|
+
langfun-0.1.2.dev202509230805.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
|
181
|
+
langfun-0.1.2.dev202509230805.dist-info/RECORD,,
|
|
File without changes
|
{langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{langfun-0.1.2.dev202509210803.dist-info → langfun-0.1.2.dev202509230805.dist-info}/top_level.txt
RENAMED
|
File without changes
|