langfun 0.1.2.dev202510310805__py3-none-any.whl → 0.1.2.dev202511010804__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 +4 -2
- langfun/env/base_environment.py +12 -19
- langfun/env/base_environment_test.py +473 -0
- langfun/env/base_feature.py +52 -8
- langfun/env/base_sandbox.py +43 -121
- langfun/env/{base_test.py → base_sandbox_test.py} +21 -484
- langfun/env/event_handlers/__init__.py +1 -1
- langfun/env/event_handlers/chain.py +255 -0
- langfun/env/event_handlers/chain_test.py +281 -0
- langfun/env/event_handlers/event_logger.py +39 -39
- langfun/env/event_handlers/event_logger_test.py +1 -1
- langfun/env/event_handlers/metric_writer.py +38 -38
- langfun/env/event_handlers/metric_writer_test.py +1 -1
- langfun/env/interface.py +344 -8
- langfun/env/test_utils.py +1 -4
- {langfun-0.1.2.dev202510310805.dist-info → langfun-0.1.2.dev202511010804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202510310805.dist-info → langfun-0.1.2.dev202511010804.dist-info}/RECORD +20 -18
- langfun/env/event_handlers/base.py +0 -350
- {langfun-0.1.2.dev202510310805.dist-info → langfun-0.1.2.dev202511010804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202510310805.dist-info → langfun-0.1.2.dev202511010804.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202510310805.dist-info → langfun-0.1.2.dev202511010804.dist-info}/top_level.txt +0 -0
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
import re
|
|
17
17
|
import time
|
|
18
18
|
from typing import Annotated
|
|
19
|
-
from langfun.env
|
|
19
|
+
from langfun.env import interface
|
|
20
20
|
import pyglove as pg
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
class EventLogger(pg.Object,
|
|
23
|
+
class EventLogger(pg.Object, interface.EventHandler):
|
|
24
24
|
"""Event handler for logging debugger."""
|
|
25
25
|
|
|
26
26
|
colored: Annotated[
|
|
@@ -125,7 +125,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
125
125
|
|
|
126
126
|
def on_environment_starting(
|
|
127
127
|
self,
|
|
128
|
-
environment:
|
|
128
|
+
environment: interface.Environment,
|
|
129
129
|
) -> None:
|
|
130
130
|
"""Called when the environment is starting."""
|
|
131
131
|
self._print(
|
|
@@ -137,7 +137,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
137
137
|
|
|
138
138
|
def on_environment_shutting_down(
|
|
139
139
|
self,
|
|
140
|
-
environment:
|
|
140
|
+
environment: interface.Environment,
|
|
141
141
|
offline_duration: float,
|
|
142
142
|
) -> None:
|
|
143
143
|
"""Called when the environment is shutting down."""
|
|
@@ -151,7 +151,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
151
151
|
|
|
152
152
|
def on_environment_start(
|
|
153
153
|
self,
|
|
154
|
-
environment:
|
|
154
|
+
environment: interface.Environment,
|
|
155
155
|
duration: float,
|
|
156
156
|
error: BaseException | None
|
|
157
157
|
) -> None:
|
|
@@ -166,7 +166,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
166
166
|
|
|
167
167
|
def on_environment_housekeep(
|
|
168
168
|
self,
|
|
169
|
-
environment:
|
|
169
|
+
environment: interface.Environment,
|
|
170
170
|
counter: int,
|
|
171
171
|
duration: float,
|
|
172
172
|
error: BaseException | None,
|
|
@@ -194,7 +194,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
194
194
|
|
|
195
195
|
def on_environment_shutdown(
|
|
196
196
|
self,
|
|
197
|
-
environment:
|
|
197
|
+
environment: interface.Environment,
|
|
198
198
|
duration: float,
|
|
199
199
|
lifetime: float,
|
|
200
200
|
error: BaseException | None
|
|
@@ -210,8 +210,8 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
210
210
|
|
|
211
211
|
def on_sandbox_start(
|
|
212
212
|
self,
|
|
213
|
-
environment:
|
|
214
|
-
sandbox:
|
|
213
|
+
environment: interface.Environment,
|
|
214
|
+
sandbox: interface.Sandbox,
|
|
215
215
|
duration: float,
|
|
216
216
|
error: BaseException | None
|
|
217
217
|
) -> None:
|
|
@@ -226,10 +226,10 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
226
226
|
|
|
227
227
|
def on_sandbox_status_change(
|
|
228
228
|
self,
|
|
229
|
-
environment:
|
|
230
|
-
sandbox:
|
|
231
|
-
old_status:
|
|
232
|
-
new_status:
|
|
229
|
+
environment: interface.Environment,
|
|
230
|
+
sandbox: interface.Sandbox,
|
|
231
|
+
old_status: interface.Sandbox.Status,
|
|
232
|
+
new_status: interface.Sandbox.Status,
|
|
233
233
|
span: float
|
|
234
234
|
) -> None:
|
|
235
235
|
if self.sandbox_status:
|
|
@@ -242,8 +242,8 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
242
242
|
|
|
243
243
|
def on_sandbox_shutdown(
|
|
244
244
|
self,
|
|
245
|
-
environment:
|
|
246
|
-
sandbox:
|
|
245
|
+
environment: interface.Environment,
|
|
246
|
+
sandbox: interface.Sandbox,
|
|
247
247
|
duration: float,
|
|
248
248
|
lifetime: float,
|
|
249
249
|
error: BaseException | None
|
|
@@ -260,8 +260,8 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
260
260
|
|
|
261
261
|
def on_sandbox_housekeep(
|
|
262
262
|
self,
|
|
263
|
-
environment:
|
|
264
|
-
sandbox:
|
|
263
|
+
environment: interface.Environment,
|
|
264
|
+
sandbox: interface.Sandbox,
|
|
265
265
|
counter: int,
|
|
266
266
|
duration: float,
|
|
267
267
|
error: BaseException | None,
|
|
@@ -279,9 +279,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
279
279
|
|
|
280
280
|
def on_feature_setup(
|
|
281
281
|
self,
|
|
282
|
-
environment:
|
|
283
|
-
sandbox:
|
|
284
|
-
feature:
|
|
282
|
+
environment: interface.Environment,
|
|
283
|
+
sandbox: interface.Sandbox,
|
|
284
|
+
feature: interface.Feature,
|
|
285
285
|
duration: float,
|
|
286
286
|
error: BaseException | None
|
|
287
287
|
) -> None:
|
|
@@ -296,9 +296,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
296
296
|
|
|
297
297
|
def on_feature_teardown(
|
|
298
298
|
self,
|
|
299
|
-
environment:
|
|
300
|
-
sandbox:
|
|
301
|
-
feature:
|
|
299
|
+
environment: interface.Environment,
|
|
300
|
+
sandbox: interface.Sandbox,
|
|
301
|
+
feature: interface.Feature,
|
|
302
302
|
duration: float,
|
|
303
303
|
error: BaseException | None
|
|
304
304
|
) -> None:
|
|
@@ -313,9 +313,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
313
313
|
|
|
314
314
|
def on_feature_setup_session(
|
|
315
315
|
self,
|
|
316
|
-
environment:
|
|
317
|
-
sandbox:
|
|
318
|
-
feature:
|
|
316
|
+
environment: interface.Environment,
|
|
317
|
+
sandbox: interface.Sandbox,
|
|
318
|
+
feature: interface.Feature,
|
|
319
319
|
session_id: str | None,
|
|
320
320
|
duration: float,
|
|
321
321
|
error: BaseException | None
|
|
@@ -331,9 +331,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
331
331
|
|
|
332
332
|
def on_feature_teardown_session(
|
|
333
333
|
self,
|
|
334
|
-
environment:
|
|
335
|
-
sandbox:
|
|
336
|
-
feature:
|
|
334
|
+
environment: interface.Environment,
|
|
335
|
+
sandbox: interface.Sandbox,
|
|
336
|
+
feature: interface.Feature,
|
|
337
337
|
session_id: str,
|
|
338
338
|
duration: float,
|
|
339
339
|
error: BaseException | None
|
|
@@ -349,9 +349,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
349
349
|
|
|
350
350
|
def on_feature_housekeep(
|
|
351
351
|
self,
|
|
352
|
-
environment:
|
|
353
|
-
sandbox:
|
|
354
|
-
feature:
|
|
352
|
+
environment: interface.Environment,
|
|
353
|
+
sandbox: interface.Sandbox,
|
|
354
|
+
feature: interface.Feature,
|
|
355
355
|
counter: int,
|
|
356
356
|
duration: float,
|
|
357
357
|
error: BaseException | None,
|
|
@@ -369,8 +369,8 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
369
369
|
|
|
370
370
|
def on_session_start(
|
|
371
371
|
self,
|
|
372
|
-
environment:
|
|
373
|
-
sandbox:
|
|
372
|
+
environment: interface.Environment,
|
|
373
|
+
sandbox: interface.Sandbox,
|
|
374
374
|
session_id: str,
|
|
375
375
|
duration: float,
|
|
376
376
|
error: BaseException | None
|
|
@@ -386,8 +386,8 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
386
386
|
|
|
387
387
|
def on_session_end(
|
|
388
388
|
self,
|
|
389
|
-
environment:
|
|
390
|
-
sandbox:
|
|
389
|
+
environment: interface.Environment,
|
|
390
|
+
sandbox: interface.Sandbox,
|
|
391
391
|
session_id: str,
|
|
392
392
|
duration: float,
|
|
393
393
|
lifetime: float,
|
|
@@ -406,9 +406,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
406
406
|
def on_sandbox_activity(
|
|
407
407
|
self,
|
|
408
408
|
name: str,
|
|
409
|
-
environment:
|
|
410
|
-
sandbox:
|
|
411
|
-
feature:
|
|
409
|
+
environment: interface.Environment,
|
|
410
|
+
sandbox: interface.Sandbox,
|
|
411
|
+
feature: interface.Feature | None,
|
|
412
412
|
session_id: str | None,
|
|
413
413
|
duration: float,
|
|
414
414
|
error: BaseException | None,
|
|
@@ -71,7 +71,7 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
71
71
|
outage_retry_interval=0,
|
|
72
72
|
housekeep_interval=1.0,
|
|
73
73
|
sandbox_keepalive_interval=1.0,
|
|
74
|
-
|
|
74
|
+
event_handler=event_logger,
|
|
75
75
|
)
|
|
76
76
|
with self._capture_logs(test_name) as stream:
|
|
77
77
|
with env:
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
"""Environment event logger."""
|
|
15
15
|
|
|
16
16
|
from typing import Annotated
|
|
17
|
-
from langfun.env
|
|
17
|
+
from langfun.env import interface
|
|
18
18
|
import pyglove as pg
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
_METRIC_NAMESPACE = '/langfun/env'
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
class MetricWriter(pg.Object,
|
|
24
|
+
class MetricWriter(pg.Object, interface.EventHandler):
|
|
25
25
|
"""Event handler for streamz metrics."""
|
|
26
26
|
|
|
27
27
|
app: Annotated[
|
|
@@ -364,14 +364,14 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
364
364
|
|
|
365
365
|
def on_environment_starting(
|
|
366
366
|
self,
|
|
367
|
-
environment:
|
|
367
|
+
environment: interface.Environment
|
|
368
368
|
) -> None:
|
|
369
369
|
"""Called when the environment is starting."""
|
|
370
370
|
self._initialize_metrics()
|
|
371
371
|
|
|
372
372
|
def on_environment_housekeep(
|
|
373
373
|
self,
|
|
374
|
-
environment:
|
|
374
|
+
environment: interface.Environment,
|
|
375
375
|
counter: int,
|
|
376
376
|
duration: float,
|
|
377
377
|
error: BaseException | None,
|
|
@@ -387,8 +387,8 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
387
387
|
|
|
388
388
|
def on_sandbox_start(
|
|
389
389
|
self,
|
|
390
|
-
environment:
|
|
391
|
-
sandbox:
|
|
390
|
+
environment: interface.Environment,
|
|
391
|
+
sandbox: interface.Sandbox,
|
|
392
392
|
duration: float,
|
|
393
393
|
error: BaseException | None
|
|
394
394
|
) -> None:
|
|
@@ -408,10 +408,10 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
408
408
|
|
|
409
409
|
def on_sandbox_status_change(
|
|
410
410
|
self,
|
|
411
|
-
environment:
|
|
412
|
-
sandbox:
|
|
413
|
-
old_status:
|
|
414
|
-
new_status:
|
|
411
|
+
environment: interface.Environment,
|
|
412
|
+
sandbox: interface.Sandbox,
|
|
413
|
+
old_status: interface.Sandbox.Status,
|
|
414
|
+
new_status: interface.Sandbox.Status,
|
|
415
415
|
span: float
|
|
416
416
|
) -> None:
|
|
417
417
|
self._sandbox_status_duration_ms.record(
|
|
@@ -421,7 +421,7 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
421
421
|
image_id=sandbox.image_id,
|
|
422
422
|
status=old_status.value
|
|
423
423
|
)
|
|
424
|
-
if old_status !=
|
|
424
|
+
if old_status != interface.Sandbox.Status.CREATED:
|
|
425
425
|
self._sandbox_count.increment(
|
|
426
426
|
delta=-1,
|
|
427
427
|
app=self.app,
|
|
@@ -429,7 +429,7 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
429
429
|
image_id=sandbox.image_id,
|
|
430
430
|
status=old_status.value
|
|
431
431
|
)
|
|
432
|
-
if new_status !=
|
|
432
|
+
if new_status != interface.Sandbox.Status.OFFLINE:
|
|
433
433
|
self._sandbox_count.increment(
|
|
434
434
|
app=self.app,
|
|
435
435
|
environment_id=str(environment.id),
|
|
@@ -439,8 +439,8 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
439
439
|
|
|
440
440
|
def on_sandbox_shutdown(
|
|
441
441
|
self,
|
|
442
|
-
environment:
|
|
443
|
-
sandbox:
|
|
442
|
+
environment: interface.Environment,
|
|
443
|
+
sandbox: interface.Sandbox,
|
|
444
444
|
duration: float,
|
|
445
445
|
lifetime: float,
|
|
446
446
|
error: BaseException | None
|
|
@@ -468,8 +468,8 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
468
468
|
|
|
469
469
|
def on_sandbox_housekeep(
|
|
470
470
|
self,
|
|
471
|
-
environment:
|
|
472
|
-
sandbox:
|
|
471
|
+
environment: interface.Environment,
|
|
472
|
+
sandbox: interface.Sandbox,
|
|
473
473
|
counter: int,
|
|
474
474
|
duration: float,
|
|
475
475
|
error: BaseException | None,
|
|
@@ -492,9 +492,9 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
492
492
|
|
|
493
493
|
def on_feature_setup(
|
|
494
494
|
self,
|
|
495
|
-
environment:
|
|
496
|
-
sandbox:
|
|
497
|
-
feature:
|
|
495
|
+
environment: interface.Environment,
|
|
496
|
+
sandbox: interface.Sandbox,
|
|
497
|
+
feature: interface.Feature,
|
|
498
498
|
duration: float,
|
|
499
499
|
error: BaseException | None
|
|
500
500
|
) -> None:
|
|
@@ -517,9 +517,9 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
517
517
|
|
|
518
518
|
def on_feature_teardown(
|
|
519
519
|
self,
|
|
520
|
-
environment:
|
|
521
|
-
sandbox:
|
|
522
|
-
feature:
|
|
520
|
+
environment: interface.Environment,
|
|
521
|
+
sandbox: interface.Sandbox,
|
|
522
|
+
feature: interface.Feature,
|
|
523
523
|
duration: float,
|
|
524
524
|
error: BaseException | None
|
|
525
525
|
) -> None:
|
|
@@ -542,9 +542,9 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
542
542
|
|
|
543
543
|
def on_feature_setup_session(
|
|
544
544
|
self,
|
|
545
|
-
environment:
|
|
546
|
-
sandbox:
|
|
547
|
-
feature:
|
|
545
|
+
environment: interface.Environment,
|
|
546
|
+
sandbox: interface.Sandbox,
|
|
547
|
+
feature: interface.Feature,
|
|
548
548
|
session_id: str | None,
|
|
549
549
|
duration: float,
|
|
550
550
|
error: BaseException | None
|
|
@@ -568,9 +568,9 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
568
568
|
|
|
569
569
|
def on_feature_teardown_session(
|
|
570
570
|
self,
|
|
571
|
-
environment:
|
|
572
|
-
sandbox:
|
|
573
|
-
feature:
|
|
571
|
+
environment: interface.Environment,
|
|
572
|
+
sandbox: interface.Sandbox,
|
|
573
|
+
feature: interface.Feature,
|
|
574
574
|
session_id: str,
|
|
575
575
|
duration: float,
|
|
576
576
|
error: BaseException | None
|
|
@@ -594,9 +594,9 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
594
594
|
|
|
595
595
|
def on_feature_housekeep(
|
|
596
596
|
self,
|
|
597
|
-
environment:
|
|
598
|
-
sandbox:
|
|
599
|
-
feature:
|
|
597
|
+
environment: interface.Environment,
|
|
598
|
+
sandbox: interface.Sandbox,
|
|
599
|
+
feature: interface.Feature,
|
|
600
600
|
counter: int,
|
|
601
601
|
duration: float,
|
|
602
602
|
error: BaseException | None,
|
|
@@ -621,8 +621,8 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
621
621
|
|
|
622
622
|
def on_session_start(
|
|
623
623
|
self,
|
|
624
|
-
environment:
|
|
625
|
-
sandbox:
|
|
624
|
+
environment: interface.Environment,
|
|
625
|
+
sandbox: interface.Sandbox,
|
|
626
626
|
session_id: str,
|
|
627
627
|
duration: float,
|
|
628
628
|
error: BaseException | None
|
|
@@ -638,8 +638,8 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
638
638
|
|
|
639
639
|
def on_session_end(
|
|
640
640
|
self,
|
|
641
|
-
environment:
|
|
642
|
-
sandbox:
|
|
641
|
+
environment: interface.Environment,
|
|
642
|
+
sandbox: interface.Sandbox,
|
|
643
643
|
session_id: str,
|
|
644
644
|
duration: float,
|
|
645
645
|
lifetime: float,
|
|
@@ -664,9 +664,9 @@ class MetricWriter(pg.Object, base.EventHandler):
|
|
|
664
664
|
def on_sandbox_activity(
|
|
665
665
|
self,
|
|
666
666
|
name: str,
|
|
667
|
-
environment:
|
|
668
|
-
sandbox:
|
|
669
|
-
feature:
|
|
667
|
+
environment: interface.Environment,
|
|
668
|
+
sandbox: interface.Sandbox,
|
|
669
|
+
feature: interface.Feature | None,
|
|
670
670
|
session_id: str | None,
|
|
671
671
|
duration: float,
|
|
672
672
|
error: BaseException | None,
|