ml-dash 0.0.17__py3-none-any.whl → 0.2.1__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.
Files changed (48) hide show
  1. ml_dash/__init__.py +58 -1
  2. ml_dash/client.py +562 -0
  3. ml_dash/experiment.py +916 -0
  4. ml_dash/files.py +313 -0
  5. ml_dash/log.py +181 -0
  6. ml_dash/metric.py +186 -0
  7. ml_dash/params.py +188 -0
  8. ml_dash/storage.py +922 -0
  9. ml_dash-0.2.1.dist-info/METADATA +237 -0
  10. ml_dash-0.2.1.dist-info/RECORD +12 -0
  11. ml_dash-0.2.1.dist-info/WHEEL +4 -0
  12. app-build/asset-manifest.json +0 -15
  13. app-build/favicon.ico +0 -0
  14. app-build/github-markdown.css +0 -957
  15. app-build/index.html +0 -1
  16. app-build/manifest.json +0 -15
  17. app-build/monaco-editor-worker-loader-proxy.js +0 -6
  18. app-build/precache-manifest.ffc09f8a591c529a1bd5c6f21f49815f.js +0 -26
  19. app-build/service-worker.js +0 -34
  20. ml_dash/app.py +0 -60
  21. ml_dash/config.py +0 -16
  22. ml_dash/file_events.py +0 -71
  23. ml_dash/file_handlers.py +0 -141
  24. ml_dash/file_utils.py +0 -5
  25. ml_dash/file_watcher.py +0 -30
  26. ml_dash/main.py +0 -60
  27. ml_dash/mime_types.py +0 -20
  28. ml_dash/schema/__init__.py +0 -110
  29. ml_dash/schema/archive.py +0 -165
  30. ml_dash/schema/directories.py +0 -59
  31. ml_dash/schema/experiments.py +0 -65
  32. ml_dash/schema/files/__init__.py +0 -204
  33. ml_dash/schema/files/file_helpers.py +0 -79
  34. ml_dash/schema/files/images.py +0 -27
  35. ml_dash/schema/files/metrics.py +0 -64
  36. ml_dash/schema/files/parameters.py +0 -50
  37. ml_dash/schema/files/series.py +0 -235
  38. ml_dash/schema/files/videos.py +0 -27
  39. ml_dash/schema/helpers.py +0 -66
  40. ml_dash/schema/projects.py +0 -65
  41. ml_dash/schema/schema_helpers.py +0 -19
  42. ml_dash/schema/users.py +0 -33
  43. ml_dash/sse.py +0 -18
  44. ml_dash-0.0.17.dist-info/METADATA +0 -67
  45. ml_dash-0.0.17.dist-info/RECORD +0 -38
  46. ml_dash-0.0.17.dist-info/WHEEL +0 -5
  47. ml_dash-0.0.17.dist-info/top_level.txt +0 -2
  48. /ml_dash/{example.py → py.typed} +0 -0
