pycif.plugins.obsoperators.standard — API reference#
Configuration reference: standard plugin
- pycif.plugins.obsoperators.standard.check.check_inputs(inputs, mode)[source]#
Check the consistency of inputs given to the observation operator.
Validates that mode is one of the accepted values and that inputs carries the attributes required by that mode.
- Parameters:
inputs – control or observation vector passed to the operator; must expose at least
xfor'fwd'mode, and bothxanddxfor'tl'mode.mode (str) – requested execution mode — one of
'fwd','tl', or'adj'.
- Returns:
Trueif all checks pass.- Return type:
bool
- Raises:
Exception – if mode is not one of
'fwd','tl', or'adj'.Exception – if mode is
'tl'and inputs does not expose bothxanddx.
- pycif.plugins.obsoperators.standard.flushrun.flushrun(self, workdir, rundir, mode, transform_pipe, full_flush=True)[source]#
Remove intermediate files produced by transforms that are no longer needed.
Iterates over every transform in transform_pipe and calls each transform’s own
flushrunmethod to clean up its output files in rundir. In adjoint mode, when the operator is not running in approximate mode, the forward reference directory of each transform is also flushed — provided it lies inside workdir, to avoid accidentally deleting files outside the managed tree.- Parameters:
self (ObsOperator) – the obs-operator plugin instance.
workdir (str) – root working directory; used to check that
transf.adj_refdiris a safe path to flush.rundir (str) – the run sub-directory whose files should be cleaned.
mode (str) – execution mode — one of
'fwd','tl', or'adj'; controls whetheradj_refdirof each transform is also flushed.transform_pipe – the
Transformobject holding all transforms for this run.full_flush (bool, optional) – forwarded to each transform’s own
flushrun; ifFalseonly a partial cleanup is performed (exact behaviour is transform-specific). Defaults toTrue.
- Raises:
PluginError – caught internally and logged as a warning if a transform’s
flushrunraises it; execution continues with the remaining transforms.
- pycif.plugins.obsoperators.standard.obsoper.obsoper(self, controlvect, obsvect, mode, run_id=0, datei=datetime.datetime(1979, 1, 1, 0, 0), datef=datetime.datetime(2100, 1, 1, 0, 0), workdir='./', reload_results=False, check_transforms=False, ignore_exceptions=False, force_fetch_results=False, **kwargs)[source]#
Run the standard observation operator in forward, tangent-linear or adjoint mode.
Orchestrates the full observation-operator pipeline:
Creates a per-run sub-directory
obsoperator/<mode>_<run_id>/under workdir.If
reload_resultsis set, attempts to recover cached outputs from a previous run before computing from scratch.Dispatches to
obsoper_serial()orobsoper_parallel()depending on whetherself.parallelis configured.Dumps the resulting observation or control vector to disk for later use.
- Parameters:
self (ObsOperator) – the obs-operator plugin instance.
controlvect (ControlVect) – control-vector object. Must carry
x(anddxfor'tl'mode); receivesdxin'adj'mode.obsvect (ObsVect) – observation-vector object. Receives
ysim(anddyfor'tl'mode); providesdyin'adj'mode.mode (str) – execution mode — one of
'fwd','tl', or'adj'.run_id (int | str, optional) – identifier for the current run; used to name the sub-directory. Defaults to
0.datei (datetime.datetime, optional) – start date of the simulation window. Defaults to
datetime.datetime(1979, 1, 1).datef (datetime.datetime, optional) – end date of the simulation window. Defaults to
datetime.datetime(2100, 1, 1).workdir (str, optional) – parent directory in which the run sub-directory is created. Defaults to
"./"reload_results (bool, optional) – if
True, attempt to recover pre-computed outputs from the run sub-directory before running the full pipeline. Defaults toFalse.check_transforms (bool, optional) – if
True, run each transform in both directions and verify the adjoint / TL identity; disables result reloading. Defaults toFalse.ignore_exceptions (bool, optional) – if
True, non-fatal transform errors are logged and swallowed rather than re-raised. Defaults toFalse.force_fetch_results (bool, optional) – if
Trueand cached outputs cannot be found, raiseIOErrorinstead of computing. Defaults toFalse.**kwargs – extra keyword arguments (ignored).
- Returns:
in
'fwd'and'tl'modes — the updated obsvect withysim(anddy) populated.ControlVect: in
'adj'mode — the updated controlvect withdxpopulated.- Return type:
- Raises:
TypeError – if run_id is neither an
intnor astr.IOError – if
force_fetch_resultsisTrueand cached outputs cannot be loaded.
- pycif.plugins.obsoperators.standard.parallel.run_pycif_in_subprocess(python_path, yaml_path)[source]#
Run a pyCIF configuration file in a blocking subprocess.
Launches
python_path -m pycif yaml_path, redirecting stdout tosubprocess_stdout.logand stderr tosubprocess_stderr.login the same directory as yaml_path.- Parameters:
python_path (str) – path to the Python interpreter (e.g.
self.platform.python).yaml_path (str) – absolute path to the pyCIF YAML configuration file to execute.
- Raises:
RuntimeError – if the subprocess exits with a non-zero return code.
- pycif.plugins.obsoperators.standard.parallel.obsoper_parallel(self, controlvect, obsvect, rundir, mode, workdir, check_transforms, ignore_exceptions)[source]#
Run the observation operator in parallel over independent time segments.
Splits the simulation window
[self.datei, self.datef]into segments of lengthself.parallel.segmentswith optional boundary overlapself.parallel.overlap, then runs each segment independently — either as subprocesses (self.parallel.subprocess = True) or as HPC jobs via theplatformplugin.Each segment is configured via a freshly dumped YAML file that restricts the
approx_operatorwindow to its date range, then executed withrun_pycif_in_subprocess()orself.platform.submit_job.After all segments finish, their outputs are reassembled:
'tl'mode —obsvect.ysimandobsvect.dyare set to the element-wise sums over all segment observation vectors.'adj'mode —controlvect.dxis set to the element-wise sum over all segment adjoint sensitivities;controlvect.xandcontrolvect.xbare reset to their pre-run values.
- Parameters:
self (ObsOperator) – the obs-operator plugin instance. Must have
self.parallel(withsegments,overlap,subprocessattributes),self.datei,self.datef,self.ref_fwd_dir, andself.platformset.controlvect (ControlVect) – control-vector object.
obsvect (ObsVect) – observation-vector object.
rundir (str) – the run sub-directory for this operator call.
mode (str) – execution mode —
'tl'or'adj'. (Forward mode is always dispatched to serial execution.)workdir (str) – parent working directory.
check_transforms (bool) – if
True, validate each segment’s transform adjoint / TL identity.ignore_exceptions (bool) – if
True, non-fatal transform errors inside segments are swallowed.
- Raises:
RuntimeError – if a subprocess-based segment exits with a non-zero return code (propagated from
run_pycif_in_subprocess()).
- pycif.plugins.obsoperators.standard.serial.obsoper_serial(self, controlvect, obsvect, rundir, mode, workdir, check_transforms, ignore_exceptions)[source]#
Run the observation operator sequentially over all transforms and time steps.
Handles bookkeeping common to every serial execution:
'fwd'/'tl'— zerosobsvect.ysimandobsvect.dy, then dumps the control vector torundir/controlvect.pickle.'adj'— initialisescontrolvect.dx = 0and enables forward-run chaining for multi-step models.
Dispatches to the Dask execution path (
init_dask()) whenself.use_daskis set, otherwise runs the standard transform loop viado_transforms().After the run, calls
flushrun()to clean up intermediate files whenself.autoflushis set (and the operator is not running in parallel mode).Stores rundir as
self.ref_fwd_dirafter a forward run so that the subsequent adjoint can locate the forward outputs.- Parameters:
self (ObsOperator) – the obs-operator plugin instance.
controlvect (ControlVect) – control-vector object.
obsvect (ObsVect) – observation-vector object.
rundir (str) – the run sub-directory for this operator call.
mode (str) – execution mode — one of
'fwd','tl', or'adj'.workdir (str) – parent working directory; forwarded to
flushrun().check_transforms (bool) – if
True, validate each transform’s adjoint / TL identity.ignore_exceptions (bool) – if
True, non-fatal transform errors are swallowed rather than re-raised.