Back to home page

EIC code displayed by LXR

 
 

    


Warning, /tutorial-developing-benchmarks/episodes/04-status_flags.md is written in an unsupported language. File is not indexed.

0001 ---
0002 title: "Exercise 4: Adding a Status Flag"
0003 teaching: 10
0004 exercises: 10
0005 ---
0006 
0007 ::::::::::::::::::::::::::::::::::::::::::::::: questions
0008 
0009 - How can your benchmark indicate that there were detrimental changes to software or detector design?
0010 
0011 :::::::::::::::::::::::::::::::::::::::::::::::
0012 
0013 ::::::::::::::::::::::::::::::::::::::::::::::: objectives
0014 
0015 - Learn what a status flag is and how to add one to your benchmark
0016 
0017 :::::::::::::::::::::::::::::::::::::::::::::::
0018 
0019 We've created a benchmark and tested it with GitLab's CI tools. Now let's explore one of the tools available to us to alert fellow developers when there has been a detrimental change in performance for your benchmark.
0020 
0021 ## What is a Status Flag?
0022 
0023 A typical benchmark might have 5 to 20 figures which each may or may not be useful in understanding detector and algorithm performance. Developers need rapid feedback when making changes to the tracking software, changing the detector geometry and so on.
0024 
0025 As a benchmark developer, the way you can design this into your benchmark is with a status flag. Status flags are binary pass/fail flags which are summarized at the end of a pipeline. These allow other developers to quickly identify any detrimental changes they may have made to the EIC software environment.
0026 
0027 At the completion of one of GitLab's pipelines, the status flags from each benchmark are gathered and summarized like this one:
0028 <img src="fig/example_status.png" alt="Status flag example" width="500">
0029 
0030 You can think about what quantities might be relevant to monitor. For example, since the u-channel rho benchmark is being used to evaluate the performance of the B0 trackers, this benchmark has a status flag assigned to the efficiency of rho reconstruction within the B0. In the April campaign, this efficiency was observed to be at roughly 95%. A flag was set such that if the efficiency dropped below 90%, it would indicate notable degredation of the performance of far-forward tracking.
0031 
0032 Depending on your observable, you might set a status flag on:
0033 
0034 - the mass width of a reconstructed particle
0035 - reconstructed momentum resolution
0036 - energy resolution in a calorimeter
0037 
0038 Just remember that a status flag that is raised too often stops being alarming to developers. So try to leave some margin for error, and check in on the benchmark's performance every so often.
0039 
0040 ## Adding a Status Flag to Your Benchmark
0041 
0042 To add a status flag, first define a function to set the benchmark status. In this example, the following function was added to the plotting macro `benchmarks/your_benchmark/macros/plot_rho_physics_benchmark.C`:
0043 
0044 ```c++
0045 ///////////// Set benchmark status!
0046 int setbenchstatus(double eff){
0047         // create our test definition
0048         common_bench::Test rho_reco_eff_test{
0049           {
0050             {"name", "rho_reconstruction_efficiency"},
0051             {"title", "rho Reconstruction Efficiency for rho -> pi+pi- in the B0"},
0052             {"description", "u-channel rho->pi+pi- reconstruction efficiency "},
0053             {"quantity", "efficiency"},
0054             {"target", "0.9"}
0055           }
0056         };
0057         //this need to be consistent with the target above
0058         double eff_target = 0.9;
0059 
0060         if(eff<0 || eff>1){
0061           rho_reco_eff_test.error(-1);
0062         }else if(eff > eff_target){
0063           rho_reco_eff_test.pass(eff);
0064         }else{
0065           rho_reco_eff_test.fail(eff);
0066         }
0067 
0068         // write out our test data
0069         common_bench::write_test(rho_reco_eff_test, "./benchmark_output/u_rho_eff.json");
0070         return 0;
0071 }
0072 ```
0073 
0074 We also have to include the appropriate header. At the top of `plot_benchmark.C`, please also add:
0075 
0076 ```c++
0077 #include "common_bench/benchmark.h"
0078 ```
0079 
0080 In the main plotting function, the reconstruction efficiency is calculated, then compared against the target:
0081 
0082 ```c++
0083 minbineff = h_VM_mass_MC_etacut->FindBin(0.6);
0084 maxbineff = h_VM_mass_MC_etacut->FindBin(1.0);
0085 double reconstuctionEfficiency = (1.0*h_VM_mass_REC_etacut->Integral(minbineff,maxbineff))/(1.0*h_VM_mass_MC_etacut->Integral(minbineff,maxbineff));
0086 //set the benchmark status:
0087 setbenchstatus(reconstuctionEfficiency);
0088 ```
0089 
0090 Now every time the plotting macro is run, it will generate the `json` file `benchmark_output/u_rho_eff.json` with this status flag. In order propagate this flag through the pipeline, you need also to create a top-level `json` file which will collect all status flags in your benchmark. 
0091 
0092 In your benchmark directory, create a file titled `benchmark.json`, or copy [this ready-made benchmark.json](files/benchmark.json). The file should contain a name and title for your benchmark, as well as a description:
0093 
0094 ```json
0095 {
0096   "name": "YOUR BENCHMARK NAME",
0097   "title": "YOUR BENCHMARK TITLE",
0098   "description": "Benchmark for ...",
0099   "target": "0.9"
0100 }
0101 ```
0102 
0103 To keep the status flags as artifacts, also add these lines to the end of the `results` rule in your `config.yml`
0104 
0105 ```yaml
0106     - echo "Finished, copying over json now"
0107     - cp benchmark_output/u_rho_eff.json results/your_benchmark/
0108     - echo "Finished copying!" 
0109 ```
0110 
0111 The status flags from your benchmark should all collected and summarized in this stage of the pipeline too. To do this, include the following lines at the end of the stage:
0112 
0113 ```yaml
0114      - collect_tests.py your_benchmark
0115      - echo "Finished collecting!"
0116 ```
0117 
0118 Now push to GitHub!
0119 
0120 ```bash
0121 git add benchmarks/your_benchmark/config.yml
0122 git add benchmarks/your_benchmark/macros/plot_rho_physics_benchmark.C
0123 git add benchmarks/your_benchmark/benchmark.json
0124 
0125 git commit -m "added a status flag!"
0126 git push origin pr/your_benchmark_<mylastname>
0127 ```
0128 
0129 Check the pipelines: 
0130 
0131 - [physics benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines)
0132 - [detector benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines)
0133 
0134 ::::::::::::::::::::::::::::::::::::::::::::::: challenge
0135 
0136 ## Exercise
0137 
0138 - Try to identify several places where the status flag information is kept. It may take a while for these to run, so [check this example pipeline](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/103909).
0139 
0140 ::::::::::::::: solution
0141 
0142 The status flag information is stored in several places: the per-test `benchmark_output/u_rho_eff.json` written by the plotting macro, the top-level `benchmark.json` in your benchmark directory, the copies kept as artifacts under `results/your_benchmark/`, and the summary produced by `collect_tests.py` at the `finish` stage of the pipeline.
0143 
0144 :::::::::::::::
0145 
0146 :::::::::::::::::::::::::::::::::::::::::::::::
0147 
0148 ::::::::::::::::::::::::::::::::::::::::::::::: keypoints
0149 
0150 - Status flags are used to indicate detrimental changes to software/detector design
0151 - Add a status flag to your benchmark to alert developers to changes in performance
0152 
0153 :::::::::::::::::::::::::::::::::::::::::::::::