ml_dash/params.py ADDED
@@ -0,0 +1,188 @@
1
+ """
2
+ Parameters module for ML-Dash SDK.
3
+
4
+ Provides fluent API for parameter management with automatic dict flattening.
5
+ Nested dicts are flattened to dot-notation: {"model": {"lr": 0.001}} → {"model.lr": 0.001}
6
+ """
7
+
8
+ from typing import Dict, Any, Optional, TYPE_CHECKING
9
+
10
+ if TYPE_CHECKING:
11
+ from .experiment import Experiment
12
+
13
+
14
+ class ParametersBuilder:
15
+ """
16
+ Fluent interface for parameter operations.
17
+
18
+ Usage:
19
+ experiment.parameters().set(model={"lr": 0.001}, optimizer="adam")
20
+ params = experiment.parameters().get()
21
+ params_nested = experiment.parameters().get(flatten=False)
22
+ """
23
+
24
+ def __init__(self, experiment: 'Experiment'):
25
+ """
26
+ Initialize parameters builder.
27
+
28
+ Args:
29
+ experiment: Parent experiment instance
30
+ """
31
+ self._experiment = experiment
32
+
33
+ def set(self, **kwargs) -> 'ParametersBuilder':
34
+ """
35
+ Set/merge parameters. Always merges with existing parameters (upsert behavior).
36
+
37
+ Nested dicts are automatically flattened:
38
+ set(model={"lr": 0.001, "batch_size": 32})
39
+ → {"model.lr": 0.001, "model.batch_size": 32}
40
+
41
+ Args:
42
+ **kwargs: Parameters to set (can be nested dicts)
43
+
44
+ Returns:
45
+ Self for potential chaining
46
+
47
+ Raises:
48
+ RuntimeError: If experiment is not open
49
+ RuntimeError: If experiment is write-protected
50
+
51
+ Examples:
52
+ # Set nested parameters
53
+ experiment.parameters().set(
54
+ model={"lr": 0.001, "batch_size": 32},
55
+ optimizer="adam"
56
+ )
57
+
58
+ # Merge/update specific parameters
59
+ experiment.parameters().set(model={"lr": 0.0001}) # Only updates model.lr
60
+
61
+ # Set flat parameters with dot notation
62
+ experiment.parameters().set(**{"model.lr": 0.001, "model.batch_size": 32})
63
+ """
64
+ if not self._experiment._is_open:
65
+ raise RuntimeError("Experiment not open. Use experiment.open() or context manager.")
66
+
67
+ if self._experiment.write_protected:
68
+ raise RuntimeError("Experiment is write-protected and cannot be modified.")
69
+
70
+ # Flatten the kwargs
71
+ flattened = self.flatten_dict(kwargs)
72
+
73
+ if not flattened:
74
+ # No parameters to set, just return
75
+ return self
76
+
77
+ # Write parameters through experiment
78
+ self._experiment._write_params(flattened)
79
+
80
+ return self
81
+
82
+ def get(self, flatten: bool = True) -> Dict[str, Any]:
83
+ """
84
+ Get parameters from the experiment.
85
+
86
+ Args:
87
+ flatten: If True, returns flattened dict with dot notation.
88
+ If False, returns nested dict structure.
89
+
90
+ Returns:
91
+ Parameters dict (flattened or nested based on flatten arg)
92
+
93
+ Raises:
94
+ RuntimeError: If experiment is not open
95
+
96
+ Examples:
97
+ # Get flattened parameters
98
+ params = experiment.parameters().get()
99
+ # → {"model.lr": 0.001, "model.batch_size": 32, "optimizer": "adam"}
100
+
101
+ # Get nested parameters
102
+ params = experiment.parameters().get(flatten=False)
103
+ # → {"model": {"lr": 0.001, "batch_size": 32}, "optimizer": "adam"}
104
+ """
105
+ if not self._experiment._is_open:
106
+ raise RuntimeError("Experiment not open. Use experiment.open() or context manager.")
107
+
108
+ # Read parameters through experiment
109
+ params = self._experiment._read_params()
110
+
111
+ if params is None:
112
+ return {}
113
+
114
+ # Return as-is if flatten=True (stored flattened), or unflatten if needed
115
+ if flatten:
116
+ return params
117
+ else:
118
+ return self.unflatten_dict(params)
119
+
120
+ @staticmethod
121
+ def flatten_dict(d: Dict[str, Any], parent_key: str = '', sep: str = '.') -> Dict[str, Any]:
122
+ """
123
+ Flatten a nested dictionary into dot-notation keys.
124
+
125
+ Args:
126
+ d: Dictionary to flatten (can contain nested dicts)
127
+ parent_key: Prefix for keys (used in recursion)
128
+ sep: Separator character (default: '.')
129
+
130
+ Returns:
131
+ Flattened dictionary with dot-notation keys
132
+
133
+ Examples:
134
+ >>> flatten_dict({"a": {"b": 1, "c": 2}, "d": 3})
135
+ {"a.b": 1, "a.c": 2, "d": 3}
136
+
137
+ >>> flatten_dict({"model": {"lr": 0.001, "layers": {"hidden": 128}}})
138
+ {"model.lr": 0.001, "model.layers.hidden": 128}
139
+ """
140
+ items = []
141
+
142
+ for k, v in d.items():
143
+ new_key = f"{parent_key}{sep}{k}" if parent_key else k
144
+
145
+ if isinstance(v, dict):
146
+ # Recursively flatten nested dicts
147
+ items.extend(ParametersBuilder.flatten_dict(v, new_key, sep=sep).items())
148
+ else:
149
+ # Keep non-dict values as-is
150
+ items.append((new_key, v))
151
+
152
+ return dict(items)
153
+
154
+ @staticmethod
155
+ def unflatten_dict(d: Dict[str, Any], sep: str = '.') -> Dict[str, Any]:
156
+ """
157
+ Unflatten a dot-notation dictionary into nested structure.
158
+
159
+ Args:
160
+ d: Flattened dictionary with dot-notation keys
161
+ sep: Separator character (default: '.')
162
+
163
+ Returns:
164
+ Nested dictionary structure
165
+
166
+ Examples:
167
+ >>> unflatten_dict({"a.b": 1, "a.c": 2, "d": 3})
168
+ {"a": {"b": 1, "c": 2}, "d": 3}
169
+
170
+ >>> unflatten_dict({"model.lr": 0.001, "model.layers.hidden": 128})
171
+ {"model": {"lr": 0.001, "layers": {"hidden": 128}}}
172
+ """
173
+ result = {}
174
+
175
+ for key, value in d.items():
176
+ parts = key.split(sep)
177
+ current = result
178
+
179
+ # Navigate/create nested structure
180
+ for part in parts[:-1]:
181
+ if part not in current:
182
+ current[part] = {}
183
+ current = current[part]
184
+
185
+ # Set the final value
186
+ current[parts[-1]] = value
187
+
188
+ return result