Coverage for python/lsst/ctrl/mpexec/cli/script/report.py: 14%
39 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-26 09:59 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-26 09:59 +0000
1# This file is part of ctrl_mpexec.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27import pprint
29import yaml
30from astropy.table import Table
31from lsst.daf.butler import Butler
32from lsst.pipe.base import QuantumGraph
33from lsst.pipe.base.execution_reports import QuantumGraphExecutionReport
36def report(
37 butler_config: str,
38 qgraph_uri: str,
39 full_output_filename: str | None,
40 logs: bool = True,
41 show_errors: bool = False,
42) -> None:
43 """Summarize the produced and missing expected dataset in a quantum graph.
45 Parameters
46 ----------
47 butler_config : `str`
48 The Butler used for this report. This should match the Butler used
49 for the run associated with the executed quantum graph.
50 qgraph_uri : `str`
51 The uri of the location of said quantum graph.
52 full_output_filename : `str`
53 Output the full summary report to a yaml file (named herein).
54 Each data id and error message is keyed to a quantum graph node id.
55 A convenient output format for error-matching and cataloguing tools
56 such as the ones in the Campaign Management database. If this is
57 not included, quanta and dataset information will be printed to the
58 command-line instead.
59 logs : `bool`
60 Get butler log datasets for extra information (error messages).
61 show_errors : `bool`
62 If no output yaml is provided, print error messages to the
63 command-line along with the report. By default, these messages and
64 their associated data ids are stored in a yaml file with format
65 `{run timestamp}_err.yaml` in the working directory instead.
66 """
67 butler = Butler.from_config(butler_config, writeable=False)
68 qgraph = QuantumGraph.loadUri(qgraph_uri)
69 report = QuantumGraphExecutionReport.make_reports(butler, qgraph)
70 if not full_output_filename:
71 # this is the option to print to the command-line
72 summary_dict = report.to_summary_dict(butler, logs, human_readable=True)
73 dataset_table_rows = []
74 data_products = []
75 quanta_summary = []
76 error_summary = []
77 for task in summary_dict.keys():
78 for data_product in summary_dict[task]["outputs"]:
79 dataset_table_rows.append(summary_dict[task]["outputs"][data_product])
80 data_products.append(data_product)
82 quanta_summary.append(
83 {
84 "Task": task,
85 "Failed Quanta": summary_dict[task]["failed_quanta"],
86 "Blocked Quanta": summary_dict[task]["n_quanta_blocked"],
87 }
88 )
90 if "errors" in summary_dict[task].keys():
91 error_summary.append({task: summary_dict[task]["errors"]})
92 quanta = Table(quanta_summary)
93 datasets = Table(dataset_table_rows)
94 datasets.add_column(data_products, index=0, name="DatasetType")
95 quanta.pprint_all()
96 print("\n")
97 if show_errors:
98 pprint.pprint(error_summary)
99 print("\n")
100 else:
101 assert qgraph.metadata is not None, "Saved QGs always have metadata."
102 collection = qgraph.metadata["output_run"]
103 collection = str(collection)
104 run_name = collection.split("/")[-1]
105 with open(f"{run_name}_err.yaml", "w") as stream:
106 yaml.safe_dump(error_summary, stream)
107 datasets.pprint_all()
108 else:
109 report.write_summary_yaml(butler, full_output_filename, do_store_logs=logs)