ml-dash 0.5.2__py3-none-any.whl → 0.5.4__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.
ml_dash/experiment.py CHANGED
@@ -791,7 +791,7 @@ class Experiment:
791
791
 
792
792
  def _append_to_metric(
793
793
  self,
794
- name: str,
794
+ name: Optional[str],
795
795
  data: Dict[str, Any],
796
796
  description: Optional[str],
797
797
  tags: Optional[List[str]],
@@ -801,7 +801,7 @@ class Experiment:
801
801
  Internal method to append a single data point to a metric.
802
802
 
803
803
  Args:
804
- name: Metric name
804
+ name: Metric name (can be None for unnamed metrics)
805
805
  data: Data point (flexible schema)
806
806
  description: Optional metric description
807
807
  tags: Optional tags
@@ -839,7 +839,7 @@ class Experiment:
839
839
 
840
840
  def _append_batch_to_metric(
841
841
  self,
842
- name: str,
842
+ name: Optional[str],
843
843
  data_points: List[Dict[str, Any]],
844
844
  description: Optional[str],
845
845
  tags: Optional[List[str]],
@@ -849,7 +849,7 @@ class Experiment:
849
849
  Internal method to append multiple data points to a metric.
850
850
 
851
851
  Args:
852
- name: Metric name
852
+ name: Metric name (can be None for unnamed metrics)
853
853
  data_points: List of data points
854
854
  description: Optional metric description
855
855
  tags: Optional tags
ml_dash/files.py CHANGED
@@ -263,11 +263,12 @@ class FileBuilder:
263
263
  if self._experiment._write_protected:
264
264
  raise RuntimeError("Experiment is write-protected and cannot be modified.")
265
265
 
266
- # Create temporary file
267
- temp_fd, temp_path = tempfile.mkstemp(suffix='.json', text=True)
266
+ # Create temporary file with desired filename
267
+ temp_dir = tempfile.mkdtemp()
268
+ temp_path = os.path.join(temp_dir, file_name)
268
269
  try:
269
270
  # Write JSON content to temp file
270
- with os.fdopen(temp_fd, 'w') as f:
271
+ with open(temp_path, 'w') as f:
271
272
  json.dump(content, f, indent=2)
272
273
 
273
274
  # Save using existing save() method
@@ -282,9 +283,10 @@ class FileBuilder:
282
283
 
283
284
  return result
284
285
  finally:
285
- # Clean up temp file
286
+ # Clean up temp file and directory
286
287
  try:
287
288
  os.unlink(temp_path)
289
+ os.rmdir(temp_dir)
288
290
  except Exception:
289
291
  pass
290
292
 
@@ -326,9 +328,9 @@ class FileBuilder:
326
328
  if self._experiment._write_protected:
327
329
  raise RuntimeError("Experiment is write-protected and cannot be modified.")
328
330
 
329
- # Create temporary file
330
- temp_fd, temp_path = tempfile.mkstemp(suffix='.pt')
331
- os.close(temp_fd) # Close the file descriptor
331
+ # Create temporary file with desired filename
332
+ temp_dir = tempfile.mkdtemp()
333
+ temp_path = os.path.join(temp_dir, file_name)
332
334
 
333
335
  try:
334
336
  # Save model to temp file
@@ -346,9 +348,69 @@ class FileBuilder:
346
348
 
347
349
  return result
348
350
  finally:
349
- # Clean up temp file
351
+ # Clean up temp file and directory
350
352
  try:
351
353
  os.unlink(temp_path)
354
+ os.rmdir(temp_dir)
355
+ except Exception:
356
+ pass
357
+
358
+ def save_pkl(self, content: Any, file_name: str) -> Dict[str, Any]:
359
+ """
360
+ Save Python object to a pickle file.
361
+
362
+ Args:
363
+ content: Python object to pickle (must be pickle-serializable)
364
+ file_name: Name of the file to create (should end with .pkl or .pickle)
365
+
366
+ Returns:
367
+ File metadata dict with id, path, filename, checksum, etc.
368
+
369
+ Raises:
370
+ RuntimeError: If experiment is not open or write-protected
371
+ ValueError: If content cannot be pickled
372
+
373
+ Examples:
374
+ data = {"model": "resnet50", "weights": np.array([1, 2, 3])}
375
+ result = experiment.file(prefix="/data").save_pkl(data, "data.pkl")
376
+
377
+ # Or save any Python object
378
+ result = experiment.file(prefix="/models").save_pkl(trained_model, "model.pickle")
379
+ """
380
+ import pickle
381
+ import tempfile
382
+ import os
383
+
384
+ if not self._experiment._is_open:
385
+ raise RuntimeError("Experiment not open. Use experiment.run.start() or context manager.")
386
+
387
+ if self._experiment._write_protected:
388
+ raise RuntimeError("Experiment is write-protected and cannot be modified.")
389
+
390
+ # Create temporary file with desired filename
391
+ temp_dir = tempfile.mkdtemp()
392
+ temp_path = os.path.join(temp_dir, file_name)
393
+ try:
394
+ # Write pickled content to temp file
395
+ with open(temp_path, 'wb') as f:
396
+ pickle.dump(content, f)
397
+
398
+ # Save using existing save() method
399
+ original_file_path = self._file_path
400
+ self._file_path = temp_path
401
+
402
+ # Upload and get result
403
+ result = self.save()
404
+
405
+ # Restore original file_path
406
+ self._file_path = original_file_path
407
+
408
+ return result
409
+ finally:
410
+ # Clean up temp file and directory
411
+ try:
412
+ os.unlink(temp_path)
413
+ os.rmdir(temp_dir)
352
414
  except Exception:
353
415
  pass
354
416
 
ml_dash/metric.py CHANGED
@@ -15,16 +15,20 @@ class MetricsManager:
15
15
  """
16
16
  Manager for metric operations that supports both named and unnamed usage.
17
17
 
18
- Supports two usage patterns:
19
- 1. Named: experiment.metrics("loss").append(value=0.5, step=1)
20
- 2. Unnamed: experiment.metrics.append(name="loss", value=0.5, step=1)
18
+ Supports three usage patterns:
19
+ 1. Named via call: experiment.metrics("loss").append(value=0.5, step=1)
20
+ 2. Named via argument: experiment.metrics.append(name="loss", value=0.5, step=1)
21
+ 3. Unnamed: experiment.metrics.append(value=0.5, step=1) # name=None
21
22
 
22
23
  Usage:
23
- # With explicit metric name
24
+ # With explicit metric name (via call)
24
25
  experiment.metrics("train_loss").append(value=0.5, step=100)
25
26
 
26
- # Without specifying name upfront (name in append call)
27
+ # With explicit metric name (via argument)
27
28
  experiment.metrics.append(name="train_loss", value=0.5, step=100)
29
+
30
+ # Without name (uses None as metric name)
31
+ experiment.metrics.append(value=0.5, step=100)
28
32
  """
29
33
 
30
34
  def __init__(self, experiment: 'Experiment'):
@@ -55,12 +59,12 @@ class MetricsManager:
55
59
  """
56
60
  return MetricBuilder(self._experiment, name, description, tags, metadata)
57
61
 
58
- def append(self, name: str, data: Optional[Dict[str, Any]] = None, **kwargs) -> Dict[str, Any]:
62
+ def append(self, name: Optional[str] = None, data: Optional[Dict[str, Any]] = None, **kwargs) -> Dict[str, Any]:
59
63
  """
60
- Append a data point to a metric (name specified in call).
64
+ Append a data point to a metric (name can be optional).
61
65
 
62
66
  Args:
63
- name: Metric name
67
+ name: Metric name (optional, can be None for unnamed metrics)
64
68
  data: Data dict (alternative to kwargs)
65
69
  **kwargs: Data as keyword arguments
66
70
 
@@ -69,13 +73,14 @@ class MetricsManager:
69
73
 
70
74
  Examples:
71
75
  experiment.metrics.append(name="loss", value=0.5, step=1)
76
+ experiment.metrics.append(value=0.5, step=1) # name=None
72
77
  experiment.metrics.append(name="loss", data={"value": 0.5, "step": 1})
73
78
  """
74
79
  if data is None:
75
80
  data = kwargs
76
81
  return self._experiment._append_to_metric(name, data, None, None, None)
77
82
 
78
- def append_batch(self, name: str, data_points: List[Dict[str, Any]],
83
+ def append_batch(self, name: Optional[str] = None, data_points: Optional[List[Dict[str, Any]]] = None,
79
84
  description: Optional[str] = None,
80
85
  tags: Optional[List[str]] = None,
81
86
  metadata: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
@@ -83,7 +88,7 @@ class MetricsManager:
83
88
  Append multiple data points to a metric.
84
89
 
85
90
  Args:
86
- name: Metric name
91
+ name: Metric name (optional, can be None for unnamed metrics)
87
92
  data_points: List of data point dicts
88
93
  description: Optional metric description
89
94
  tags: Optional tags for categorization
@@ -100,7 +105,15 @@ class MetricsManager:
100
105
  {"value": 0.4, "step": 2}
101
106
  ]
102
107
  )
108
+ experiment.metrics.append_batch(
109
+ data_points=[
110
+ {"value": 0.5, "step": 1},
111
+ {"value": 0.4, "step": 2}
112
+ ]
113
+ ) # name=None
103
114
  """
115
+ if data_points is None:
116
+ data_points = []
104
117
  return self._experiment._append_batch_to_metric(name, data_points, description, tags, metadata)
105
118
 
106
119
 
ml_dash/storage.py CHANGED
@@ -636,7 +636,7 @@ class LocalStorage:
636
636
  self,
637
637
  project: str,
638
638
  experiment: str,
639
- metric_name: str,
639
+ metric_name: Optional[str],
640
640
  data: Dict[str, Any],
641
641
  description: Optional[str] = None,
642
642
  tags: Optional[List[str]] = None,
@@ -653,7 +653,7 @@ class LocalStorage:
653
653
  Args:
654
654
  project: Project name
655
655
  experiment: Experiment name
656
- metric_name: Metric name
656
+ metric_name: Metric name (None for unnamed metrics)
657
657
  data: Data point (flexible schema)
658
658
  description: Optional metric description
659
659
  tags: Optional tags
@@ -666,7 +666,9 @@ class LocalStorage:
666
666
  metrics_dir = experiment_dir / "metrics"
667
667
  metrics_dir.mkdir(parents=True, exist_ok=True)
668
668
 
669
- metric_dir = metrics_dir / metric_name
669
+ # Convert None to string for directory name
670
+ dir_name = str(metric_name) if metric_name is not None else "None"
671
+ metric_dir = metrics_dir / dir_name
670
672
  metric_dir.mkdir(exist_ok=True)
671
673
 
672
674
  data_file = metric_dir / "data.jsonl"
@@ -720,7 +722,7 @@ class LocalStorage:
720
722
  self,
721
723
  project: str,
722
724
  experiment: str,
723
- metric_name: str,
725
+ metric_name: Optional[str],
724
726
  data_points: List[Dict[str, Any]],
725
727
  description: Optional[str] = None,
726
728
  tags: Optional[List[str]] = None,
@@ -732,7 +734,7 @@ class LocalStorage:
732
734
  Args:
733
735
  project: Project name
734
736
  experiment: Experiment name
735
- metric_name: Metric name
737
+ metric_name: Metric name (None for unnamed metrics)
736
738
  data_points: List of data points
737
739
  description: Optional metric description
738
740
  tags: Optional tags
@@ -745,7 +747,9 @@ class LocalStorage:
745
747
  metrics_dir = experiment_dir / "metrics"
746
748
  metrics_dir.mkdir(parents=True, exist_ok=True)
747
749
 
748
- metric_dir = metrics_dir / metric_name
750
+ # Convert None to string for directory name
751
+ dir_name = str(metric_name) if metric_name is not None else "None"
752
+ metric_dir = metrics_dir / dir_name
749
753
  metric_dir.mkdir(exist_ok=True)
750
754
 
751
755
  data_file = metric_dir / "data.jsonl"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ml-dash
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: ML experiment tracking and data storage
5
5
  Keywords: machine-learning,experiment-tracking,mlops,data-storage
6
6
  Author: Ge Yang, Tom Tao
@@ -0,0 +1,13 @@
1
+ ml_dash/__init__.py,sha256=o_LrWVJBY_VkUGhSBs5wdb_NqEsHD1AK9HGsjZGxHxQ,1414
2
+ ml_dash/auto_start.py,sha256=c3XcXFpZdvjtWauEoK5043Gw9k0L_5IDq4fdiB2ha88,959
3
+ ml_dash/client.py,sha256=vhWcS5o2n3o4apEjVeLmu7flCEzxBbBOoLSQNcAx_ew,17267
4
+ ml_dash/experiment.py,sha256=efEdKkA3KBOlC-uNEXVtun1ARiZ_AQG3nOGAUsLLZ5Q,30640
5
+ ml_dash/files.py,sha256=Nx7f0n9zoQ7XqPtiHu_SBEZK0cT2b3F6-EhJBNs3C6k,15824
6
+ ml_dash/log.py,sha256=0yXaNnFwYeBI3tRLHX3kkqWRpg0MbSGwmgjnOfsElCk,5350
7
+ ml_dash/metric.py,sha256=c0Zl0wEufmQuVfwIMvrORLwqe92Iaf0PfKRgmlgQWzQ,10343
8
+ ml_dash/params.py,sha256=xaByDSVar4D1pZqxTANkMPeZTL5-V7ewJe5TXfPLhMQ,5980
9
+ ml_dash/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ ml_dash/storage.py,sha256=8lyT5ZdvhS2nEyrEgMnFAT0LzV5ne1v8tkI3w1PUHJ4,30793
11
+ ml_dash-0.5.4.dist-info/WHEEL,sha256=X16MKk8bp2DRsAuyteHJ-9qOjzmnY0x1aj0P1ftqqWA,78
12
+ ml_dash-0.5.4.dist-info/METADATA,sha256=5qFL8t0ikhtuAIC65zYAZAYt24n937KA5RzJEreBxU0,6043
13
+ ml_dash-0.5.4.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- ml_dash/__init__.py,sha256=o_LrWVJBY_VkUGhSBs5wdb_NqEsHD1AK9HGsjZGxHxQ,1414
2
- ml_dash/auto_start.py,sha256=c3XcXFpZdvjtWauEoK5043Gw9k0L_5IDq4fdiB2ha88,959
3
- ml_dash/client.py,sha256=vhWcS5o2n3o4apEjVeLmu7flCEzxBbBOoLSQNcAx_ew,17267
4
- ml_dash/experiment.py,sha256=zdGB3oZsFNFyg9olRazWk7dTO7tfy-vTa4neFq5i2CY,30552
5
- ml_dash/files.py,sha256=FZGHqf5VZ6Hgrpbng-AwTZyw04-Zof252YSjF6nRWX8,13667
6
- ml_dash/log.py,sha256=0yXaNnFwYeBI3tRLHX3kkqWRpg0MbSGwmgjnOfsElCk,5350
7
- ml_dash/metric.py,sha256=LMb6-T08VAl6UBAv6FlZee6LleVLjFaBNc19b17NlfI,9662
8
- ml_dash/params.py,sha256=xaByDSVar4D1pZqxTANkMPeZTL5-V7ewJe5TXfPLhMQ,5980
9
- ml_dash/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- ml_dash/storage.py,sha256=UTuux2nfclLrrtlkC6TsOvDB_wIbSDvYGg8Gtbvk6mc,30471
11
- ml_dash-0.5.2.dist-info/WHEEL,sha256=X16MKk8bp2DRsAuyteHJ-9qOjzmnY0x1aj0P1ftqqWA,78
12
- ml_dash-0.5.2.dist-info/METADATA,sha256=ZbZgasRMgq0iQ5VqPGbySV-pm9HJJlDNU8g4Zs6nFiM,6043
13
- ml_dash-0.5.2.dist-info/RECORD,,