uv.util package¶
Submodules¶
uv.util.attachment module¶
Code for manipulating and joining prefixes and suffixes to metric keys.
TODO convert attach into a single dispatch method, and make a new suffix method.
-
uv.util.attachment.attach(m: Dict[str, Any], a: Union[str, List[str]], prefix: bool = True) → Dict[str, Any][source]¶ Attaches the supplied prefix or suffix to every key in the dictionary.
-
uv.util.attachment.attach_iter(xs: Iterable[str], a: Union[str, List[str]], prefix: bool = True) → Iterable[str][source]¶ Attaches the supplied prefix or suffix to every item in the iterable.
-
uv.util.attachment.attach_s(s: str, a: Union[str, List[str]], prefix: bool = True) → str[source]¶ Attach the supplied prefix or suffix to the string s.
-
uv.util.attachment.by_prefix(ms: Dict[Union[str, List[str]], Dict[str, Any]]) → Dict[str, Any][source]¶ Collapse the prefixes into the key. If you do this, you can avoid using prefixed reporters.
uv.util.env module¶
Utilities for interacting with the system environment.
-
uv.util.env.extract_params(prefix: Optional[str] = None, env: Optional[Dict[str, str]] = None) → Dict[str, str][source]¶ Some libraries that interact with UV pass experiment parameters via environment variables. This function returns a dict containing all environment keys (and their values) that begin with the supplied prefix and, optionally, an underscore.
An environment like this:
ENVVAR_MY_KEY=face ENVVAR_ANOTHER_KEY=sandwich ENVVARTHIRD_KEY=ham
would return:
- {
“my_key”: “face”, “another_key”: “sandwich”, “third_key”: “ham”
}
Module contents¶
Utilities grab bag.
-
class
uv.util.TqdmFile(file)[source]¶ Bases:
objectDummy file-like that will write to tqdm’s ‘write’ method, which will in turn write back into the supplied file. Use this when you need to redirect some stream in such a way that won’t cause the tqdm progress bar to reset.
-
file= None¶
-
-
uv.util.is_number(s)[source]¶ Returns true if the supplied item can be converted into a float; false otherwise.
-
uv.util.json_str(item: Any) → str[source]¶ Converts the supplied python object to a Python dictionary.
The difference from json.dumps is that this method makes a best effort to serialize anything it finds within a nested structure. np.float32 instances, for example.