Source code for pycif.plugins.transforms.system.dump2inputs.adjoint

from logging import info


[docs] def adjoint( transform, inout_datastore, controlvect, obsvect, mapper, di, df, mode, runsubdir, workdir, onlyinit=False, check_transforms=False, **kwargs ): """Read model adjoint sensitivity files back into CIF arrays. The adjoint of :func:`forward`: calls ``transform.native2inputs_adj`` to read the model-native adjoint sensitivity files and convert them to CIF-internal arrays. The results are merged into both ``'inputs'`` and ``'outputs'`` sub-dicts of the datastore. Args: transform (Plugin): dump2inputs instance (carries ``native2inputs_adj``). inout_datastore (dict): mutable datastore. controlvect: unused. obsvect: unused. mapper (dict): transform mapper. di (datetime): sub-simulation start date. df (datetime): sub-simulation end date. mode (str): ``'adj'``. runsubdir (str): passed to ``native2inputs_adj``. workdir (str): unused. onlyinit (bool): if ``True``, ``native2inputs_adj`` is not called. check_transforms (bool): passed to ``native2inputs_adj``. **kwargs: unused. """ datastore = inout_datastore["outputs"] for trid in mapper["inputs"]: input_type = trid[0] # Create new data to extract data2dump = {trid: {"data": datastore.get(trid, {}), **mapper["inputs"][trid]}} if not onlyinit: data2dump = transform.native2inputs_adj( data2dump, input_type, di, df, runsubdir, mode, check_transforms=check_transforms ) for tr in data2dump: if tr in inout_datastore["inputs"]: inout_datastore["inputs"][tr].update(data2dump[tr]["data"]) else: info( f"{tr} was simulated by the model, but could not be transferred to the control vector" ) # Update inputs inout_datastore["inputs"].update(inout_datastore["outputs"])