accelforge.util package#

Submodules#

accelforge.util.exceptions module#

Public exceptions for AccelForge.

exception accelforge.util.exceptions.EvaluationError[source]#

Bases: Exception

Exception raised when parsing fails.

This exception is raised when there’s an error parsing specifications, architectures, workloads, or mappings.

Parameters:
  • *args – Standard exception arguments.

  • source_field (Any, optional) – The field where the error occurred.

  • message (str, optional) – Error message describing what went wrong.

  • **kwargs – Additional keyword arguments.

__init__(*args, source_field=None, message=None, **kwargs)[source]#
add_field(field)[source]#

Add a field to the error context. The output error message will include the field path as a period-separated string like “spec.arch.nodes.0.name”.

Parameters:

field (Any) – The field to add to the error context.

accelforge.util.parallel module#

accelforge.util.parallel.delayed(function)[source]#

Decorator used to capture the arguments of a function.

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:

int

accelforge.util.parallel.is_using_parallel_processing()[source]#

Returns True if parallel processing is enabled.

Return type:

bool

accelforge.util.parallel.parallel(jobs, n_jobs=None, pbar=None, 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, optional) – 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, optional) – A label for a progress bar. If not provided, no progress bar is shown.

  • return_as (Literal["list", "generator", "generator_unordered"], optional) – The type of return value. If not provided, the return value is a list.

Returns:

The result of the parallelized jobs.

Return type:

list[Any] | Generator[Any, None, None] | dict[Any, Any]

accelforge.util.parallel.set_n_parallel_jobs(n_jobs, print_message=False)[source]#

Set the number of parallel jobs to use.

Parameters:
  • n_jobs (int) – The number of parallel jobs to use.

  • print_message (bool, optional) – Whether to print a message when the number of parallel jobs is set.

Return type:

None

Module contents#

exception accelforge.util.EvaluationError[source]#

Bases: Exception

Exception raised when parsing fails.

This exception is raised when there’s an error parsing specifications, architectures, workloads, or mappings.

Parameters:
  • *args – Standard exception arguments.

  • source_field (Any, optional) – The field where the error occurred.

  • message (str, optional) – Error message describing what went wrong.

  • **kwargs – Additional keyword arguments.

__init__(*args, source_field=None, message=None, **kwargs)[source]#
add_field(field)[source]#

Add a field to the error context. The output error message will include the field path as a period-separated string like “spec.arch.nodes.0.name”.

Parameters:

field (Any) – The field to add to the error context.

class accelforge.util.LiteralString[source]#

Bases: str

A string literal that should not be evaluated.

accelforge.util.NUMPY_FLOAT_TYPE#

alias of float32

accelforge.util.delayed(function)[source]#

Decorator used to capture the arguments of a function.

class accelforge.util.fzs[source]#

Bases: frozenset[T], Generic[T]

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:

int

accelforge.util.is_using_parallel_processing()[source]#

Returns True if parallel processing is enabled.

Return type:

bool

accelforge.util.parallel(jobs, n_jobs=None, pbar=None, 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, optional) – 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, optional) – A label for a progress bar. If not provided, no progress bar is shown.

  • return_as (Literal["list", "generator", "generator_unordered"], optional) – The type of return value. If not provided, the return value is a list.

Returns:

The result of the parallelized jobs.

Return type:

list[Any] | Generator[Any, None, None] | dict[Any, Any]

accelforge.util.set_n_parallel_jobs(n_jobs, print_message=False)[source]#

Set the number of parallel jobs to use.

Parameters:
  • n_jobs (int) – The number of parallel jobs to use.

  • print_message (bool, optional) – Whether to print a message when the number of parallel jobs is set.

Return type:

None