SingleQuantumExecutor

class lsst.ctrl.mpexec.SingleQuantumExecutor(taskFactory: TaskFactory, skipExistingIn: list[str] | None = None, clobberOutputs: bool = False, enableLsstDebug: bool = False, exitOnKnownError: bool = False, mock: bool = False, mock_configs: list[lsst.ctrl.mpexec.cli.utils._PipelineAction] | None = None)

Bases: QuantumExecutor

Executor class which runs one Quantum at a time.

Parameters:
butlerButler

Data butler.

taskFactoryTaskFactory

Instance of a task factory.

skipExistingInlist [ str ], optional

Accepts list of collections, if all Quantum outputs already exist in the specified list of collections then that Quantum will not be rerun.

clobberOutputsbool, optional

If True, then existing outputs in output run collection will be overwritten. If skipExistingIn is defined, only outputs from failed quanta will be overwritten.

enableLsstDebugbool, optional

Enable debugging with lsstDebug facility for a task.

exitOnKnownErrorbool, optional

If True, call sys.exit with the appropriate exit code for special known exceptions, after printing a traceback, instead of letting the exception propagate up to calling. This is always the behavior for InvalidQuantumError.

mockbool, optional

If True then mock task execution.

mock_configslist [ _PipelineAction ], optional

Optional config overrides for mock tasks.

Attributes Summary

stream_json_logs

If True each log record is written to a temporary file and ingested when quantum completes.

Methods Summary

captureLogging(taskDef, quantum, butler)

Configure logging system to capture logs for execution of this task.

checkExistingOutputs(quantum, butler, taskDef)

Decide whether this quantum needs to be executed.

execute(taskDef, quantum, butler)

Execute single quantum.

getReport()

Return execution report from last call to execute.

initGlobals(quantum, butler)

Initialize global state needed for task execution.

makeTask(taskClass, name, config, butler)

Make new task instance.

runQuantum(task, quantum, taskDef, butler)

Execute task on a single quantum.

updatedQuantumInputs(quantum, butler, taskDef)

Update quantum with extra information, returns a new updated Quantum.

writeLogRecords(quantum, taskDef, butler, store)

writeMetadata(quantum, metadata, taskDef, butler)

Attributes Documentation

stream_json_logs = True

If True each log record is written to a temporary file and ingested when quantum completes. If False the records are accumulated in memory and stored in butler on quantum completion.

Methods Documentation

captureLogging(taskDef: TaskDef, quantum: Quantum, butler: Butler) Iterator

Configure logging system to capture logs for execution of this task.

Parameters:
taskDeflsst.pipe.base.TaskDef

The task definition.

quantumQuantum

Single Quantum instance.

butlerButler

Butler to write logs to.

Notes

Expected to be used as a context manager to ensure that logging records are inserted into the butler once the quantum has been executed:

with self.captureLogging(taskDef, quantum, butler):
    # Run quantum and capture logs.

Ths method can also setup logging to attach task- or quantum-specific information to log messages. Potentially this can take into account some info from task configuration as well.

checkExistingOutputs(quantum: Quantum, butler: Butler, taskDef: TaskDef) bool

Decide whether this quantum needs to be executed.

If only partial outputs exist then they are removed if clobberOutputs is True, otherwise an exception is raised.

Parameters:
quantumQuantum

Quantum to check for existing outputs

butlerButler

Data butler.

taskDefTaskDef

Task definition structure.

Returns:
existbool

True if self.skipExistingIn is defined, and a previous execution of this quanta appears to have completed successfully (either because metadata was written or all datasets were written). False otherwise.

Raises:
RuntimeError

Raised if some outputs exist and some not.

execute(taskDef: TaskDef, quantum: Quantum, butler: Butler) Quantum

Execute single quantum.

Parameters:
taskDefTaskDef

Task definition structure.

quantumQuantum

Quantum for this execution.

butlerButler

Data butler instance

Returns:
quantumQuantum

The quantum actually executed. At present this quantum will contain only unresolved DatasetRef instances for output datasets, reflecting the state of the quantum just before it was run (but after any adjustments for predicted but now missing inputs). This may change in the future to include resolved output DatasetRef objects.

Notes

Any exception raised by the task or code that wraps task execution is propagated to the caller of this method.

getReport() QuantumReport | None

Return execution report from last call to execute.

Returns:
reportQuantumReport

Structure describing the status of the execution of a quantum. None is returned if implementation does not support this feature.

Raises:
RuntimeError

Raised if this method is called before execute.

initGlobals(quantum: Quantum, butler: Butler) None

Initialize global state needed for task execution.

Parameters:
quantumQuantum

Single Quantum instance.

butlerButler

Data butler.

Notes

There is an issue with initializing filters singleton which is done by instrument, to avoid requiring tasks to do it in runQuantum() we do it here when any dataId has an instrument dimension. Also for now we only allow single instrument, verify that all instrument names in all dataIds are identical.

This will need revision when filter singleton disappears.

makeTask(taskClass: type[lsst.pipe.base.pipelineTask.PipelineTask], name: str, config: PipelineTaskConfig, butler: Butler) PipelineTask

Make new task instance.

Parameters:
taskClasstype

Sub-class of PipelineTask.

namestr

Name for this task.

configPipelineTaskConfig

Configuration object for this task

Returns:
taskPipelineTask

Instance of taskClass type.

butlerButler

Data butler.

runQuantum(task: PipelineTask, quantum: Quantum, taskDef: TaskDef, butler: Butler) None

Execute task on a single quantum.

Parameters:
taskPipelineTask

Task object.

quantumQuantum

Single Quantum instance.

taskDefTaskDef

Task definition structure.

butlerButler

Data butler.

updatedQuantumInputs(quantum: Quantum, butler: Butler, taskDef: TaskDef) Quantum

Update quantum with extra information, returns a new updated Quantum.

Some methods may require input DatasetRefs to have non-None dataset_id, but in case of intermediate dataset it may not be filled during QuantumGraph construction. This method will retrieve missing info from registry.

Parameters:
quantumQuantum

Single Quantum instance.

butlerButler

Data butler.

taskDefTaskDef

Task definition structure.

Returns:
updateQuantum

Updated Quantum instance

writeLogRecords(quantum: Quantum, taskDef: TaskDef, butler: Butler, store: bool) None
writeMetadata(quantum: Quantum, metadata: Any, taskDef: TaskDef, butler: Butler) None