hydraflow 0.5.3__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.
hydraflow/config.py CHANGED
@@ -22,7 +22,6 @@ def collect_params(config: object) -> dict[str, Any]:
22
22
 
23
23
  Returns:
24
24
  dict[str, Any]: A dictionary of collected parameters.
25
-
26
25
  """
27
26
  return dict(iter_params(config))
28
27
 
@@ -41,7 +40,6 @@ def iter_params(config: object, prefix: str = "") -> Iterator[tuple[str, Any]]:
41
40
 
42
41
  Yields:
43
42
  Key-value pairs representing the parameters in the configuration object.
44
-
45
43
  """
46
44
  if config is None:
47
45
  return
@@ -115,7 +113,6 @@ def select_config(config: object, names: list[str]) -> dict[str, Any]:
115
113
 
116
114
  Returns:
117
115
  DictConfig: A new configuration object containing only the selected parameters.
118
-
119
116
  """
120
117
  if not isinstance(config, DictConfig):
121
118
  config = OmegaConf.structured(config)
hydraflow/context.py CHANGED
@@ -48,7 +48,6 @@ def log_run(
48
48
  # Perform operations within the MLflow run context
49
49
  pass
50
50
  ```
51
-
52
51
  """
53
52
  if config:
54
53
  log_params(config, synchronous=synchronous)
