noether.core.utils.common¶
Submodules¶
Classes¶
A stopwatch class to measure elapsed time. |
|
Sampler needs to implement __len__ and be iterable such that the type checking doesn't complain. |
Functions¶
|
Return the type name of an object in lowercase. |
|
Convert pascal/camel to snake case using Regex. |
|
Return the type name of an object in snake case. |
|
Access values of an object, a list or a dictionary using a string path. |
|
Converts a string to a Path, validates it, and optionally creates it. |
|
Checks if all arguments are None. |
|
Checks if at least one of the arguments is not None. |
|
Checks if at most one of the arguments is not None. |
|
Checks if exactly one of the arguments is not None. |
|
Checks if either all arguments are not None or if all are None. |
Converts floats without decimals to int. |
Package Contents¶
- noether.core.utils.common.lower_type_name(obj)¶
Return the type name of an object in lowercase.
- noether.core.utils.common.pascal_to_snake(pascal_case)¶
Convert pascal/camel to snake case using Regex.
Handles acronyms and numbers correctly. .. rubric:: Example
XMLParser -> xml_parser HTTPClient -> http_client V2Model -> v2_model
- noether.core.utils.common.snake_type_name(obj)¶
Return the type name of an object in snake case.
- noether.core.utils.common.select_with_path(obj, path)¶
Access values of an object, a list or a dictionary using a string path.
- noether.core.utils.common.validate_path(path, exists='must', suffix=None, mkdir=False)¶
Converts a string to a Path, validates it, and optionally creates it.
- Parameters:
path (str | pathlib.Path) – The path string to validate.
exists (Literal['must', 'must_not', 'any']) –
“must”: Raises FileNotFoundError if the path doesn’t exist.
”must_not”: Raises FileExistsError if the path already exists.
”any”: Performs no existence check.
suffix (str | None) – If provided, checks if the path ends with this suffix.
mkdir (bool) – If True, creates the directory path (like mkdir -p).
- Returns:
The validated path.
- Return type:
Path
- class noether.core.utils.common.Stopwatch(device=None)¶
A stopwatch class to measure elapsed time.
Supports two timing backends depending on the provided device:
CPU (
device=None): plaintime.perf_counter()wall-clock timing.GPU (CUDA or MPS
device): device event-based timing usingtorch.cuda.Event/torch.mps.Eventfor accurate GPU measurements. Events are recorded non-blocking instop()/lap()and resolved lazily inelapsed_seconds, which synchronizes each pending event pair individually before callingelapsed_time().
- Parameters:
device (torch.device | None) – Optional device that selects the timing backend.
- stop()¶
Stop the stopwatch and return the elapsed time since the last lap.
For GPU devices the return value is always
float("nan"); accesselapsed_secondsafter stopping to obtain the resolved time.- Return type:
- lap()¶
Record a lap time and return the elapsed time since the last lap.
For GPU devices the return value is always
float("nan"); accesselapsed_secondsafter stopping to obtain the resolved time.- Return type:
- static sync(device)¶
Synchronize the given GPU device. No-op for CPU devices.
- Parameters:
device (torch.device)
- Return type:
None
- class noether.core.utils.common.SizedIterable¶
Bases:
ProtocolSampler needs to implement __len__ and be iterable such that the type checking doesn’t complain.
- noether.core.utils.common.check_all_none(*args)¶
Checks if all arguments are None.
- Parameters:
args (Any)
- Return type:
- noether.core.utils.common.check_at_least_one(*args)¶
Checks if at least one of the arguments is not None.
- Parameters:
args (Any)
- Return type:
- noether.core.utils.common.check_at_most_one(*args)¶
Checks if at most one of the arguments is not None.
- Parameters:
args (Any)
- Return type:
- noether.core.utils.common.check_exclusive(*args)¶
Checks if exactly one of the arguments is not None.
- Parameters:
args (Any)
- Return type:
- noether.core.utils.common.check_inclusive(*args)¶
Checks if either all arguments are not None or if all are None.
- Parameters:
args (Any)
- Return type: