hyri.optimiser.optimiser#
Define the abstract base class for optimisers.
This module provides the shared optimiser interface used by all imaging algorithms together with helper methods for exporting distributed image-domain products such as the model image, dirty image, PSF, and residual image.
Class
Represent the shared interface for imaging optimisers. |
- class hyri.optimiser.optimiser.Optimiser(meas: list[Tensor], ch_freq: Tensor, meas_op: MeasOp, save_pth: str = 'results', file_prefix: str = '', rank_ch_start: int = 0)#
Bases:
ABCRepresent the shared interface for imaging optimisers.
This class stores measurement data, channel metadata, and common image buffers used by optimiser implementations. It also defines the lifecycle hooks implemented by concrete forward-backward and primal-dual algorithms. In distributed runs, it tracks per-rank channel ownership and provides helper methods for gathering image-domain tensors back to a destination rank.
- _ch_freq#
Local channel frequencies with shape
(1, C_rank, 1, 1).- Type:
- _meas#
Local measurement tensors moved to the measurement-operator device.
- Type:
torch.Tensor | tuple[torch.Tensor, …]
- _meas_bp#
Backprojected dirty image cube.
- Type:
- _model#
Current model image cube.
- Type:
- _model_prev#
Previous model image cube.
- Type:
- _psf#
Local PSF cube.
- Type:
Example
>>> # Concrete subclasses implement the abstract optimisation hooks. >>> optimiser = SomeOptimiser(meas, ch_freq, meas_op) >>> optimiser.initialisation() >>> optimiser.run()
Initialise shared optimiser state.
- Parameters:
meas (List[torch.Tensor]) – Local measurement tensors, typically one tensor per local channel.
ch_freq (torch.Tensor) – Frequencies for the local spectral channels.
meas_op (MeasOp) – Measurement operator used for forward and adjoint applications.
save_pth (str, optional) – Directory where optimiser products are saved. Default:
"results".file_prefix (str, optional) – Prefix prepended to saved file names. Default:
"".rank_ch_start (int, optional) – Global starting channel index owned by the current rank. Default: 0.
- abstract initialisation() Any#
Initialise algorithm-specific state before the optimisation loop.
- Returns:
Subclass-defined initialisation result.
- Return type:
Any
- abstract run() Any#
Run the main optimisation loop.
- Returns:
Subclass-defined run result.
- Return type:
Any
- abstract _each_iter_begin() Any#
Run subclass logic at the beginning of each iteration.
- Returns:
Subclass-defined iteration state.
- Return type:
Any
- abstract _stop_criteria() Any#
Evaluate the stopping criterion for the optimisation loop.
- Returns:
Subclass-defined stopping indicator.
- Return type:
Any
- abstract _each_iter_end() Any#
Run subclass logic at the end of each iteration.
- Returns:
Subclass-defined iteration state.
- Return type:
Any
- abstract finalisation() Any#
Finalise optimisation after the main loop terminates.
- Returns:
Subclass-defined finalisation result.
- Return type:
Any
- get_model_image(dtype: dtype = torch.float64, dest: int = 0) ndarray | None#
Return the gathered model image cube.
- Parameters:
dtype (torch.dtype, optional) – Output dtype used before converting to NumPy. Default:
torch.double.dest (int, optional) – Destination rank for distributed gathering. Default: 0.
- Returns:
Gathered model image on
dest, orNoneon non-destination ranks in distributed runs.- Return type:
np.ndarray | None
- get_psf(dtype: dtype = torch.float64, dest: int = 0) ndarray | None#
Return the gathered PSF cube.
- Parameters:
dtype (torch.dtype, optional) – Output dtype used before converting to NumPy. Default:
torch.double.dest (int, optional) – Destination rank for distributed gathering. Default: 0.
- Returns:
Gathered PSF on
dest, orNoneon non-destination ranks in distributed runs.- Return type:
np.ndarray | None
- get_dirty_image(normalise: float | None = None, dtype: dtype = torch.float64, dest: int = 0) ndarray | None#
Return the gathered dirty image cube.
- Parameters:
normalise (float | None, optional) – Optional scalar divisor applied to the dirty image before gathering. Default: None.
dtype (torch.dtype, optional) – Output dtype used before converting to NumPy. Default:
torch.double.dest (int, optional) – Destination rank for distributed gathering. Default: 0.
- Returns:
Gathered dirty image on
dest, orNoneon non-destination ranks in distributed runs.- Return type:
np.ndarray | None
- get_residual_image(dtype: dtype = torch.float64, dest: int = 0) ndarray | None#
Return the gathered residual image cube.
- Parameters:
dtype (torch.dtype, optional) – Output dtype used before converting to NumPy. Default:
torch.double.dest (int, optional) – Destination rank for distributed gathering. Default: 0.
- Returns:
Gathered residual image on
dest, orNoneon non-destination ranks in distributed runs.- Return type:
np.ndarray | None
- _gather_ch_img_to_tensor(tensor_ch_rank: Tensor, dest: int = 0) Tensor | None#
Gather channel-partitioned image tensors to a destination rank.
- Parameters:
tensor_ch_rank (torch.Tensor) – Local tensor with shape
(1, C_rank, H, W).dest (int, optional) – Destination rank for distributed gathering. Default: 0.
- Returns:
Gathered tensor with shape
(1, C_total, H, W)ondest, orNoneon non-destination ranks.- Return type:
torch.Tensor | None
Note
Ranks with fewer channels are zero-padded temporarily so
torch.distributed.gathercan operate on tensors with matching shapes before the padding is removed ondest.