hydraflow 0.6.1__py3-none-any.whl → 0.7.0__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.
@@ -236,7 +236,7 @@ class RunCollection:
236
236
 
237
237
  def filter(
238
238
  self,
239
- config: object | None = None,
239
+ config: object | Callable[[Run], bool] | None = None,
240
240
  *,
241
241
  override: bool = False,
242
242
  select: list[str] | None = None,
@@ -257,11 +257,13 @@ class RunCollection:
257
257
  - Membership checks for lists of values.
258
258
  - Range checks for tuples of two values (inclusive of both the lower
259
259
  and upper bound).
260
+ - Callable that takes a `Run` object and returns a boolean value.
260
261
 
261
262
  Args:
262
- config (object | None): The configuration object to filter the runs.
263
- This can be any object that provides key-value pairs through
264
- the `iter_params` function.
263
+ config (object | Callable[[Run], bool] | None): The configuration object
264
+ to filter the runs. This can be any object that provides key-value
265
+ pairs through the `iter_params` function, or a callable that
266
+ takes a `Run` object and returns a boolean value.
265
267
  override (bool): If True, override the configuration object with the
266
268
  provided key-value pairs.
267
269
  select (list[str] | None): The list of parameters to select.
@@ -284,105 +286,11 @@ class RunCollection:
284
286
  ),
285
287
  )
286
288
 
287
- def find(self, config: object | None = None, **kwargs) -> Run:
288
- """Find the first `Run` instance based on the provided configuration.
289
-
290
- This method filters the runs in the collection according to the
291
- specified configuration object and returns the first run that matches
292
- the provided parameters. If no run matches the criteria, a `ValueError`
293
- is raised.
294
-
295
- Args:
296
- config (object | None): The configuration object to identify the run.
297
- **kwargs: Additional key-value pairs to filter the runs.
298
-
299
- Returns:
300
- The first `Run` instance that matches the provided configuration.
301
-
302
- Raises:
303
- ValueError: If no run matches the criteria.
304
-
305
- See Also:
306
- `filter`: Perform the actual filtering logic.
307
-
308
- """
309
- try:
310
- return self.filter(config, **kwargs).first()
311
- except ValueError:
312
- raise ValueError("No run matches the provided configuration.")
313
-
314
- def try_find(self, config: object | None = None, **kwargs) -> Run | None:
315
- """Try to find the first `Run` instance based on the provided configuration.
316
-
317
- This method filters the runs in the collection according to the
318
- specified configuration object and returns the first run that matches
319
- the provided parameters. If no run matches the criteria, None is
320
- returned.
321
-
322
- Args:
323
- config (object | None): The configuration object to identify the run.
324
- **kwargs: Additional key-value pairs to filter the runs.
325
-
326
- Returns:
327
- The first `Run` instance that matches the provided configuration, or
328
- None if no runs match the criteria.
329
-
330
- See Also:
331
- `filter`: Perform the actual filtering logic.
332
-
333
- """
334
- return self.filter(config, **kwargs).try_first()
335
-
336
- def find_last(self, config: object | None = None, **kwargs) -> Run:
337
- """Find the last `Run` instance based on the provided configuration.
338
-
339
- This method filters the runs in the collection according to the
340
- specified configuration object and returns the last run that matches
341
- the provided parameters. If no run matches the criteria, a `ValueError`
342
- is raised.
343
-
344
- Args:
345
- config (object | None): The configuration object to identify the run.
346
- **kwargs: Additional key-value pairs to filter the runs.
347
-
348
- Returns:
349
- The last `Run` instance that matches the provided configuration.
350
-
351
- Raises:
352
- ValueError: If no run matches the criteria.
353
-
354
- See Also:
355
- `filter`: Perform the actual filtering logic.
356
-
357
- """
358
- try:
359
- return self.filter(config, **kwargs).last()
360
- except ValueError:
361
- raise ValueError("No run matches the provided configuration.")
362
-
363
- def try_find_last(self, config: object | None = None, **kwargs) -> Run | None:
364
- """Try to find the last `Run` instance based on the provided configuration.
365
-
366
- This method filters the runs in the collection according to the
367
- specified configuration object and returns the last run that matches
368
- the provided parameters. If no run matches the criteria, None is
369
- returned.
370
-
371
- Args:
372
- config (object | None): The configuration object to identify the run.
373
- **kwargs: Additional key-value pairs to filter the runs.
374
-
375
- Returns:
376
- The last `Run` instance that matches the provided configuration, or
377
- None if no runs match the criteria.
378
-
379
- See Also:
380
- `filter`: Perform the actual filtering logic.
381
-
382
- """
383
- return self.filter(config, **kwargs).try_last()
384
-
385
- def get(self, config: object | None = None, **kwargs) -> Run:
289
+ def get(
290
+ self,
291
+ config: object | Callable[[Run], bool] | None = None,
292
+ **kwargs,
293
+ ) -> Run:
386
294
  """Retrieve a specific `Run` instance based on the provided configuration.
387
295
 
388
296
  This method filters the runs in the collection according to the
@@ -391,7 +299,10 @@ class RunCollection:
391
299
  one run matches the criteria, a `ValueError` is raised.
392
300
 
393
301
  Args:
394
- config (object | None): The configuration object to identify the run.
302
+ config (object | Callable[[Run], bool] | None): The configuration object
303
+ to identify the run. This can be any object that provides key-value
304
+ pairs through the `iter_params` function, or a callable that
305
+ takes a `Run` object and returns a boolean value.
395
306
  **kwargs: Additional key-value pairs to filter the runs.
396
307
 
397
308
  Returns:
@@ -411,7 +322,11 @@ class RunCollection:
411
322
  msg = "The filtered collection does not contain exactly one run."
412
323
  raise ValueError(msg)
413
324
 
414
- def try_get(self, config: object | None = None, **kwargs) -> Run | None:
325
+ def try_get(
326
+ self,
327
+ config: object | Callable[[Run], bool] | None = None,
328
+ **kwargs,
329
+ ) -> Run | None:
415
330
  """Try to get a specific `Run` instance based on the provided configuration.
