hydraflow 0.5.3__py3-none-any.whl → 0.6.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
hydraflow/context.py CHANGED
@@ -56,7 +56,7 @@ def log_run(
56
56
  hc = HydraConfig.get()
57
57
  output_dir = Path(hc.runtime.output_dir)
58
58
 
59
- # Save '.hydra' config directory first.
59
+ # Save '.hydra' config directory.
60
60
  output_subdir = output_dir / (hc.output_subdir or "")
61
61
  mlflow.log_artifacts(output_subdir.as_posix(), hc.output_subdir)
62
62
 
@@ -69,14 +69,41 @@ def log_run(
69
69
  raise
70
70
 
71
71
  finally:
72
- # Save output_dir including '.hydra' config directory.
73
- mlflow.log_artifacts(output_dir.as_posix())
72
+ log_hydra(output_dir)
73
+
74
+
75
+ def log_hydra(output_dir: Path) -> None:
76
+ """Log hydra logs of the current run as artifacts.
77
+
78
+ Args:
79
+ output_dir (Path): The output directory of the Hydra job.
80
+
81
+ """
82
+ uri = mlflow.get_artifact_uri()
83
+ artifact_dir = Path(mlflow.artifacts.download_artifacts(uri))
84
+
85
+ for file_hydra in output_dir.glob("*.log"):
86
+ if not file_hydra.is_file():
87
+ continue
88
+
89
+ file_artifact = artifact_dir / file_hydra.name
90
+ if file_artifact.exists():
91
+ text = file_artifact.read_text()
92
+ if not text.endswith("\n"):
93
+ text += "\n"
94
+ else:
95
+ text = ""
96
+
97
+ text += file_hydra.read_text()
98
+ mlflow.log_text(text, file_hydra.name)
74
99
 
75
100
 
76
101
  @contextmanager
77
102
  def start_run( # noqa: PLR0913
78
103
  config: object,
79
104
  *,
105
+ chdir: bool = False,
106
+ run: Run | None = None,
80
107
  run_id: str | None = None,
81
108
  experiment_id: str | None = None,
82
109
  run_name: str | None = None,
@@ -94,6 +121,9 @@ def start_run( # noqa: PLR0913
94
121
 
95
122
  Args:
96
123
  config (object): The configuration object to log parameters from.
124
+ chdir (bool): Whether to change the current working directory to the
125
+ artifact directory of the current run. Defaults to False.
126
+ run (Run | None): The existing run. Defaults to None.
97
127
  run_id (str | None): The existing run ID. Defaults to None.
98
128
  experiment_id (str | None): The experiment ID. Defaults to None.
99
129
  run_name (str | None): The name of the run. Defaults to None.
@@ -120,6 +150,9 @@ def start_run( # noqa: PLR0913
120
150
  run context.
121
151
 
122
152
  """
153
+ if run:
154
+ run_id = run.info.run_id
155
+
123
156
  with (
124
157
  mlflow.start_run(
125
158
  run_id=run_id,
@@ -133,7 +166,11 @@ def start_run( # noqa: PLR0913
133
166
  ) as run,
134
167
  log_run(config if run_id is None else None, synchronous=synchronous),
135
168
  ):
136
- yield run
169
+ if chdir:
170
+ with chdir_artifact(run):
171
+ yield run
172
+ else:
173
+ yield run
137
174
 
138
175
 
139
176
  @contextmanager
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:
@@ -30,6 +30,9 @@ def match(param: str, value: Any) -> bool:
30
30
  False otherwise.
31
31
 
32
32
  """
33
+ if callable(value):
34
+ return value(param)
35
+
33
36
  if any(value is x for x in [None, True, False]):
34
37
  return param == str(value)
35
38
 
@@ -234,7 +234,15 @@ class RunCollection:
234
234
  """
235
235
  return self._runs[-1] if self._runs else None
236
236
 
237
- def filter(self, config: object | None = None, **kwargs) -> RunCollection:
237
+ def filter(
238
+ self,
239
+ config: object | None = None,
240
+ *,
241
+ override: bool = False,
242
+ select: list[str] | None = None,
243
+ status: str | list[str] | int | list[int] | None = None,
244
+ **kwargs,
245
+ ) -> RunCollection:
238
246
  """Filter the `Run` instances based on the provided configuration.
239
247
 
240
248
  This method filters the runs in the collection according to the
@@ -254,13 +262,27 @@ class RunCollection:
254
262
  config (object | None): The configuration object to filter the runs.
255
263
  This can be any object that provides key-value pairs through
256
264
  the `iter_params` function.
265
+ override (bool): If True, override the configuration object with the
266
+ provided key-value pairs.
267
+ select (list[str] | None): The list of parameters to select.
268
+ status (str | list[str] | int | list[int] | None): The status of the
269
+ runs to filter.
257
270
  **kwargs: Additional key-value pairs to filter the runs.
258
271
 
259
272
  Returns:
260
273
  A new `RunCollection` object containing the filtered runs.
261
274
 
262
275
  """
263
- return RunCollection(filter_runs(self._runs, config, **kwargs))
276
+ return RunCollection(
277
+ filter_runs(
278
+ self._runs,
279
+ config,
280
+ override=override,
281
+ select=select,
282
+ status=status,
283
+ **kwargs,
284
+ ),
285
+ )
264
286
 
265
287
  def find(self, config: object | None = None, **kwargs) -> Run:
266
288
  """Find the first `Run` instance based on the provided configuration.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hydraflow
3
- Version: 0.5.3
3
+ Version: 0.6.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
@@ -1,14 +1,14 @@
1
1
  hydraflow/__init__.py,sha256=9XO9FD3uiTTPN6X6UAC9FtkJjEqUQZNqpoAmSrjUHfI,855
2
2
  hydraflow/config.py,sha256=MNX9da5bPVDcjnpji7Cm9ndK6ura92pt361m4PRh6_E,4326
3
- hydraflow/context.py,sha256=3g7OQXWcFvK6PVVbXpQg7Hr8nsJkF9pLFrXNi_3aV5A,5524
3
+ hydraflow/context.py,sha256=rc43zvE2ueki0zEzorCMIthD9cho_PkbLLJYF9WgDqY,6562
4
4
  hydraflow/mlflow.py,sha256=h2S_A2wElr_1lAq0D1wkoEfdtDZpPuWFNRcO8mV_VrA,8932
5
- hydraflow/param.py,sha256=c5sc6NwD6DKwZzVwprXzZD5FSi6qRgSHkc6TXBKQEdg,4502
5
+ hydraflow/param.py,sha256=yu1aMNXRLegXGDL-68vwIkfeDF9CaU784WZENGLwl7Q,4572
6
6
  hydraflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- hydraflow/run_collection.py,sha256=zPrlKwLuzqePj57pXbgKWrE03S_kjxTaxY9trItf6Gc,26772
7
+ hydraflow/run_collection.py,sha256=2GRVOy87_2SPjHuCzzUvRNugO_grtFUVjtTfhznwBAc,27444
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=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,,
11
+ hydraflow-0.6.0.dist-info/METADATA,sha256=xUib1EsbG3Es5jFx0cSkF1QItfTuciBHYM1040GqFzA,4700
12
+ hydraflow-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
+ hydraflow-0.6.0.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
14
+ hydraflow-0.6.0.dist-info/RECORD,,