Skip to content
Snippets Groups Projects
Select Git revision
  • 922a512b26b24eb560bd04ae9241a157e61a6917
  • master default protected
  • optimize_workflow
  • releases/v5.1 protected
  • releases/v5.1rc1 protected
  • reverse_versions
  • poppy_integration_v50
  • poppy_integration
  • releases/v5.0 protected
  • use-versioned-releases
  • releases/v5.0rc2 protected
  • releases/v5.0rc1 protected
  • releases/ldv_v407_atdb protected
  • ldv_v407_debug
  • releases/ldv_v406_debug protected
  • releases/ldv_v405 protected
  • releases/ldv_v404 protected
  • v5.1
  • v5.0
  • v5.0rc2
  • v5.0rc1
  • ldv_v406_debug
  • ldv_v405_debug
  • ldv_v404
  • ldv_v403
  • ldv_v402
  • v4.0
  • ldv_v401
  • ldv_v40
  • ldv_v031
  • ldv_v03
  • ldv_v01
32 results

check_workflow_results.py

Blame
  • Marcel Loose's avatar
    Marcel Loose authored
    The existing script to compare workflow results bails out of first error.
    This improved version tries to do as many checks as possible. It also
    saves the values of differing solution tables in human-readable format
    for later inspection.
    1160a283
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    check_workflow_results.py 2.84 KiB
    #! /usr/bin/env python3
    """
    Checks the outputs of a workflow run
    """
    import argparse
    from argparse import RawTextHelpFormatter
    from losoto.h5parm import h5parm
    import os
    import sys
    from filecmp import dircmp
    import numpy as np
    
    
    def main(results_path, control_path):
        """
        Checks the outputs of an end-to-end workflow job
    
        Parameters
        ----------
        results_path : str
            Path to output results directory of job
        control_path : str
            Path to control results directory
        """
        error = False
        # Check that all expected output files are present
        dcmp = dircmp(results_path, control_path)
        if len(dcmp.left_only) > 0 or len(dcmp.right_only) > 0:
            if len(dcmp.left_only) > 0:
                print('ERROR: The following files are present in the output but not in the '
                      'control: {}'.format(dcmp.left_only))
            if len(dcmp.right_only) > 0:
                print('ERROR: The following files are present in the control but not in the '
                      'output: {}'.format(dcmp.right_only))
            error = True
    
        # Check that the calibration solutions match the control ones
        check_h5parm = os.path.join(results_path, 'cal_values', 'cal_solutions.h5')
        control_h5parm = os.path.join(control_path, 'cal_values', 'cal_solutions.h5')
        check_h5 = h5parm(check_h5parm, readonly=True)
        control_h5 = h5parm(control_h5parm, readonly=True)
        for check_solset in check_h5.getSolsets():
            control_solset = control_h5.getSolset(check_solset.name)
            for check_soltab in check_solset.getSoltabs():
                control_soltab = control_solset.getSoltab(check_soltab.name)
                if not np.allclose(check_soltab.val, control_soltab.val, rtol=1e-03,
                                   atol=1e-03, equal_nan=True):
                    error = True
                    print('ERROR: Val array of soltab {} of solset {} does not match '
                          'the control'.format(check_soltab.name, check_solset.name))
                    with open("check_soltab.{}.val".format(check_soltab.name), "w") as f:
                        f.write(str(check_soltab.val))
                    with open("control_soltab.{}.val".format(control_soltab.name), "w") as f:
                        f.write(str(control_soltab.val))
                else:
                    print('INFO: Val array of soltab {} of solset {} matches '
                          'the control'.format(check_soltab.name, check_solset.name))
        control_h5.close()
        check_h5.close()
        sys.exit(error)
    
    if __name__ == '__main__':
        descriptiontext = "Checks the ouput of a workflow run.\n"
    
        parser = argparse.ArgumentParser(description=descriptiontext, formatter_class=RawTextHelpFormatter)
        parser.add_argument('results_path', help='Path to output results')
        parser.add_argument('control_path', help='Path to control results')
        args = parser.parse_args()
    
        main(args.results_path, args.control_path)