416
331
 
417
332
  This method filters the runs in the collection according to the
@@ -420,7 +335,10 @@ class RunCollection:
420
335
  If more than one run matches the criteria, a `ValueError` is raised.
421
336
 
422
337
  Args:
423
- config (object | None): The configuration object to identify the run.
338
+ config (object | Callable[[Run], bool] | None): The configuration object
339
+ to identify the run. This can be any object that provides key-value
340
+ pairs through the `iter_params` function, or a callable that
341
+ takes a `Run` object and returns a boolean value.
424
342
  **kwargs: Additional key-value pairs to filter the runs.
425
343
 
426
344
  Returns:
@@ -711,7 +629,7 @@ def _param_matches(run: Run, key: str, value: Any) -> bool:
711
629
 
712
630
  def filter_runs(
713
631
  runs: list[Run],
714
- config: object | None = None,
632
+ config: object | Callable[[Run], bool] | None = None,
715
633
  *,
716
634
  override: bool = False,
717
635
  select: list[str] | None = None,
@@ -735,9 +653,11 @@ def filter_runs(
735
653
 
736
654
  Args:
737
655
  runs (list[Run]): The list of runs to filter.
738
- config (object | None, optional): The configuration object to filter the
739
- runs. This can be any object that provides key-value pairs through
740
- the `iter_params` function. Defaults to None.
656
+ config (object | Callable[[Run], bool] | None, optional): The
657
+ configuration object to filter the runs. This can be any object
658
+ that provides key-value pairs through the `iter_params` function.
659
+ This can also be a callable that takes a `Run` object and returns
660
+ a boolean value. Defaults to None.
741
661
  override (bool, optional): If True, filter the runs based on
742
662
  the overrides. Defaults to False.
743
663
  select (list[str] | None, optional): The list of parameters to select.
@@ -750,15 +670,19 @@ def filter_runs(
750
670
  A list of runs that match the specified configuration and key-value pairs.
751
671
 
752
672
  """
753
- if override:
754
- config = select_overrides(config)
755
- elif select:
756
- config = select_config(config, select)
757
-
758
- for key, value in chain(iter_params(config), kwargs.items()):
759
- runs = [run for run in runs if _param_matches(run, key, value)]
760
- if not runs:
761
- return []
673
+ if callable(config):
674
+ runs = [run for run in runs if config(run)]
675
+
676
+ else:
677
+ if override:
678
+ config = select_overrides(config)
679
+ elif select:
680
+ config = select_config(config, select)
681
+
682
+ for key, value in chain(iter_params(config), kwargs.items()):
683
+ runs = [run for run in runs if _param_matches(run, key, value)]
684
+ if not runs:
685
+ return []
762
686
 
763
687
  if status is None:
764
688
  return runs
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hydraflow
3
- Version: 0.6.1
3
+ Version: 0.7.0
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
@@ -4,11 +4,11 @@ hydraflow/context.py,sha256=3xfKhMozkKFqtWeOp9Gie0A5o5URMta4US6iVD5TcLU,6002
4
4
  hydraflow/mlflow.py,sha256=imD3XL0RTlpnKrkyvO8FNy_Bv6hwSfLiOu1yJuL40ck,8773
5
5
  hydraflow/param.py,sha256=yu1aMNXRLegXGDL-68vwIkfeDF9CaU784WZENGLwl7Q,4572
6
6
  hydraflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- hydraflow/run_collection.py,sha256=2GRVOy87_2SPjHuCzzUvRNugO_grtFUVjtTfhznwBAc,27444
7
+ hydraflow/run_collection.py,sha256=YCWg5Dz1j49xB2LA75onq5wsAeQQbifXpG4yPUwRN4I,24776
8
8
  hydraflow/run_data.py,sha256=dpyyfnuH9mCtIZeigMo1iFQo9bafMdEL4i4uI2l0UqY,1525
9
9
  hydraflow/run_info.py,sha256=Jf5wrIjRLIV1-k-obHDqwKHa6j_ZonrY8od-rXlbtMo,1024
10
10
  hydraflow/utils.py,sha256=a9i5PEJn8Ssowv9dqHadAihZXlsqtVjHZ9MZvkPq1bY,4747
11
- hydraflow-0.6.1.dist-info/METADATA,sha256=FzLPE3L9VlZdrYOicnzTda7BhHuLTU0-WRz02TLgt6c,4700
12
- hydraflow-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
- hydraflow-0.6.1.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
14
- hydraflow-0.6.1.dist-info/RECORD,,
11
+ hydraflow-0.7.0.dist-info/METADATA,sha256=hfKlxd1X1BKemmK_ph-ylWe4JaBCSw5SnXxK4MIKBN0,4700
12
+ hydraflow-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
+ hydraflow-0.7.0.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
14
+ hydraflow-0.7.0.dist-info/RECORD,,