climate_ref_core.executor
#
Executor interface for running diagnostics
Executor
#
Bases: Protocol
An executor is responsible for running a diagnostic asynchronously
The diagnostic may be run locally in the same process or in a separate process or container.
Notes
This is an extremely basic interface and will be expanded in the future, as we figure out our requirements.
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
collects_results_on_join
instance-attribute
#
Whether execution results are only collected and persisted during join.
When True (e.g. the local process pool and HPC executors), skipping join
(via --no-wait) leaves completed outputs in the scratch directory
without copying them to the results directory or ingesting them.
When False (e.g. the synchronous and Celery executors),
results are persisted elsewhere (inline in run or by a worker callback),
so join only waits for completion.
join(timeout)
#
Wait for all executions to finish
If the timeout is reached, the method will return and raise an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Maximum time to wait for all executions to finish in seconds |
required |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout is reached |
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
run(definition, execution=None)
#
Execute a diagnostic with a given definition
No executions are returned from this method, as the execution may be performed asynchronously so executions may not be immediately available.
Note
In future, we may return a Future object that can be used to retrieve the result,
but that requires some additional work to implement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
ExecutionDefinition
|
Definition of the information needed to execute a diagnostic This definition describes which datasets are required to run the diagnostic and where the output should be stored. |
required |
execution
|
Any
|
The execution object to update with the results of the execution. This is a database object that contains the executions of the execution. If provided, it will be updated with the executions of the execution. This may happen asynchronously, so the executions may not be immediately available. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Results from running the diagnostic |
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
execute_locally(definition, log_level, raise_error=False, measure=True, exclusive=False)
#
Run a diagnostic execution
This is the chunk of work that should be executed by an executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
ExecutionDefinition
|
A description of the information needed for this execution of the diagnostic |
required |
log_level
|
str
|
The log level to use for the execution |
required |
measure
|
bool
|
Whether to record what the execution costs in wall time, CPU time and peak memory. When False the result carries no resource usage. |
True
|
exclusive
|
bool
|
Whether this process has its cgroup to itself for the duration of the execution. Only the executor knows its own concurrency. When False the peak memory is measured over this process tree rather than the cgroup. |
False
|
Source code in packages/climate-ref-core/src/climate_ref_core/executor.py
import_executor_cls(fqn)
#
Import an executor using a fully qualified module path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fqn
|
str
|
Full package and attribute name of the executor to import For example: |
required |
Raises:
| Type | Description |
|---|---|
InvalidExecutorException
|
If the executor cannot be imported If the executor isn't a valid |
Returns:
| Type | Description |
|---|---|
type[Executor]
|
Executor instance |