Task

PtychographyTask

class ptychi.api.task.PtychographyTask(options: PtychographyTaskOptions, *args, **kwargs)[source]

Bases: Task

build()[source]
build_data()[source]
build_default_device()[source]
build_default_dtype()[source]
build_logger()[source]
build_object()[source]
build_opr_mode_weights()[source]
build_probe()[source]
build_probe_positions()[source]
build_random_seed()[source]
build_reconstructor()[source]
check_options()[source]
copy_data_from_task(task: PtychographyTask, params_to_copy: tuple[str, ...] = ('object', 'probe', 'probe_positions', 'opr_mode_weights')) None[source]

Copy data of reconstruction parameters from another task object.

Parameters:
  • task (PtychographyTask) – The task object to copy from.

  • params_to_copy (tuple[str, ...], optional) – The parameters to copy. By default, copy all parameters.

get_data(name: Literal['object', 'probe', 'probe_positions', 'opr_mode_weights']) Tensor[source]

Get a detached copy of the data of the given name.

Parameters:

name (Literal["object", "probe", "probe_positions", "opr_mode_weights"]) – The name of the data to get.

Returns:

The data of the given name.

Return type:

Tensor

get_data_to_cpu(name: Literal['object', 'probe', 'probe_positions', 'opr_mode_weights'], as_numpy: bool = False) Tensor | ndarray[source]
get_options_as_dict() dict[source]
get_probe_positions_x(as_numpy: bool = False) Tensor | ndarray[source]
get_probe_positions_y(as_numpy: bool = False) Tensor | ndarray[source]
load_options_from_dict(d: dict) None[source]
run(n_epochs: int = None, reset_timer_globals: bool = True)[source]

Run reconstruction either for n_epochs (if given), or for the number of epochs given in the options. The internal states of the Task object persists when this function finishes. To run more epochs continuing from the last run, call this function again.

Parameters:
  • n_epochs (int, optional) – The number of epochs to run. If None, use the number of epochs specified in the option object.

  • reset_timer_globals (bool, optional) – When True (default) the global timing accumulators are cleared before the run. Set to False to continue accumulating timing data across successive calls.

set_large_tensor_device(device: Literal['cpu', 'cuda'] | device | None = None) None[source]

Move large task buffers between CPU and a target device.

This helper is aimed at multi-task workflows where only one task is active on the accelerator at a time. Call it with device="cpu" to offload the heavy object/probe/diffraction buffers to system memory, and call it again (without arguments, or with an explicit device string) before resuming the task to bring the tensors back to the accelerator.

Parameters:

device (str | torch.device | None, optional) – Target device for the large buffers. If None, tensors are moved back to the current default device. If a string is given, it must be either “cpu” or “cuda”.