|
| 1 | +import logging |
1 | 2 | from pathlib import Path |
2 | 3 |
|
3 | | -from .storage import TrackioStorage |
4 | | -from .ui import launch_ui |
| 4 | +from trackio.run import Run, current_run |
| 5 | +from trackio.ui import launch_ui |
5 | 6 |
|
6 | 7 | __version__ = Path(__file__).parent.joinpath("version.txt").read_text().strip() |
7 | 8 |
|
8 | | -_current_run = None |
9 | | - |
10 | | - |
11 | | -class Run: |
12 | | - def __init__(self, project, name, config): |
13 | | - self.project = project |
14 | | - self.name = name |
15 | | - self.config = config |
16 | | - self.storage = TrackioStorage(project, name, config) |
17 | | - |
18 | | - def log(self, metrics): |
19 | | - self.storage.log(metrics) |
20 | | - |
21 | | - def finish(self): |
22 | | - self.storage.finish() |
23 | | - |
24 | 9 |
|
25 | 10 | def init(project, name=None, config=None): |
26 | | - global _current_run |
27 | | - _current_run = Run(project, name, config) |
28 | | - return _current_run |
| 11 | + logging.info(f"Initializing run | Project: {project} | Name: {name}") |
| 12 | + current_run.set(Run(project, name, config)) |
29 | 13 |
|
30 | 14 |
|
31 | 15 | def log(metrics): |
32 | | - if _current_run is None: |
| 16 | + if current_run.get() is None: |
33 | 17 | raise RuntimeError("Call trackio.init() before log().") |
34 | | - _current_run.log(metrics) |
| 18 | + current_run.get().log(metrics) |
35 | 19 |
|
36 | 20 |
|
37 | 21 | def finish(): |
38 | | - if _current_run is None: |
| 22 | + if current_run.get() is None: |
39 | 23 | raise RuntimeError("Call trackio.init() before finish().") |
40 | | - _current_run.finish() |
41 | | - global _current_run |
42 | | - _current_run = None |
| 24 | + current_run.get().finish() |
| 25 | + current_run.set(None) |
43 | 26 |
|
44 | 27 |
|
45 | 28 | def ui(): |
|
0 commit comments