uv package¶
Subpackages¶
Submodules¶
uv.types module¶
Types shared between readers and reporters.
Module contents¶
-
uv.active_reporter(r: uv.reporter.base.AbstractReporter)[source]¶
-
uv.get_reporter() → uv.reporter.base.AbstractReporter[source]¶ Returns the active reporter set using set_reporter()
-
uv.set_reporter(r: uv.reporter.base.AbstractReporter) → uv.reporter.base.AbstractReporter[source]¶ Set the globally available reporter instance. Returns its input.
-
uv.report(step: int, k: str, v: Any) → None[source]¶ Accepts a step (an ordered int referencing some timestep), a metric key and a value, and persists the metric into the globally available reporter returned by uv.get_reporter().
-
uv.report_all(step: int, m: Dict[str, Any]) → None[source]¶ Accepts a step (an ordered int referencing some timestep) and a dictionary of metric key => metric value, and persists the metric into the globally available reporter returned by uv.get_reporter().
-
uv.report_param(k: str, v: str) → None[source]¶ Accepts a key and value parameter and logs these as parameters alongside the reported metrics. Reports to the globally available reporter returned by uv.get_reporter().
-
uv.report_params(m: Dict[str, str]) → None[source]¶ Accepts a dict of parameter name -> value, and logs these as parameters alongside the reported metrics. Reports to the globally available reporter returned by uv.get_reporter().
-
uv.start_run(param_prefix: Optional[str] = None, experiment_name: Optional[str] = None, run_name: Optional[str] = None, artifact_location: Optional[str] = None, **args) → mlflow.tracking.fluent.ActiveRun[source]¶ Close alias of mlflow.start_run. The only difference is that uv.start_run attempts to extract parameters from the environment and log those to the bound UV reporter using report_params.
Note that if experiment_name is specified and refers to an existing experiment, then the artifact_location will not be honored as this is an immutable property of an mlflow experiment. This method will issue a warning but proceed.
Note that the returned value can be used as a context manager: https://www.mlflow.org/docs/latest/python_api/mlflow.html#mlflow.start_run
-
class
uv.AbstractReporter[source]¶ Bases:
objectBase class for all reporters. A reporter is a type that is able to log timeseries of values for different t.MetricKey instances, one item at a time.
NOTE - by default, report_all and report are implemented in terms of one another. This means that you can choose which method you’d like to override, or override both… but if you don’t override any you’ll see infinite recursion.
Be careful not to abuse the kindness!
-
filter_step(pred: Callable[[int], bool], on_false: Optional[AbstractReporter] = None)[source]¶ Accepts a predicate function from step to boolean, and returns a reporter that tests every step against the supplied function. If the function returns true, metrics get passed on to this reporter; else, they get filtered out.
If a reporter is supplied to on_false, any time the predicate returns false items are routes to that store instead of base.
-
filter_values(pred: Callable[[int, Any], bool], on_false: Optional[AbstractReporter] = None)[source]¶ “Accepts a function from (step, metric) to boolean; every (step, metric) pair passed to report and report_all are passed into this function. If the predicate returns true, the metric is passed on; else, it’s filtered.
-
from_thunk(thunk: Callable[], Dict[str, Any]])[source]¶ Returns a new Reporter that passes all AbstractReporter methods through, but adds a new method called “thunk()” that, when called, will pass the emitted map of metric key to metric down to the underlying store.
thunk() returns the value emitted by the no-arg function passed here via thunk.
-
map_values(fn: Callable[[int, Any], Any])[source]¶ “Accepts a function from (step, metric) to some new metric; every (step, metric) pair passed to report and report_all are passed into this function, and the result is passed down the chain to this, the calling reporter.
-
plus(*others: uv.reporter.base.AbstractReporter)[source]¶ Returns an instance of MultiReporter wrapping the current instance. This reporter broadcasts its inputs to this instance, plus any other reporters supplied to this method, every time it sees a metric passed in via report or report_all.
-
reader() → Optional[uv.reader.base.AbstractReader][source]¶ Returns an implementation of AbstractReader that can access the data in this store.
Returns None by default; extending classes are encouraged, but not required, to override.
-
report(step: int, k: str, v: Any) → None[source]¶ Accepts a step (an ordered int referencing some timestep), a metric key and a value, and persists the metric into some underlying store.
-
report_all(step: int, m: Dict[str, Any]) → None[source]¶ Accepts a step (an ordered int referencing some timestep) and a dictionary of metric key => metric value, and persists the metric into some underlying store.
Extending classes are expected to perform some side effect that’s either visually useful, as in a live-plot, or recoverable via some matching extension of AbstractReader.
-
report_each_n(n: int)[source]¶ Returns a new reporter that only reports every n steps; specifically, the new reporter will only accept metrics where step % n == 0.
If n <= 1, this reporter, untouched, is returned directly.
-
report_param(k: str, v: str) → None[source]¶ Accepts a key and value parameter and logs these as parameters alongside the reported metrics.
-
report_params(m: Dict[str, Union[str, Dict]]) → None[source]¶ Accepts a dict of parameter name -> value, and logs these as parameters alongside the reported metrics.
-
stepped(step_key: Optional[str] = None)[source]¶ Returns a new reporter that modifies incoming metrics by wrapping them in a dict of this form before passing them down to this instance of reporter:
{step_key: step, “value”: metric_value}
where step_key is the supplied argument, and equal to “step” by default. This is useful for keeping track of each metric’s timestamp.
-
-
class
uv.LoggingReporter(file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, digits: int = 3)[source]¶ Bases:
uv.reporter.base.AbstractReporterReporter that logs all data to the file handle you pass in using a fairly sane format. Compatible with tqdm, the python progress bar.
-
report_all(step: int, m: Dict[str, Any]) → None[source]¶ Accepts a step (an ordered int referencing some timestep) and a dictionary of metric key => metric value, and persists the metric into some underlying store.
Extending classes are expected to perform some side effect that’s either visually useful, as in a live-plot, or recoverable via some matching extension of AbstractReader.
-
-
class
uv.MemoryReporter(m: Optional[Dict[str, List[Any]]] = None, params_store: Optional[Dict[str, str]] = None)[source]¶ Bases:
uv.reporter.base.AbstractReporterReporter that stores metrics in a Python dictionary, keyed by t.MetricKey. Metrics are stored as a list.
- Parameters
m – Optional dictionary mapping metric keys to a list of accumulated metric values. If supplied, this dictionary will be mutated as new metrics arrive.
-
reader() → Optional[uv.reader.base.AbstractReader][source]¶ Returns an implementation of AbstractReader that can access the data in this store.
Returns None by default; extending classes are encouraged, but not required, to override.
-
report_all(step: int, m: Dict[str, Any]) → None[source]¶ Accepts a step (an ordered int referencing some timestep) and a dictionary of metric key => metric value, and persists the metric into some underlying store.
Extending classes are expected to perform some side effect that’s either visually useful, as in a live-plot, or recoverable via some matching extension of AbstractReader.