"""Verbosity utilities for scimba_torch."""importrefrompathlibimportPathimporttorchdef_get_version_from_init(path):ifnotPath(path).is_file():raiseFileNotFoundError(f"No such file or directory: {path}")content=Path(path).read_text()match=re.search(r'__version__\s*=\s*["\']([^"\']+)["\']',content)ifnotmatch:raiseValueError(f"__version__ not found in {path}")returnmatch.group(1)SCIMBA_IS_VERBOSE=False
[docs]defprint_torch_setting()->None:"""Print torch device and default floating point format."""print(f"torch device: {torch.get_default_device()}")print(f"torch floating point format: {torch.get_default_dtype()}")iftorch.cuda.is_available():print(f"cuda devices: {torch.cuda.device_count()}")print(f"cuda current device: {torch.cuda.current_device()}")print(f"cuda device name: {torch.cuda.get_device_name(0)}")
[docs]defget_verbosity()->bool:"""Get the verbosity level of scimba. Returns: the current verbosity. """returnSCIMBA_IS_VERBOSE
[docs]defset_verbosity(verbose:bool)->None:"""Set the verbosity level of scimba. Args: verbose: the wanted verbosity """globalSCIMBA_IS_VERBOSESCIMBA_IS_VERBOSE=verboseinit_path=Path(__file__).parent.parent/"__init__.py"version=_get_version_from_init(init_path)ifSCIMBA_IS_VERBOSE:print(f"\n/////////////// Scimba {version} ////////////////")print_torch_setting()print("\n")