langfun 0.1.2.dev202509220805__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.

@@ -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.is_alive and not sandbox.is_busy and not sandbox.is_pending:
55
- # Mark the sandbox as pending so that it will not be acquired by other
56
- # threads.
57
- sandbox.set_pending()
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
- is_alive: bool = True
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
- def set_pending(self, pending: bool = True) -> None:
48
- self.rebind(
49
- is_pending=pending, skip_notification=True, raise_on_no_change=False
50
- )
45
+ @property
46
+ def state_errors(self) -> list[interface.SandboxStateError]:
47
+ return []
51
48
 
52
- def set_busy(self, busy: bool = True) -> None:
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 set_alive(self, alive: bool = True) -> None:
58
- self.rebind(
59
- is_alive=alive, skip_notification=True, raise_on_no_change=False
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
- '0',
88
- is_alive=False,
89
- is_pending=False,
90
- is_busy=False,
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.assertTrue(sandbox.is_pending)
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.assertTrue(sandbox.is_pending)
101
+ self.assertEqual(sandbox.status, interface.Sandbox.Status.ACQUIRED)
125
102
 
126
- sandbox_pool[0].set_alive()
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.assertTrue(sandbox.is_pending)
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.set_busy()
143
- sandbox.set_pending(False)
119
+ sandbox.set_status(interface.Sandbox.Status.IN_SESSION)
144
120
  time.sleep(0.1)
145
- sandbox.set_busy(False)
146
- sandbox.set_alive(False)
121
+ sandbox.set_status(interface.Sandbox.Status.OFFLINE)
147
122
  time.sleep(0.1)
148
- sandbox.set_alive()
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202509220805
3
+ Version: 0.1.2.dev202509230805
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -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=YB44mvoCNiqWP48ITExQKZ3yHGoskFGB1pYRUEwWdbc,1582
169
- langfun/env/base_environment.py,sha256=BMdSpsk0uMCPklrZ7XQPpJ03IL3ZEzCIs3RlUfG8yNo,14215
170
- langfun/env/base_feature.py,sha256=C3s9ovV7MPOBGNM9evfABVkGxcfazX8A03Jb_RB1MW0,4936
171
- langfun/env/base_sandbox.py,sha256=SWDU3Mez7FVctpMwePbcavru3GkdTsC59neWz8MqTis,14126
172
- langfun/env/base_test.py,sha256=FuytEQJeKnxX_VEW0axdEoCg1A1d2rIVQss0qxoPPAQ,26739
173
- langfun/env/interface.py,sha256=4Q6ewOtj8XJyy8OEQqSYwogjzfvivFOljGS5txhlx_U,21534
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=jbT3pB7QpPVovbXeJK1PNohUcrYrJNtWU8KaWzxO9nI,1963
176
- langfun/env/load_balancers_test.py,sha256=bAjC89zxmROpkl56BqvMU_yKOJ03Gtu8x8j56HO5HNc,4124
177
- langfun-0.1.2.dev202509220805.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
178
- langfun-0.1.2.dev202509220805.dist-info/METADATA,sha256=U4NSVNlycYj5bCJRjXMfziIvjiKQd0wyyL2GJG25Oi0,7380
179
- langfun-0.1.2.dev202509220805.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
180
- langfun-0.1.2.dev202509220805.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
181
- langfun-0.1.2.dev202509220805.dist-info/RECORD,,
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,,