@@ -118,7 +117,6 @@ def start_run( # noqa: PLR0913
118
117
  - `mlflow.start_run`: The MLflow function to start a run directly.
119
118
  - `log_run`: A context manager to log parameters and manage the MLflow
120
119
  run context.
121
-
122
120
  """
123
121
  with (
124
122
  mlflow.start_run(
@@ -169,7 +167,6 @@ def chdir_artifact(
169
167
  Args:
170
168
  run (Run): The run to get the artifact directory from.
171
169
  artifact_path (str | None): The artifact path.
172
-
173
170
  """
174
171
  curdir = Path.cwd()
175
172
  path = mlflow.artifacts.download_artifacts(
hydraflow/mlflow.py CHANGED
@@ -54,7 +54,6 @@ def set_experiment(
54
54
  Returns:
55
55
  Experiment: An instance of `mlflow.entities.Experiment` representing
56
56
  the new active experiment.
57
-
58
57
  """
59
58
  if uri is not None:
60
59
  mlflow.set_tracking_uri(uri)
@@ -78,7 +77,6 @@ def log_params(config: object, *, synchronous: bool | None = None) -> None:
78
77
  config (object): The configuration object to log the parameters from.
79
78
  synchronous (bool | None): Whether to log the parameters synchronously.
80
79
  Defaults to None.
81
-
82
80
  """
83
81
  for key, value in iter_params(config):
84
82
  mlflow.log_param(key, value, synchronous=synchronous)
@@ -135,7 +133,6 @@ def search_runs( # noqa: PLR0913
135
133
 
136
134
  Returns:
137
135
  A `RunCollection` object containing the search results.
138
-
139
136
  """
140
137
  runs = mlflow.search_runs(
141
138
  experiment_ids=experiment_ids,
@@ -180,7 +177,6 @@ def list_runs(
180
177
  Returns:
181
178
  RunCollection: A `RunCollection` instance containing the runs for the
182
179
  specified experiments.
183
-
184
180
  """
185
181
  rc = _list_runs(experiment_names, n_jobs)
186
182
  if status is None:
hydraflow/param.py CHANGED
@@ -18,7 +18,7 @@ if TYPE_CHECKING:
18
18
  from mlflow.entities import Run
19
19
 
20
20
 
21
- def match(param: str, value: Any) -> bool:
21
+ def match(param: str, value: Any) -> bool: # noqa: PLR0911
22
22
  """Check if the string matches the specified value.
23
23
 
24
24
  Args:
@@ -28,8 +28,10 @@ def match(param: str, value: Any) -> bool:
28
28
  Returns:
29
29
  True if the parameter matches the specified value,
30
30
  False otherwise.
31
-
32
31
  """
32
+ if callable(value):
33
+ return value(param)
34
+
33
35
  if any(value is x for x in [None, True, False]):
34
36
  return param == str(value)
35
37
 
@@ -92,7 +94,6 @@ def to_value(param: str | None, type_: type) -> Any:
92
94
 
93
95
  Returns:
94
96
  The converted value.
95
-
96
97
  """
97
98
  if param is None or param == "None":
98
99
  return None
@@ -128,7 +129,6 @@ def get_params(run: Run, *names: str | list[str]) -> tuple[str | None, ...]:
128
129
  Returns:
129
130
  tuple[str | None, ...]: A tuple containing the values of the specified
130
131
  parameters in the order they were provided.
131
-
132
132
  """
133
133
  names_ = []
134
134
  for name in names:
@@ -155,7 +155,6 @@ def get_values(run: Run, names: list[str], types: list[type]) -> tuple[Any, ...]
155
155
  Returns:
156
156
  tuple[Any, ...]: A tuple containing the values of the specified
157
157
  parameters in the order they were provided.
158
-
159
158
  """
160
159
  params = get_params(run, names)
161
160
  it = zip(params, types, strict=True)
@@ -106,7 +106,6 @@ class RunCollection:
106
106
 
107
107
  Returns:
108
108
  A new `RunCollection` instance with the runs from both collections.
109
-
110
109
  """
111
110
  return self.__class__(self._runs + other._runs)
112
111
 
@@ -119,7 +118,6 @@ class RunCollection:
119
118
  Returns:
120
119
  A new `RunCollection` instance with the runs that are in this collection
121
120
  but not in the other.
122
-
123
121
  """
124
122
  runs = [run for run in self._runs if run not in other._runs] # noqa: SLF001
125
123
  return self.__class__(runs)
@@ -152,7 +150,6 @@ class RunCollection:
152
150
  Returns:
153
151
  A new `RunCollection` instance containing the first n runs if n is
154
152
  positive, or the last n runs if n is negative.
155
-
156
153
  """
157
154
  if n < 0:
158
155
  return self.__class__(self._runs[n:])
@@ -167,7 +164,6 @@ class RunCollection:
167
164
 
168
165
  Raises:
169
166
  ValueError: If the collection does not contain exactly one run.
170
-
171
167
  """
172
168
  if len(self._runs) != 1:
173
169
  raise ValueError("The collection does not contain exactly one run.")
@@ -180,7 +176,6 @@ class RunCollection:
180
176
  Returns:
181
177
  The only `Run` instance in the collection, or None if the collection
182
178
  does not contain exactly one run.
183
-
184
179
  """
185
180
  return self._runs[0] if len(self._runs) == 1 else None
186
181
 
@@ -192,7 +187,6 @@ class RunCollection:
192
187
 
193
188
  Raises:
194
189
  ValueError: If the collection is empty.
195
-
196
190
  """
197
191
  if not self._runs:
198
192
  raise ValueError("The collection is empty.")
@@ -205,7 +199,6 @@ class RunCollection:
205
199
  Returns:
206
200
  The first `Run` instance in the collection, or None if the collection
207
201
  is empty.
208
-
209
202
  """
210
203
  return self._runs[0] if self._runs else None
211
204
 
@@ -217,7 +210,6 @@ class RunCollection:
217
210
 
218
211
  Raises:
219
212
  ValueError: If the collection is empty.
220
-
221
213
  """
222
214
  if not self._runs:
223
215
  raise ValueError("The collection is empty.")
@@ -230,11 +222,18 @@ class RunCollection:
230
222
  Returns:
231
223
  The last `Run` instance in the collection, or None if the collection
232
224
  is empty.
233
-
234
225
  """
235
226
  return self._runs[-1] if self._runs else None
236
227
 
237
- def filter(self, config: object | None = None, **kwargs) -> RunCollection:
228
+ def filter(
229
+ self,
230
+ config: object | None = None,
231
+ *,
232
+ override: bool = False,
233
+ select: list[str] | None = None,
234
+ status: str | list[str] | int | list[int] | None = None,
235
+ **kwargs,
236
+ ) -> RunCollection:
238
237
  """Filter the `Run` instances based on the provided configuration.
239
238
 
240
239
  This method filters the runs in the collection according to the
@@ -254,13 +253,26 @@ class RunCollection:
254
253
  config (object | None): The configuration object to filter the runs.
255
254
  This can be any object that provides key-value pairs through
256
255
  the `iter_params` function.
256
+ override (bool): If True, override the configuration object with the
257
+ provided key-value pairs.
258
+ select (list[str] | None): The list of parameters to select.
259
+ status (str | list[str] | int | list[int] | None): The status of the
260
+ runs to filter.
257
261
  **kwargs: Additional key-value pairs to filter the runs.
258
262
 
259
263
  Returns:
260
264
  A new `RunCollection` object containing the filtered runs.
261
-
262
265
  """
263
- return RunCollection(filter_runs(self._runs, config, **kwargs))
266
+ return RunCollection(
267
+ filter_runs(
268
+ self._runs,
269
+ config,
270
+ override=override,
271
+ select=select,
272
+ status=status,
273
+ **kwargs,
274
+ ),
275
+ )
264
276
 
265
277
  def find(self, config: object | None = None, **kwargs) -> Run:
266
278
  """Find the first `Run` instance based on the provided configuration.
@@ -282,7 +294,6 @@ class RunCollection:
282
294
 
283
295
  See Also:
284
296
  `filter`: Perform the actual filtering logic.
285
-
286
297
  """
287
298
  try:
288
299
  return self.filter(config, **kwargs).first()
@@ -307,7 +318,6 @@ class RunCollection:
307
318
 
308
319
  See Also:
309
320
  `filter`: Perform the actual filtering logic.
310
-
311
321
  """
312
322
  return self.filter(config, **kwargs).try_first()
313
323
 
@@ -331,7 +341,6 @@ class RunCollection:
331
341
 
332
342
  See Also:
333
343
  `filter`: Perform the actual filtering logic.
334
-
335
344
  """
336
345
  try:
337
346
  return self.filter(config, **kwargs).last()
@@ -356,7 +365,6 @@ class RunCollection:
356
365
 
357
366
  See Also:
358
367
  `filter`: Perform the actual filtering logic.
359
-
360
368
  """
361
369
  return self.filter(config, **kwargs).try_last()
362
370
 
@@ -381,7 +389,6 @@ class RunCollection:
381
389
 
382
390
  See Also:
383
391
  `filter`: Perform the actual filtering logic.
384
-
385
392
  """
386
393
  try:
387
394
  return self.filter(config, **kwargs).one()
@@ -410,7 +417,6 @@ class RunCollection:
410
417
 
411
418
  See Also:
412
419
  `filter`: Perform the actual filtering logic.
413
-
414
420
  """
415
421
  return self.filter(config, **kwargs).try_one()
416
422
 
@@ -423,7 +429,6 @@ class RunCollection:
423
429
 
424
430
  Returns:
425
431
  A list of unique parameter names.
426
-
427
432
  """
428
433
  param_names = set()
429
434
 
@@ -448,7 +453,6 @@ class RunCollection:
448
453
  Returns:
449
454
  A dictionary where the keys are parameter names and the values are
450
455
  lists of parameter values.
451
-
452
456
  """
453
457
  params = {}
454
458
 
@@ -480,7 +484,6 @@ class RunCollection:
480
484
 
481
485
  Yields:
482
486
  Results obtained by applying the function to each run in the collection.
483
-
484
487
  """
485
488
  return (func(run, *args, **kwargs) for run in self)
486
489
 
@@ -501,7 +504,6 @@ class RunCollection:
501
504
  Yields:
502
505
  Results obtained by applying the function to each run id in the
503
506
  collection.
504
-
505
507
  """
506
508
  return (func(run_id, *args, **kwargs) for run_id in self.info.run_id)
507
509
 
@@ -522,7 +524,6 @@ class RunCollection:
522
524
  Yields:
523
525
  Results obtained by applying the function to each run configuration
524
526
  in the collection.
525
-
526
527
  """
527
528
  return (func(load_config(run), *args, **kwargs) for run in self)
528
529
 
@@ -547,7 +548,6 @@ class RunCollection:
547
548
  Yields:
548
549
  Results obtained by applying the function to each artifact URI in the
549
550
  collection.
550
-
551
551
  """
552
552
  return (func(uri, *args, **kwargs) for uri in self.info.artifact_uri)
553
553
 
@@ -571,7 +571,6 @@ class RunCollection:
571
571
  Yields:
572
572
  Results obtained by applying the function to each artifact directory
573
573
  in the collection.
574
-
575
574
  """
576
575
  return (func(dir, *args, **kwargs) for dir in self.info.artifact_dir) # noqa: A001
577
576
 
@@ -595,7 +594,6 @@ class RunCollection:
595
594
  dictionary where the keys are tuples of parameter values and the
596
595
  values are `RunCollection` objects containing the runs that match
597
596
  those parameter values.
598
-
599
597
  """
600
598
  grouped_runs: dict[str | None | tuple[str | None, ...], list[Run]] = {}
601
599
  is_list = isinstance(names, list)
@@ -622,7 +620,6 @@ class RunCollection:
622
620
  key (Callable[[Run], Any] | None): A function that takes a run and returns
623
621
  a value to sort by.
624
622
  reverse (bool): If True, sort in descending order.
625
-
626
623
  """
627
624
  self._runs.sort(key=key or (lambda x: x.info.start_time), reverse=reverse)
628
625
 
@@ -636,7 +633,6 @@ class RunCollection:
636
633
 
637
634
  Returns:
638
635
  A list of values for the specified parameters.
639
-
640
636
  """
641
637
  is_list = isinstance(names, list)
642
638
 
@@ -668,7 +664,6 @@ class RunCollection:
668
664
  This can be a single parameter name or multiple names provided
669
665
  as separate arguments or as a list.
670
666
  reverse (bool): If True, sort in descending order.
671
-
672
667
  """
673
668
  values = self.values(names)
674
669
  index = sorted(range(len(self)), key=lambda i: values[i], reverse=reverse)
@@ -726,7 +721,6 @@ def filter_runs(
726
721
 
727
722
  Returns:
728
723
  A list of runs that match the specified configuration and key-value pairs.
729
-
730
724
  """
731
725
  if override:
732
726
  config = select_overrides(config)
@@ -757,7 +751,6 @@ def filter_runs_by_status(
757
751
 
758
752
  Returns:
759
753
  A list of runs that match the specified status.
760
-
761
754
  """
762
755
  if isinstance(status, str):
763
756
  if status.startswith("!"):
hydraflow/run_data.py CHANGED
@@ -37,7 +37,6 @@ class RunCollectionData:
37
37
 
38
38
  Returns:
39
39
  A DataFrame containing the runs' configurations.
40
-
41
40
  """
42
41
  return DataFrame(self._runs.map_config(collect_params))
43
42
 
hydraflow/utils.py CHANGED
@@ -26,7 +26,6 @@ def get_artifact_dir(run: Run | None = None) -> Path:
26
26
 
27
27
  Returns:
28
28
  The local path to the directory where the artifacts are downloaded.
29
-
30
29
  """
31
30
  uri = mlflow.get_artifact_uri() if run is None else run.info.artifact_uri
32
31
 
@@ -53,7 +52,6 @@ def get_artifact_path(run: Run | None, path: str) -> Path:
53
52
 
54
53
  Returns:
55
54
  The local path to the artifact.
56
-
57
55
  """
58
56
  return get_artifact_dir(run) / path
59
57
 
@@ -76,7 +74,6 @@ def get_hydra_output_dir(run: Run | None = None) -> Path:
76
74
  Raises:
77
75
  FileNotFoundError: If the Hydra configuration file is not found
78
76
  in the artifacts.
79
-
80
77
  """
81
78
  if run is None:
82
79
  hc = HydraConfig.get()
@@ -105,7 +102,6 @@ def load_config(run: Run) -> DictConfig:
105
102
  Returns:
106
103
  The loaded configuration as a DictConfig object. Returns an empty
107
104
  DictConfig if the configuration file is not found.
108
-
109
105
  """
110
106
  path = get_artifact_dir(run) / ".hydra/config.yaml"
111
107
  return OmegaConf.load(path) # type: ignore
@@ -130,7 +126,6 @@ def load_overrides(run: Run) -> list[str]:
130
126
  Returns:
131
127
  The loaded overrides as a list of strings. Returns an empty list
132
128
  if the overrides file is not found.
133
-
134
129
  """
135
130
  path = get_artifact_dir(run) / ".hydra/overrides.yaml"
136
131
  return [str(x) for x in OmegaConf.load(path)]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hydraflow
3
- Version: 0.5.3
3
+ Version: 0.5.4
4
4
  Summary: Hydraflow integrates Hydra and MLflow to manage and track machine learning experiments.
5
5
  Project-URL: Documentation, https://daizutabi.github.io/hydraflow/
6
6
  Project-URL: Source, https://github.com/daizutabi/hydraflow
@@ -0,0 +1,14 @@
1
+ hydraflow/__init__.py,sha256=9XO9FD3uiTTPN6X6UAC9FtkJjEqUQZNqpoAmSrjUHfI,855
2
+ hydraflow/config.py,sha256=k6pwneDoC4mb7cVkafMfITn8QemICPnFbhIRGLsmF4w,4323
3
+ hydraflow/context.py,sha256=KukvVexCF32myBOryYMVhINknbAgPFcanmr4cT2EXog,5521
4
+ hydraflow/mlflow.py,sha256=TVp6O9rYNYcdqnlssstXQlI_P_N6inUG-F01X6uJNv4,8928
5
+ hydraflow/param.py,sha256=kuVlxEfgoKL35rNu49M-PkdNr41djK0YZ5IO7fHTSSU,4568
6
+ hydraflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ hydraflow/run_collection.py,sha256=mMGpr6cAh9Bf2SeRsYNHySOQJNrWNMI7esDWzyMxnJg,27415
8
+ hydraflow/run_data.py,sha256=V_yhkBsJlDTkLbh1TShkvDxUQYUYTpXFahXJGfdmgro,1524
9
+ hydraflow/run_info.py,sha256=Jf5wrIjRLIV1-k-obHDqwKHa6j_ZonrY8od-rXlbtMo,1024
10
+ hydraflow/utils.py,sha256=ha-gSq3TkWWOlKmnDuyLNCuKNQdEG08CXRzKtb3C4mk,4344
11
+ hydraflow-0.5.4.dist-info/METADATA,sha256=ijJv5powqpMjZ1adDCWdLxRLeEaosmKF3gG74L25fCs,4700
12
+ hydraflow-0.5.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
+ hydraflow-0.5.4.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
14
+ hydraflow-0.5.4.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- hydraflow/__init__.py,sha256=9XO9FD3uiTTPN6X6UAC9FtkJjEqUQZNqpoAmSrjUHfI,855
2
- hydraflow/config.py,sha256=MNX9da5bPVDcjnpji7Cm9ndK6ura92pt361m4PRh6_E,4326
3
- hydraflow/context.py,sha256=3g7OQXWcFvK6PVVbXpQg7Hr8nsJkF9pLFrXNi_3aV5A,5524
4
- hydraflow/mlflow.py,sha256=h2S_A2wElr_1lAq0D1wkoEfdtDZpPuWFNRcO8mV_VrA,8932
5
- hydraflow/param.py,sha256=c5sc6NwD6DKwZzVwprXzZD5FSi6qRgSHkc6TXBKQEdg,4502
6
- hydraflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- hydraflow/run_collection.py,sha256=zPrlKwLuzqePj57pXbgKWrE03S_kjxTaxY9trItf6Gc,26772
8
- hydraflow/run_data.py,sha256=dpyyfnuH9mCtIZeigMo1iFQo9bafMdEL4i4uI2l0UqY,1525
9
- hydraflow/run_info.py,sha256=Jf5wrIjRLIV1-k-obHDqwKHa6j_ZonrY8od-rXlbtMo,1024
10
- hydraflow/utils.py,sha256=oXjcyfQBbPzJNTh3_CbZfl23zgJS-mbNM9GAWBwsn8c,4349
11
- hydraflow-0.5.3.dist-info/METADATA,sha256=8grWqDq2SBXtVljA72NnKJPJjwaWmjOOXIvGSOP5kqM,4700
12
- hydraflow-0.5.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
- hydraflow-0.5.3.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
14
- hydraflow-0.5.3.dist-info/RECORD,,