hydraflow 0.6.2__py3-none-any.whl → 0.7.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
hydraflow/__init__.py CHANGED
@@ -1,10 +1,11 @@
1
1
  """Integrate Hydra and MLflow to manage and track machine learning experiments."""
2
2
 
3
- from .config import select_config, select_overrides
4
- from .context import chdir_artifact, log_run, start_run
5
- from .mlflow import list_runs, search_runs, set_experiment
6
- from .run_collection import RunCollection
7
- from .utils import (
3
+ from hydraflow.config import select_config, select_overrides
4
+ from hydraflow.context import chdir_artifact, log_run, start_run
5
+ from hydraflow.main import main
6
+ from hydraflow.mlflow import list_runs, search_runs, set_experiment
7
+ from hydraflow.run_collection import RunCollection
8
+ from hydraflow.utils import (
8
9
  get_artifact_dir,
9
10
  get_artifact_path,
10
11
  get_hydra_output_dir,
@@ -25,6 +26,7 @@ __all__ = [
25
26
  "load_config",
26
27
  "load_overrides",
27
28
  "log_run",
29
+ "main",
28
30
  "remove_run",
29
31
  "search_runs",
30
32
  "select_config",
hydraflow/main.py ADDED
@@ -0,0 +1,55 @@
1
+ """main decorator."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from functools import wraps
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ import hydra
9
+ from hydra.core.config_store import ConfigStore
10
+ from mlflow.entities import RunStatus
11
+
12
+ import hydraflow
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Callable
16
+
17
+ from mlflow.entities import Run
18
+
19
+ FINISHED = RunStatus.to_string(RunStatus.FINISHED)
20
+
21
+
22
+ def main(
23
+ node: Any,
24
+ config_name: str = "config",
25
+ *,
26
+ chdir: bool = True,
27
+ skip_finished: bool = True,
28
+ force_new_run: bool = False,
29
+ override: bool = True,
30
+ ):
31
+ """Main decorator."""
32
+
33
+ def decorator(app: Callable[[Run, Any], None]) -> Callable[[], None]:
34
+ ConfigStore.instance().store(name=config_name, node=node)
35
+
36
+ @wraps(app)
37
+ @hydra.main(version_base=None, config_name=config_name)
38
+ def inner_app(cfg: object) -> None:
39
+ hydraflow.set_experiment()
40
+
41
+ if force_new_run:
42
+ run = None
43
+ else:
44
+ rc = hydraflow.search_runs()
45
+ run = rc.try_get(cfg, override=override)
46
+
47
+ if skip_finished and run and run.info.status == FINISHED:
48
+ return
49
+
50
+ with hydraflow.start_run(cfg, run=run, chdir=chdir) as run:
51
+ app(run, cfg)
52
+
53
+ return inner_app
54
+
55
+ return decorator
@@ -286,105 +286,11 @@ class RunCollection:
286
286
  ),
287
287
  )
288
288
 
289
- def find(self, config: object | None = None, **kwargs) -> Run:
290
- """Find the first `Run` instance based on the provided configuration.
291
-
292
- This method filters the runs in the collection according to the
293
- specified configuration object and returns the first run that matches
294
- the provided parameters. If no run matches the criteria, a `ValueError`
295
- is raised.
296
-
297
- Args:
298
- config (object | None): The configuration object to identify the run.
299
- **kwargs: Additional key-value pairs to filter the runs.
300
-
301
- Returns:
302
- The first `Run` instance that matches the provided configuration.
303
-
304
- Raises:
305
- ValueError: If no run matches the criteria.
306
-
307
- See Also:
308
- `filter`: Perform the actual filtering logic.
309
-
310
- """
311
- try:
312
- return self.filter(config, **kwargs).first()
313
- except ValueError:
314
- raise ValueError("No run matches the provided configuration.")
315
-
316
- def try_find(self, config: object | None = None, **kwargs) -> Run | None:
317
- """Try to find the first `Run` instance based on the provided configuration.
318
-
319
- This method filters the runs in the collection according to the
320
- specified configuration object and returns the first run that matches
321
- the provided parameters. If no run matches the criteria, None is
322
- returned.
323
-
324
- Args:
325
- config (object | None): The configuration object to identify the run.
326
- **kwargs: Additional key-value pairs to filter the runs.
327
-
328
- Returns:
329
- The first `Run` instance that matches the provided configuration, or
330
- None if no runs match the criteria.
331
-
332
- See Also:
333
- `filter`: Perform the actual filtering logic.
334
-
335
- """
336
- return self.filter(config, **kwargs).try_first()
337
-
338
- def find_last(self, config: object | None = None, **kwargs) -> Run:
339
- """Find the last `Run` instance based on the provided configuration.
340
-
341
- This method filters the runs in the collection according to the
342
- specified configuration object and returns the last run that matches
343
- the provided parameters. If no run matches the criteria, a `ValueError`
344
- is raised.
345
-
346
- Args:
347
- config (object | None): The configuration object to identify the run.
348
- **kwargs: Additional key-value pairs to filter the runs.
349
-
350
- Returns:
351
- The last `Run` instance that matches the provided configuration.
352
-
353
- Raises:
354
- ValueError: If no run matches the criteria.
355
-
356
- See Also:
357
- `filter`: Perform the actual filtering logic.
358
-
359
- """
360
- try:
361
- return self.filter(config, **kwargs).last()
362
- except ValueError:
363
- raise ValueError("No run matches the provided configuration.")
364
-
365
- def try_find_last(self, config: object | None = None, **kwargs) -> Run | None:
366
- """Try to find the last `Run` instance based on the provided configuration.
367
-
368
- This method filters the runs in the collection according to the
369
- specified configuration object and returns the last run that matches
370
- the provided parameters. If no run matches the criteria, None is
371
- returned.
372
-
373
- Args:
374
- config (object | None): The configuration object to identify the run.
375
- **kwargs: Additional key-value pairs to filter the runs.
376
-
377
- Returns:
378
- The last `Run` instance that matches the provided configuration, or
379
- None if no runs match the criteria.
380
-
381
- See Also:
382
- `filter`: Perform the actual filtering logic.
383
-
384
- """
385
- return self.filter(config, **kwargs).try_last()
386
-
387
- 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:
388
294
  """Retrieve a specific `Run` instance based on the provided configuration.
389
295
 
390
296
  This method filters the runs in the collection according to the
@@ -393,7 +299,10 @@ class RunCollection:
393
299
  one run matches the criteria, a `ValueError` is raised.
394
300
 
395
301
  Args:
396
- 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.
397
306
  **kwargs: Additional key-value pairs to filter the runs.
398
307
 
399
308
  Returns:
@@ -413,7 +322,11 @@ class RunCollection:
413
322
  msg = "The filtered collection does not contain exactly one run."
414
323
  raise ValueError(msg)
415
324
 
416
- 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:
417
330
  """Try to get a specific `Run` instance based on the provided configuration.
418
331
 
419
332
  This method filters the runs in the collection according to the
@@ -422,7 +335,10 @@ class RunCollection:
422
335
  If more than one run matches the criteria, a `ValueError` is raised.
423
336
 
424
337
  Args:
425
- 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.
426
342
  **kwargs: Additional key-value pairs to filter the runs.
427
343
 
428
344
  Returns:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hydraflow
3
- Version: 0.6.2
3
+ Version: 0.7.2
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
@@ -1,14 +1,15 @@
1
- hydraflow/__init__.py,sha256=VPIPNNCyjMAkWBbdvB7Ltwe3QWoc2FwuqkV8uJM5JoM,809
1
+ hydraflow/__init__.py,sha256=rujOGabEPPhPfyqTHynem3unqIEQ1haTWWSMuu2LuoQ,898
2
2
  hydraflow/config.py,sha256=MNX9da5bPVDcjnpji7Cm9ndK6ura92pt361m4PRh6_E,4326
3
3
  hydraflow/context.py,sha256=3xfKhMozkKFqtWeOp9Gie0A5o5URMta4US6iVD5TcLU,6002
4
+ hydraflow/main.py,sha256=8DYYxyyS1sToEIoIQlzGcGDNgzIFg3fLnjBufQtQASc,1344
4
5
  hydraflow/mlflow.py,sha256=imD3XL0RTlpnKrkyvO8FNy_Bv6hwSfLiOu1yJuL40ck,8773
5
6
  hydraflow/param.py,sha256=yu1aMNXRLegXGDL-68vwIkfeDF9CaU784WZENGLwl7Q,4572
6
7
  hydraflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- hydraflow/run_collection.py,sha256=w_GZdc_6yviwzRWLndWDSWB4DKyGyA9di9d9UpkkLZo,27926
8
+ hydraflow/run_collection.py,sha256=YCWg5Dz1j49xB2LA75onq5wsAeQQbifXpG4yPUwRN4I,24776
8
9
  hydraflow/run_data.py,sha256=dpyyfnuH9mCtIZeigMo1iFQo9bafMdEL4i4uI2l0UqY,1525
9
10
  hydraflow/run_info.py,sha256=Jf5wrIjRLIV1-k-obHDqwKHa6j_ZonrY8od-rXlbtMo,1024
10
11
  hydraflow/utils.py,sha256=a9i5PEJn8Ssowv9dqHadAihZXlsqtVjHZ9MZvkPq1bY,4747
11
- hydraflow-0.6.2.dist-info/METADATA,sha256=9a3blsQ91rNP1Ql4kFDc7tZxDMbdK5PzEAfP9ZyUY6A,4700
12
- hydraflow-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
- hydraflow-0.6.2.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
14
- hydraflow-0.6.2.dist-info/RECORD,,
12
+ hydraflow-0.7.2.dist-info/METADATA,sha256=TJfrv_OjNiZskkog8UFmJI9wXjatNBKFTovPdMjnbK8,4700
13
+ hydraflow-0.7.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ hydraflow-0.7.2.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
15
+ hydraflow-0.7.2.dist-info/RECORD,,