robo-goggles 0.1.0__tar.gz

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 robo-goggles might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Antonio Terpin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,600 @@
1
+ Metadata-Version: 2.4
2
+ Name: robo-goggles
3
+ Version: 0.1.0
4
+ Summary: Observability framework for robotics research
5
+ Author-email: Antonio Terpin <aterpin@ethz.ch>, Francesco Banelli <fbanelli@ethz.ch>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/antonioterpin/goggles
8
+ Project-URL: Repository, https://github.com/antonioterpin/goggles
9
+ Project-URL: Documentation, https://github.com/antonioterpin/goggles#readme
10
+ Project-URL: Issues, https://github.com/antonioterpin/goggles/issues
11
+ Keywords: robotics,logging,observability,jax,wandb,experiment-tracking
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: System :: Logging
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: ruamel.yaml
27
+ Requires-Dist: rich
28
+ Requires-Dist: portal>=3.7.3
29
+ Requires-Dist: typing-extensions>=4.15.0
30
+ Requires-Dist: netifaces>=0.11.0
31
+ Requires-Dist: pyyaml>=6.0.3
32
+ Requires-Dist: numpy>=2.2.6
33
+ Requires-Dist: imageio[ffmpeg,pyav]>=2.37.0
34
+ Requires-Dist: matplotlib>=3.10.7
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
38
+ Requires-Dist: hypothesis>=6.0.0; extra == "dev"
39
+ Requires-Dist: snowballstemmer==2.2.0; extra == "dev"
40
+ Requires-Dist: pre_commit==4.0.1; extra == "dev"
41
+ Requires-Dist: tomli; extra == "dev"
42
+ Provides-Extra: jax
43
+ Requires-Dist: jax>=0.4.0; extra == "jax"
44
+ Requires-Dist: jaxlib>=0.4.0; extra == "jax"
45
+ Provides-Extra: wandb
46
+ Requires-Dist: wandb[media]; extra == "wandb"
47
+ Dynamic: license-file
48
+
49
+ # 😎 Goggles - Observability for Robotics Research
50
+
51
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
52
+ [![GitHub stars](https://img.shields.io/github/stars/antonioterpin/robostack?style=social)](https://github.com/antonioterpin/goggles/stargazers)
53
+ [![codecov](https://codecov.io/gh/antonioterpin/goggles/graph/badge.svg?token=J49B8TFDSM)](https://codecov.io/gh/antonioterpin/goggles)
54
+ [![Tests](https://github.com/antonioterpin/goggles/actions/workflows/test.yaml/badge.svg)](https://github.com/antonioterpin/goggles/actions/workflows/test.yaml)
55
+ [![Code Style](https://github.com/antonioterpin/goggles/actions/workflows/code-style.yaml/badge.svg)](https://github.com/antonioterpin/goggles/actions/workflows/code-style.yaml)
56
+ [![PyPI version](https://img.shields.io/pypi/v/robo-goggles.svg)](https://pypi.org/project/robo-goggles)
57
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
58
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
59
+
60
+
61
+ A lightweight, flexible Python observability framework designed for robotics research. Goggles provides structured logging, experiment tracking, performance profiling, and device-resident temporal memory management for JAX-based pipelines.
62
+
63
+ ## ✨ Features
64
+
65
+ - πŸ€– **Multi-process (and multi-machines) logging** - Synchronize logs across spawned processes reliably and efficiently (shared memory when available).
66
+ - 🎯 **Multi-output support** - Log to console, files, and remote services simultaneously.
67
+ - πŸ“Š **Experiment tracking** - Native integration with Weights & Biases for metrics, images, and videos.
68
+ - πŸ•’ **Performance profiling** - `@goggles.timeit` decorator for automatic runtime measurement.
69
+ - 🐞 **Error tracing** - `@goggles.trace_on_error` auto-logs full stack traces on exceptions.
70
+ - 🧠 **Device-resident histories** - JAX-based GPU memory management for efficient, long-running experiments metrics.
71
+ - 🚦 **Graceful shutdown** - Automatic cleanup of resources and handlers.
72
+ - βš™οΈ **Structured configuration** - YAML-based config loading with validation.
73
+ - πŸ”Œ **Extensible handlers** - Plugin architecture for custom logging backends.
74
+
75
+ ## πŸ—οΈ Projects Built with Goggles
76
+
77
+ This framework has been battle-tested across multiple research projects:
78
+
79
+ [![FluidSControl](https://img.shields.io/badge/GitHub-antonioterpin%2Ffluidscontrol-2ea44f?logo=github)](https://github.com/antonioterpin/fluidscontrol)
80
+ [![FlowGym](https://img.shields.io/badge/GitHub-antonioterpin%2Fflowgym-2ea44f?logo=github)](https://github.com/antonioterpin/flowgym)
81
+ [![SynthPix](https://img.shields.io/badge/GitHub-antonioterpin%2Fsynthpix-2ea44f?logo=github)](https://github.com/antonioterpin/synthpix)
82
+ [![Ξ net](https://img.shields.io/badge/GitHub-antonioterpin%2Fpinet-2ea44f?logo=github)](https://github.com/antonioterpin/pinet)
83
+ [![Glitch](https://img.shields.io/badge/GitHub-antonioterpin%2Fglitch-2ea44f?logo=github)](https://github.com/antonioterpin/glitch)
84
+
85
+ ## πŸš€ Quick Start
86
+
87
+ ### Installation
88
+
89
+ ```bash
90
+ # Basic installation
91
+ uv add robo-goggles # or pip install robo-goggles
92
+
93
+ # With Weights & Biases support
94
+ uv add "robo-goggles[wandb]"
95
+
96
+ # With JAX device-resident histories
97
+ uv add "robo-goggles[jax]"
98
+ ```
99
+
100
+ For the development installation, see our [How to contribute](./CONTRIBUTING.md) page.
101
+
102
+ ### Basic usage
103
+
104
+ ```python
105
+ import goggles as gg
106
+ import logging
107
+
108
+ # Set up console logging
109
+ logger = gg.get_logger("my_experiment")
110
+ gg.attach(
111
+ gg.ConsoleHandler(name="console", level=logging.INFO),
112
+ )
113
+
114
+ # Basic logging
115
+ logger.info("Experiment started")
116
+ logger.warning("This is a warning")
117
+ logger.error("An error occurred")
118
+ ```
119
+
120
+ See also [Example 1](./examples/01_basic_run.py), which you can run after cloning the repo with
121
+ ```bash
122
+ uv run examples/01_basic_run.py
123
+ ```
124
+
125
+ ### Experiment tracking with W&B
126
+
127
+ ```python
128
+ import goggles as gg
129
+ import numpy as np
130
+
131
+ # Enable metrics logging
132
+ logger = gg.get_logger("experiment", with_metrics=True)
133
+ gg.attach(
134
+ gg.WandBHandler(project="my_project", name="run_1"),
135
+ )
136
+
137
+ # Log metrics, images, and videos
138
+ for step in range(100):
139
+ logger.scalar("loss", np.random.random(), step=step)
140
+ logger.scalar("accuracy", 0.8 + 0.2 * np.random.random(), step=step)
141
+
142
+ # Log images and videos
143
+ image = np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)
144
+ logger.image(image, name="sample_image")
145
+
146
+ video = np.random.randint(0, 255, (30, 3, 64, 64), dtype=np.uint8)
147
+ logger.video(video, name="sample_video", fps=10)
148
+
149
+ # Ensure proper cleanup
150
+ gg.finish()
151
+ ```
152
+
153
+ ### Performance profiling and error tracking
154
+
155
+ ```python
156
+ import goggles as gg
157
+ import logging
158
+
159
+ class Trainer:
160
+ @gg.timeit(severity=logging.INFO)
161
+ def train_step(self, batch):
162
+ # Your training logic here
163
+ return {"loss": 0.1}
164
+
165
+ @gg.trace_on_error()
166
+ def risky_operation(self, data):
167
+ # This will log full traceback on any exception
168
+ return data / 0 # Will trigger trace logging
169
+
170
+ trainer = Trainer()
171
+ trainer.train_step({"x": [1, 2, 3]}) # Logs execution time
172
+
173
+ try:
174
+ trainer.risky_operation(10)
175
+ except ZeroDivisionError:
176
+ pass # Full traceback was automatically logged
177
+ ```
178
+
179
+ ### Configuration Management
180
+
181
+ Load and validate YAML configurations:
182
+
183
+ ```python
184
+ import goggles
185
+
186
+ # Load configuration with automatic validation
187
+ config = goggles.load_configuration("config.yaml")
188
+ print(config) # Pretty print
189
+ print(config["learning_rate"]) # Access as dict
190
+
191
+ # Pretty-print configuration
192
+ goggles.save_configuration(config, "output.yaml")
193
+ ```
194
+
195
+ ### Supported Platforms πŸ’»
196
+
197
+ | Platform | Basic | W&B | JAX/GPU | Development |
198
+ |----------|-------|-----|---------|-------------|
199
+ | Linux | βœ… | βœ… | βœ… | βœ… |
200
+ | macOS | βœ… | βœ… | βœ… | βœ… |
201
+ | Windows | βœ… | βœ… | ❌ | βœ… |
202
+
203
+ *GPU support requires CUDA-compatible hardware and drivers*
204
+
205
+ ## πŸ”₯ Examples
206
+
207
+ Explore the `examples/` directory for comprehensive usage patterns:
208
+
209
+ ```bash
210
+ # Basic logging setup
211
+ uv run examples/01_basic_run.py
212
+
213
+ # Advanced: Multi-scope logging
214
+ uv run examples/02_multi_scope.py
215
+
216
+ # File-based logging (local storage)
217
+ uv run examples/03_local_storage.py
218
+
219
+ # Weights & Biases integration
220
+ uv run examples/04_wandb.py
221
+
222
+ # Advanced: Weights & Biases multi-run setup
223
+ uv run examples/05_wandb_multiple_runs.py
224
+
225
+ # Advanced: Custom handler
226
+ uv run exacmples/06_custom_handler.py
227
+
228
+ # Graceful shutdown utils
229
+ uv run examples/100_interrupt.py
230
+
231
+ # Pretty and convenient utils for configuration laoding
232
+ uv run examples/101_config.py
233
+
234
+ # Advanced: Performance decorators
235
+ uv run examples/102_decorators.py
236
+
237
+ # Advanced: JAX device-resident histories
238
+ uv run examples/103_history.py
239
+ ```
240
+
241
+ ## 🧠 For Goggles power user
242
+
243
+ This section includes some cool functionalities of `goggles`. Enjoy!
244
+
245
+ ### Multi-scope logging
246
+ Goggles allow easily to set up different handlers for different scopes. That is, one can have an handler attached to multiple scopes, and a scope having multiple handlers. Each logger is associated to a single scope (by default: `global`), and logging with that logger will invoke all the loggers associated with the scope.
247
+
248
+ #### Why?
249
+ Within the same run, we may have logs that belong to different scopes. An example is training in Reinforcement Learning, where in a single training run there are multiple episodes. A complete example for this is provided in the [multiple runs in WandB](#multiple-runs-in-wandb) section.
250
+
251
+ #### Usage
252
+
253
+ ```python
254
+ # In this example, we set up a handlers associated
255
+ # to different scopes.
256
+ handler1 = gg.ConsoleHandler(name="examples.basic.console.1", level=logging.INFO)
257
+ gg.attach(handler1, scopes=["global", "scope1"])
258
+
259
+ handler2 = gg.ConsoleHandler(name="examples.basic.console.2", level=logging.INFO)
260
+ gg.attach(handler2, scopes=["global", "scope2"])
261
+
262
+ # We need to get separate loggers for each scope
263
+ logger_scope1 = gg.get_logger("examples.basic.scope1", scope="scope1")
264
+ logger_scope2 = gg.get_logger("examples.basic.scope2")
265
+ logger_scope2.bind(scope="scope2") # You can also bind the scope after creation
266
+ logger_global = gg.get_logger("examples.basic.global", scope="global")
267
+
268
+ # Now we can log messages to different scopes, so that only the interested
269
+ # handlers will process them.
270
+ logger_scope1.info(f"This will be logged only by {handler1.name}")
271
+ logger_scope2.info(f"This will be logged only by {handler2.name}")
272
+ logger_global.info("This will be logged by both handlers.")
273
+ ```
274
+
275
+ See also [examples/02_multi_scope.py](./examples/02_multi_scope.py) for a running example.
276
+
277
+ ### Multiple runs in WandB
278
+ An example of the benefit of scopes is given by the WandBHandler, which instantiate a different WandB run for each scope and groups them together:
279
+
280
+ ```python
281
+ import goggles as gg
282
+ from goggles import WandBHandler
283
+
284
+ # In this example, we set up multiple runs in Weights & Biases (W&B).
285
+ # All runs created by the handler will be grouped under
286
+ # the same project and group.
287
+ logger: gg.GogglesLogger = gg.get_logger("examples.basic", with_metrics=True)
288
+ handler = WandBHandler(
289
+ project="goggles_example", reinit="create_new", group="multiple_runs"
290
+ )
291
+
292
+ # In particular, we set up multiple runs in an RL training loop, with each
293
+ # episode being a separate W&B run and a global run tracking all episodes.
294
+ num_episodes = 3
295
+ episode_length = 10
296
+ scopes = [f"episode_{episode}" for episode in range(num_episodes + 1)]
297
+ scopes.append("global")
298
+ gg.attach(handler, scopes=scopes)
299
+
300
+
301
+ def my_episode(index: int):
302
+ episode_logger = gg.get_logger(scope=f"episode_{index}", with_metrics=True)
303
+ for step in range(episode_length):
304
+ # Supports scopes transparently
305
+ # and has its own step counter
306
+ episode_logger.scalar("env/reward", index * episode_length + step, step=step)
307
+
308
+
309
+ for i in range(num_episodes):
310
+ my_episode(i)
311
+ logger.scalar("total_reward", i, step=i)
312
+
313
+ # When using asynchronous logging (like wandb), make sure to finish
314
+ gg.finish()
315
+ ```
316
+
317
+ ### Fully asynchronous logging
318
+ As in the WandB example, all the handlers work in the background. By default, the logging calls are blocking, but can be made not blocking by setting the environment variable `GOGGLES_ASYNC` to `1` or `true`. When you use the async mode, remember to call `gg.finish()` at the end from your host machine!
319
+ >[!WARNING]
320
+ > This functionality still needs thorough tesing, as well as a better documentation. Help is appreciated! πŸ€—
321
+
322
+ ### Multi-machine logging
323
+ Goggles provides options to synchronize logging across machines, since there is always only a single server active. The relevant environment variables here are `GOGGLES_HOST` and `GOGGLES_PORT`.
324
+ >[!WARNING]
325
+ > This functionality still needs thorough tesing, as well as a better documentation. Help is appreciated! πŸ€—
326
+
327
+ ### Adding a custom handler
328
+ > [!NOTE]
329
+ > Ideally, you should open a PR: We would love to integrate your work!
330
+
331
+ Adding a custom handler is straightforward:
332
+
333
+ ```python
334
+ import goggles as gg
335
+ import logging
336
+
337
+
338
+ class CustomConsoleHandler(gg.ConsoleHandler):
339
+ """A custom console handler that adds a prefix to each log message."""
340
+
341
+ def handle(self, event: gg.Event) -> None:
342
+ dict = event.to_dict()
343
+
344
+ dict["payload"] = f"[CUSTOM PREFIX] {dict['payload']}"
345
+
346
+ event = gg.Event.from_dict(dict)
347
+ super().handle(event)
348
+
349
+
350
+ # Register the custom handler so it can be serialized/deserialized
351
+ gg.register_handler(CustomConsoleHandler)
352
+
353
+ # In this basic example, we set up a logger that outputs to the console.
354
+ logger = gg.get_logger("examples.custom_handler")
355
+
356
+
357
+ gg.attach(
358
+ CustomConsoleHandler(name="examples.custom.console", level=logging.INFO),
359
+ scopes=["global"],
360
+ )
361
+ # Because the logging level is set to INFO, the debug message will not be shown.
362
+ logger.info("Hello, world!")
363
+ logger.debug("you won't see this at INFO")
364
+
365
+ ```
366
+
367
+ See also [examples/05_custom_handler.py](./examples/06_custom_handler.py) for a complete example.
368
+
369
+ ### Device-resident histories
370
+ For long-running GPU experiments that need efficient temporal memory management:
371
+
372
+ #### Why?
373
+
374
+ During development of fluid control experiments and reinforcement learning pipelines, we needed to:
375
+ - Track detailed metrics during GPU-accelerated training
376
+ - Avoid expensive device-to-host transfers
377
+ - Maintain temporal state across episodes
378
+ - Support JIT compilation for maximum performance
379
+
380
+ #### Features
381
+
382
+ - **Pure functional** and **JIT-safe** buffer updates
383
+ - **Per-field history lengths** with episodic reset support
384
+ - **Batch-first convention**: `(B, T, *shape)` for all tensors
385
+ - **Zero host-device synchronization** during updates
386
+ - **Integrated with FlowGym's** `EstimatorState` for temporal RL memory
387
+
388
+ #### Usage
389
+
390
+ ```python
391
+ from goggles.history import HistorySpec, create_history, update_history
392
+ import jax.numpy as jnp
393
+
394
+ # Define what to track over time
395
+ spec = HistorySpec.from_config({
396
+ "states": {"length": 100, "shape": (64, 64, 2), "dtype": jnp.float32},
397
+ "actions": {"length": 50, "shape": (8,), "dtype": jnp.float32},
398
+ "rewards": {"length": 100, "shape": (), "dtype": jnp.float32},
399
+ })
400
+
401
+ # Create GPU-resident history buffers
402
+ history = create_history(spec, batch_size=32)
403
+ print(history["states"].shape) # (32, 100, 64, 64, 2)
404
+
405
+ # Update buffers during training (JIT-compiled)
406
+ new_state = jnp.ones((32, 64, 64, 2))
407
+ history = update_history(history, {"states": new_state})
408
+ ```
409
+
410
+ See also [examples/103_history.py](./examples/103_history.py) for a running example.
411
+
412
+
413
+ ## 🀝 Contributing
414
+
415
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for detailed information on:
416
+
417
+ β€’ Development workflow and environment setup
418
+ β€’ Code style requirements and automated checks
419
+ β€’ Testing standards and coverage expectations
420
+ β€’ PR preparation and commit message conventions
421
+
422
+ ## πŸ“„ License
423
+
424
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
425
+
426
+ ---
427
+
428
+ *Ready to enhance your robotics research with structured observability? Get started with Goggles today! πŸš€*gles
429
+
430
+ A lightweight, flexible Python logging and monitoring library designed to simplify and enhance experiment tracking, performance profiling, and error tracing. Integrates with terminal, file-based logs, and W\&B (Weights & Biases). It is thought primarily for research projects in robotics.
431
+
432
+ ```bash
433
+ pip install "goggles @ git+ssh://git@github.com/antonioterpin/goggles.git"
434
+ ```
435
+
436
+ ## Features
437
+
438
+ - πŸ€– **Multi-process, single-thread compatible**
439
+ Synchronize logs from all spawned processes via shared memory.
440
+
441
+ - 🎯 **Multi-output logging**
442
+ Log to terminal and/or file.
443
+
444
+ - πŸ•’ **Performance profiling**
445
+ `@goggles.timeit` decorator measures and logs runtime.
446
+
447
+ - 🐞 **Error tracing**
448
+ `@goggles.trace_on_error` auto-logs full stack on exceptions.
449
+
450
+ - πŸ“Š **Metrics tracking**
451
+ `goggles.scalar`, `goggles.vector`, `goggles.image`, `goggles.video` β†’ Weights & Biases.
452
+
453
+ - 🚦 **Graceful shutdown**
454
+ Call `goggles.cleanup()` (or hook into your own `signal` handler).
455
+
456
+ - βš™οΈ **Asynchronous scheduling**
457
+ Offload heavy logging tasks via `goggles.schedule_log(...)`.
458
+
459
+ - πŸ“ **Pretty configuration loading**
460
+ `goggles.load_configuration(...)` loads YAML with validation.
461
+
462
+ ## Quickstart
463
+
464
+ 1. TODO: update
465
+
466
+ 2. **Ready to log**:
467
+
468
+ ```python
469
+ import goggles
470
+
471
+ goggles.debug("Debugging details…")
472
+ goggles.info("Experiment started")
473
+ goggles.warning("This is a warning")
474
+ goggles.error("An error occurred")
475
+ ```
476
+
477
+ We cleanup all the resources automatically at exit.
478
+
479
+ ## Configuration
480
+
481
+ Pretty logging of configuration files.
482
+
483
+ ```python
484
+ import goggles
485
+
486
+ # Load from examples/example_config.yaml
487
+ config = goggles.load_configuration("examples/example_config.yaml")
488
+ print(config)
489
+
490
+ # Access as dict
491
+ print(f"time_per_experiment = {config['time_per_experiment']}")
492
+ ```
493
+
494
+ ## Decorators: `@goggles.timeit` and `@goggles.trace_on_error`
495
+
496
+ Measure execution time of methods or functions:
497
+
498
+ ```python
499
+ import goggles
500
+
501
+ class Worker:
502
+ @goggles.timeit(severity=logging.DEBUG)
503
+ def compute_heavy(self, n):
504
+ return sum(range(n))
505
+
506
+ @goggles.trace_on_error()
507
+ def risky_division(self, x, y):
508
+ return x / y
509
+
510
+ g = Worker()
511
+ g.compute_heavy(1_000_000)
512
+
513
+ try:
514
+ g.risky_division(1, 0)
515
+ except ZeroDivisionError:
516
+ pass # Full traceback was logged
517
+ ```
518
+
519
+ ## W\&B Integration
520
+
521
+ Log scalars, vectors, images, and videos directly to Weights & Biases:
522
+
523
+ ```python
524
+ import goggles
525
+ from PIL import Image
526
+ import numpy as np
527
+
528
+ # Start or switch a W&B run
529
+ goggles.new_wandb_run(name="exp-run", config={"lr":1e-3, "batch":32})
530
+
531
+ # Scalars & histograms
532
+ goggles.scalar("accuracy", 0.92)
533
+ goggles.vector("loss_curve", [0.5,0.4,0.3])
534
+
535
+ # Images
536
+ img = Image.fromarray((np.random.rand(64,64,3)*255).astype(np.uint8))
537
+ goggles.image("random_image", img)
538
+ ```
539
+
540
+ ## Graceful Shutdown
541
+
542
+ Cleanly handle interrupts (e.g., Ctrl-C) and perform cleanup:
543
+
544
+ ```python
545
+ import goggles
546
+ from PIL import Image
547
+ import numpy as np
548
+
549
+ # Start or switch a W&B run
550
+ goggles.new_wandb_run(name="exp-run", config={"lr":1e-3, "batch":32})
551
+
552
+ # Scalars & histograms
553
+ goggles.scalar("accuracy", 0.92)
554
+ goggles.vector("loss_curve", [0.5,0.4,0.3])
555
+
556
+ # Images
557
+ img = Image.fromarray((np.random.rand(64,64,3)*255).astype(np.uint8))
558
+ goggles.image("random_image", img)
559
+
560
+ ```
561
+
562
+ ## Asynchronous Logging & Video
563
+
564
+ Offload heavy logging tasks to worker threads and log video sequences:
565
+
566
+ ```python
567
+ import goggles, numpy as np, time
568
+ from PIL import Image
569
+
570
+ goggles.new_wandb_run("video_demo", {})
571
+ goggles.init_scheduler(num_workers=4)
572
+
573
+ def save_and_log_frame(frame, idx):v
574
+ path = f"/tmp/frame_{idx}.png"
575
+ frame.save(path)
576
+ goggles.image(f"frame_{idx}", frame)
577
+
578
+ for i in range(100):
579
+ arr = (np.random.rand(64,64,3)*255).astype(np.uint8)
580
+ img = Image.fromarray(arr)
581
+ goggles.schedule_log(save_and_log_frame, img, i)
582
+ goggles.scalar("queue_size", goggles._task_queue.qsize())
583
+
584
+ goggles.stop_workers()
585
+ ```
586
+
587
+ ## Full list of running examples
588
+
589
+ We prepared an `examples/` folder with scripts covering:
590
+
591
+ TODO
592
+
593
+ ## Contributing
594
+
595
+ PRs, issues, and feature requests are welcome! Open an issue or submit a PR on GitHub.
596
+ See our [contributing guide](./CONTRIBUTING.md) for more information.
597
+
598
+ ## License
599
+
600
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.