Skip to content

Clean up logic for customising PyConf.Algorithm outputs

Rosen Matev requested to merge rm-pyconf-output into master
  • The shape of outputs now participates in the algorithm identity. This fixes the issue of mistakenly getting a cached instance that does not correspond to the given outputs.
  • Removed the possibility of outputs being a list.
  • Always require outputs when output_transform is given and deprecate inferring outputs from output_transform's keyword parameters.
  • Improve documentation for customising outputs
  • Add a number of sanity checks and tests for outputs.
  • Add some more meaningful examples of customising output in test_outputs_examples().
  • Remove use of cachetools (closes #127 (closed)).

/cc @sponce

Example of how this might be used with !2993 (merged)

    # Dynamically-sized list of outputs
    location_map = OrderedDict([
        # ("exposed attribute", "location/branch in input file")
        ("VeloRawEvent", "/Event/Velo/RawEvent"),
        ("CaloRawEvent", "/Event/Calo/RawEvent"),
    ])

    def RootIOAlg_transform(**outputs):
        return {
            "Branches": {
                location_map[k]: tes_location
                for k, tes_location in outputs.items()
            }
        }

    alg = RootIOAlg(
        outputs={prop: None
                 for prop in location_map},
        output_transform=RootIOAlg_transform)
    assert isinstance(alg.VeloRawEvent, DataHandle)
    assert isinstance(alg.CaloRawEvent, DataHandle)
    alg_conf, = alg.configuration().values()
    assert alg_conf["Branches"] == {
        location_map["VeloRawEvent"]: alg.VeloRawEvent.location,
        location_map["CaloRawEvent"]: alg.CaloRawEvent.location,
    }
Edited by Rosen Matev

Merge request reports