httomo.method_wrappers.generic.GenericMethodWrapper#
- class httomo.method_wrappers.generic.GenericMethodWrapper(method_repository: MethodRepository, module_path: str, method_name: str, comm: mpi4py.MPI.Comm, save_result: bool | None = None, output_mapping: Dict[str, str] = {}, **kwargs)[source]#
Defines a generic method backend wrapper in httomo which is used by task runner.
Method parameters (configuration parameters, usually set by the user) can be set either using keyword arguments to the constructor, or by using conventional dictionary set/get methods like:
wrapper["parameter"] = value
Methods
__init__
(method_repository, module_path, ...)Constructs a MethodWrapper for a method located in module_path with the name method_name.
append_config_params
(params)Append configuration parameters to the existing config_params
calculate_max_slices
(data_dtype, ...)If it runs on GPU, determine the maximum number of slices that can fit in the available memory in bytes, and return a tuple of
calculate_output_dims
(non_slice_dims_shape)Calculate the dimensions of the output for this method
Calculate the padding required by the method
execute
(block)Execute functions for external packages.
Override this method for functions that have a side output.
Whether the wrapper class needs the preview information from the loader to execute the methods it wraps or not.
should_select_this_class
(module_path, ...)Method to dermine if this class should be used for wrapper instantiation, given the module path and method name.
Attributes
The MPI communicator used
Access a copy of the configuration parameters (cannot be modified directly)
True if method runs on GPU and expects a CuPy array as inputs
Get the time spent on GPU in the last call to execute
Implementation of this method
True if this is a CPU-only method
True if this is a GPU method
Memory requirements for GPU execution
The actual method underlying this wrapper
Returns the name of the method function
Returns the full module path where the method function is defined
Whether output dimensions change after executing this method
The name of the top-level package where this method is implementated, e.g. 'httomolib'.
Determine if the method needs padding
List of parameter names of the underlying method
Determine the recon algorithm used, if the method is reconstruction.
Whether to save the result of this method to intermediate files
Determine if the method performs sweep
task_id
pattern
- append_config_params(params: Dict[str, str | bool | int | float | PathLike | ndarray | cupy.ndarray | List[str | bool | int | float | PathLike | ndarray | cupy.ndarray]])[source]#
Append configuration parameters to the existing config_params
- calculate_max_slices(data_dtype: dtype, non_slice_dims_shape: Tuple[int, int], available_memory: int) Tuple[int, int] [source]#
If it runs on GPU, determine the maximum number of slices that can fit in the available memory in bytes, and return a tuple of
(max_slices, available_memory)
The available memory may have been adjusted for the methods that follow, in case something persists afterwards.
- calculate_output_dims(non_slice_dims_shape: Tuple[int, int]) Tuple[int, int] [source]#
Calculate the dimensions of the output for this method
- property comm: mpi4py.MPI.Comm#
The MPI communicator used
- property config_params: Dict[str, Any]#
Access a copy of the configuration parameters (cannot be modified directly)
- property cupyrun: bool#
True if method runs on GPU and expects a CuPy array as inputs
- execute(block: T) T [source]#
Execute functions for external packages.
Developer note: Derived classes may override this function or any of the methods it uses to modify behaviour.
- Parameters:
block (T (implements Block)) – A numpy or cupy dataset, mutable (method might work in-place).
- Returns:
A CPU or GPU-based dataset object with the output
- Return type:
T (implements Block)
- get_side_output() Dict[str, Any] [source]#
Override this method for functions that have a side output. The returned dictionary will be merged with the dict_params parameter passed to execute for all methods that follow in the pipeline
- property gpu_time: GpuTimeInfo#
Get the time spent on GPU in the last call to execute
- property implementation: Literal['gpu', 'cpu', 'gpu_cupy']#
Implementation of this method
- property is_cpu: bool#
True if this is a CPU-only method
- property is_gpu: bool#
True if this is a GPU method
- property memory_gpu: GpuMemoryRequirement | None#
Memory requirements for GPU execution
- property method: Callable#
The actual method underlying this wrapper
- property method_name: str#
Returns the name of the method function
- property module_path: str#
Returns the full module path where the method function is defined
- property output_dims_change: bool#
Whether output dimensions change after executing this method
- property package_name: str#
The name of the top-level package where this method is implementated, e.g. ‘httomolib’
- property padding: bool#
Determine if the method needs padding
- property parameters: List[str]#
List of parameter names of the underlying method
- property recon_algorithm: str | None#
Determine the recon algorithm used, if the method is reconstruction. Otherwise return None.
- classmethod requires_preview() bool [source]#
Whether the wrapper class needs the preview information from the loader to execute the methods it wraps or not.
- property save_result: bool#
Whether to save the result of this method to intermediate files
- classmethod should_select_this_class(module_path: str, method_name: str) bool [source]#
Method to dermine if this class should be used for wrapper instantiation, given the module path and method name.
The make_method_wrapper function will iterate through all subclasses and evaluate this condition in the order of declaration, falling back to GenericMethodWrapper if all evaluate to False.
Therefore, deriving classes should override this method to indicate the criteria when they should be instantiated.
- property sweep: bool#
Determine if the method performs sweep