hyri.regulariser.regulariser#

Define the abstract base API for regularisers.

This file provides the shared constructor and minimal interface used by all regulariser implementations in this repository.

Class

Regulariser

Define the base interface for regulariser operators.

class hyri.regulariser.regulariser.Regulariser(rank_num_ch: int = 1, rank_ch_start: int = 0, device: device = device(type='cpu'), dtype: dtype = torch.float32)#

Bases: ABC

Define the base interface for regulariser operators.

Subclasses implement __call__() to apply a regularisation step and update() to refresh internal state between optimisation iterations.

_rank_num_ch#

Number of channels assigned to this rank.

Type:

int

_rank_ch_start#

Global index of the first local channel.

Type:

int

_device#

Device used for operator state and outputs.

Type:

torch.device

_dtype#

Tensor dtype used by the operator.

Type:

torch.dtype

_is_dist#

Whether distributed execution is enabled.

Type:

bool

_rank#

Distributed rank identifier (0 in non-distributed mode).

Type:

int

_world_size#

Number of distributed ranks (1 in non-distributed mode).

Type:

int

Initialise shared regulariser state.

Parameters:
  • rank_num_ch (int, optional) – Number of channels handled by this rank. Default: 1.

  • rank_ch_start (int, optional) – Global start index of local channels. Default: 0.

  • device (torch.device, optional) – Execution device for regulariser state and outputs. Default: torch.device(“cpu”).

  • dtype (torch.dtype, optional) – Tensor dtype used by the regulariser. Default: torch.float.

Note

When torch.distributed is initialised, this constructor caches rank metadata and chooses a point-to-point communication device based on the active backend.

abstract __call__(x: Tensor) → Any#

Apply the regulariser to an input tensor.

Parameters:

x (torch.Tensor) – Input tensor in image domain.

Returns:

Regularised output produced by a concrete implementation.

Return type:

Any

abstract update(*args, **kwargs) → Any#

Update internal regulariser state.

Parameters:
  • *args (Any) – Positional arguments required by the subclass.

  • **kwargs (Any) – Keyword arguments required by the subclass.

Returns:

Optional update artefacts returned by the subclass.

Return type:

Any

get_device() → device#

Return the regulariser execution device.

Returns:

Device used for internal state and outputs.

Return type:

torch.device

get_data_type() → dtype#

Return the regulariser tensor dtype.

Returns:

Dtype expected for inputs and produced for outputs.

Return type:

torch.dtype