accelforge.util package#
Submodules#
accelforge.util.exceptions module#
Public exceptions for AccelForge.
accelforge.util.indent module#
accelforge.util.parallel module#
- accelforge.util.parallel.delayed(function)[source]#
Decorator used to capture the arguments of a function.
- Parameters:
function (callable) – The function to be decorated.
- Returns:
A new function
Fsuch that callingF(*args, **kwargs)returns a tuple(function, args, kwargs), allowing the later execution offunction(*args, **kwargs).- Return type:
callable
Notes
Be careful about the order in which decorators are applied, especially when using
Memory.cache. For instance,Memory.cache(delayed(func))will cache the outputs ofdelayed(func), that is, tuples of the form(func, args, kwargs). To cache the outputs offuncitself, you must instead usedelayed(Memory.cache(func)).
- accelforge.util.parallel.get_n_parallel_jobs()[source]#
Returns the number of parallel jobs being used. If parallel processing is not enabled, returns 1.
- Return type:
- accelforge.util.parallel.is_using_parallel_processing()[source]#
Returns True if parallel processing is enabled.
- Return type:
- accelforge.util.parallel.parallel(jobs, n_jobs=None, pbar=None, pbar_position=0, return_as=None)[source]#
Parallelizes a list of jobs.
- Parameters:
jobs (
list[tuple[Callable,tuple,dict]]) – The jobs to parallelize. The first element of each tuple is a function, the second is a tuple of arguments, and the third is a dictionary of keyword arguments.n_jobs (
int) – The number of jobs to run in parallel. If not provided, the number of parallel jobs is set to the number of CPU cores.pbar (
str) – A label for a progress bar. If not provided, no progress bar is shown.pbar_position (
int) – The position of the progress bar. If not provided, the progress bar is shown at the beginning of the output.return_as (
str) – The type of return value. If not provided, the return value is a list.
- Returns:
The result of the parallelized jobs.
- Return type:
Union[list[Any],Generator[Any,None,None],dict[Any,Any]]
Module contents#
- exception accelforge.util.EvaluationError[source]#
Bases:
ExceptionException raised when parsing fails.
This exception is raised when there’s an error parsing specifications, architectures, workloads, or mappings.
- Parameters:
- class accelforge.util.LiteralString[source]#
Bases:
strA string literal that should not be evaluated.
- accelforge.util.NUMPY_FLOAT_TYPE#
alias of
float32
- class accelforge.util.Permutation[source]#
Bases:
objectA sequence on integers from the set of [0,N) representing a permutation of a sequence that has N elements.
- apply(sequence, include_remaining_unpermuted=True)[source]#
Apply permutation to sequence. If include_remaining_unpermuted and the sequence is longer than the permutation, then the remainder of the sequence is included unpermuted. Otherwise, the remainder of the sequence is omitted.
- accelforge.util.delayed(function)[source]#
Decorator used to capture the arguments of a function.
- Parameters:
function (callable) – The function to be decorated.
- Returns:
A new function
Fsuch that callingF(*args, **kwargs)returns a tuple(function, args, kwargs), allowing the later execution offunction(*args, **kwargs).- Return type:
callable
Notes
Be careful about the order in which decorators are applied, especially when using
Memory.cache. For instance,Memory.cache(delayed(func))will cache the outputs ofdelayed(func), that is, tuples of the form(func, args, kwargs). To cache the outputs offuncitself, you must instead usedelayed(Memory.cache(func)).
- accelforge.util.get_n_parallel_jobs()[source]#
Returns the number of parallel jobs being used. If parallel processing is not enabled, returns 1.
- Return type:
- accelforge.util.is_using_parallel_processing()[source]#
Returns True if parallel processing is enabled.
- Return type:
- class accelforge.util.oset[source]#
-
Set that iterates in sorted order for deterministic behavior.
- difference(*others)[source]#
Return the difference of two or more sets as a new set.
(i.e. all elements that are in this set but not the others.)
- intersection(*others)[source]#
Return the intersection of two sets as a new set.
(i.e. all elements that are in both sets.)
- accelforge.util.parallel(jobs, n_jobs=None, pbar=None, pbar_position=0, return_as=None)[source]#
Parallelizes a list of jobs.
- Parameters:
jobs (
list[tuple[Callable,tuple,dict]]) – The jobs to parallelize. The first element of each tuple is a function, the second is a tuple of arguments, and the third is a dictionary of keyword arguments.n_jobs (
int) – The number of jobs to run in parallel. If not provided, the number of parallel jobs is set to the number of CPU cores.pbar (
str) – A label for a progress bar. If not provided, no progress bar is shown.pbar_position (
int) – The position of the progress bar. If not provided, the progress bar is shown at the beginning of the output.return_as (
str) – The type of return value. If not provided, the return value is a list.
- Returns:
The result of the parallelized jobs.
- Return type:
Union[list[Any],Generator[Any,None,None],dict[Any,Any]]