Warning, /tutorial-developing-benchmarks/episodes/02-first_benchmark.md is written in an unsupported language. File is not indexed.
0001 ---
0002 title: "Exercise 2: Setting up your first benchmark with pipelines"
0003 teaching: 20
0004 exercises: 10
0005 ---
0006
0007 ::::::::::::::::::::::::::::::::::::::::::::::: questions
0008
0009 - How do we create a new pipeline with GitLab CI?
0010
0011 :::::::::::::::::::::::::::::::::::::::::::::::
0012
0013 ::::::::::::::::::::::::::::::::::::::::::::::: objectives
0014
0015 - Go through the process of contributing benchmarks on GitHub
0016 - Learn basics of running on eicweb GitLab CI
0017
0018 :::::::::::::::::::::::::::::::::::::::::::::::
0019
0020 ## Setting up a repository
0021
0022 Let's now put our analysis workflow on GitLab's Continuous Integration (CI) system!
0023
0024 Benchmarks are currently organized into two repositories:
0025
0026 - [https://github.com/eic/detector_benchmarks](https://github.com/eic/detector_benchmarks)
0027 - [https://github.com/eic/physics_benchmarks](https://github.com/eic/physics_benchmarks)
0028
0029 Let's make a physics benchmark. In the previous lesson, we were working in the `tutorial_directory/starting_script` direcotry. Let's go back one directory to `tutorial_directory/` and start by cloning the git repository:
0030
0031 ```bash
0032 git clone git@github.com:eic/physics_benchmarks.git
0033 cd physics_benchmarks
0034 ```
0035
0036 (If you get an error here, you might need to set up your SSH keys.)
0037
0038 Please create a feature branch in your local repository:
0039
0040 ```bash
0041 git checkout -b pr/your_benchmark_<mylastname>
0042 ```
0043
0044 *(Replace `<mylastname>` with your last name or any other nickname.)*
0045
0046 ## Defining GitLab Continuous Integration jobs
0047
0048 Let's see what kind of bechmarks are available:
0049
0050 ```output
0051 # ls benchmarks
0052 backgrounds benchmarks.json demp diffractive_vm dis dvcs dvmp tcs u_omega
0053 ```
0054
0055 Now, create a new directory for your benchmark
0056
0057 ```bash
0058 mkdir benchmarks/your_benchmark
0059 ```
0060
0061 The Continuous Integration system needs to know what steps it has to execute. This is specified using YAML files. Create a file `benchmarks/your_benchmark/config.yml`.
0062
0063 For a physics benchmark, create a `config.yml` with the following contents:
0064
0065 ```yaml
0066 your_benchmark:compile:
0067 extends: .phy_benchmark
0068 stage: compile
0069 script:
0070 - echo "You can compile your code here!"
0071
0072 your_benchmark:simulate:
0073 extends: .phy_benchmark
0074 stage: simulate
0075 script:
0076 - echo "I will simulate detector response here!"
0077
0078 your_benchmark:results:
0079 extends: .phy_benchmark
0080 stage: collect
0081 needs:
0082 - ["your_benchmark:simulate"]
0083 script:
0084 - echo "I will collect results here!"
0085
0086 ```
0087
0088 The basic idea here is that we are defining the rules for each step of the [pipeline](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/102530).
0089
0090 A few things to note about the `config.yml`:
0091
0092 - The rules take basic bash script as input. Anything you would write in a bash script you can put in the script section of a rule in the `config.yml` file.
0093 - Each rule does not need to do something. In the example `config.yml` given here, each rule is just printing a statement.
0094 - Each rule corresponds to a stage in GitLab's pipelines. So the collect rule in your `config.yml` tells the pipeline what to do when it gets to the collect stage of the [pipeline](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/102530).
0095
0096 Since we've just created a new file, we need to let git know about it by staging it:
0097
0098 ```bash
0099 git add benchmarks/your_benchmark/config.yml
0100 ```
0101
0102 We also need to let the CI system know that we want it to execute steps that we've just defined. For that, it has to be included from the `.gitlab-ci.yml` file. Open it in your text editor of choice and locate lines that look like:
0103
0104 ```yaml
0105 include:
0106 - local: 'benchmarks/diffractive_vm/config.yml'
0107 - local: 'benchmarks/dis/config.yml'
0108 - local: 'benchmarks/dvmp/config.yml'
0109 - local: 'benchmarks/dvcs/config.yml'
0110 - local: 'benchmarks/tcs/config.yml'
0111 - local: 'benchmarks/u_omega/config.yml'
0112 - local: 'benchmarks/backgrounds/config.yml'
0113 ```
0114
0115 Insert an appropriate line for your newly created `benchmarks/your_benchmark/config.yml`. We will be doing a lot of testing using GitLab's pipelines. We don't need GitLab to simulate every other benchmark while we're still testing ours. To speed things up, you can comment out most other benchmarks. Consider leaving a few uncommented to make sure everything is working right:
0116
0117 ```yaml
0118 include:
0119 #- local: 'benchmarks/diffractive_vm/config.yml'
0120 - local: 'benchmarks/dis/config.yml'
0121 #- local: 'benchmarks/dvmp/config.yml'
0122 #- local: 'benchmarks/dvcs/config.yml'
0123 #- local: 'benchmarks/tcs/config.yml'
0124 #- local: 'benchmarks/u_omega/config.yml'
0125 #- local: 'benchmarks/backgrounds/config.yml'
0126 - local: 'benchmarks/your_benchmark/config.yml'
0127 ```
0128
0129 In order to make your benchmark produce artifacts, also add your benchmark to this section, and comment out any benchmarks you commented out above:
0130
0131 ```yaml
0132 summary:
0133 stage: finish
0134 needs:
0135 #- "diffractive_vm:results"
0136 - "dis:results"
0137 #- "dvcs:results"
0138 #- "tcs:results"
0139 #- "u_omega:results"
0140 #- "backgrounds:results"
0141 - "your_benchmark:results"
0142 ```
0143
0144 Save and close the file.
0145
0146 The change that you've just made needs to be also staged. We will now learn a cool git trick. Run this:
0147
0148 ```bash
0149 git add -p
0150 ```
0151
0152 Here `-p` stands for `--patch`. This will display unstaged changes to the local files and let you review and optionally stage them. There will be only one change for you to check, so just type <kbd>y</kbd> and press <kbd>Enter</kbd>.
0153
0154 ## Submit a GitHub Pull Request
0155
0156 Even though our benchmark doesn't do anything yet, let's submit it to the CI and see it run and do nothing useful. The way to do it is to submit a pull request. We first commit the staged changes to the current branch:
0157
0158 ```bash
0159 git commit -m "add benchmarks/your_benchmark"
0160 ```
0161
0162 And push that branch from the local repository to the shared repository on GitHub (referenced to as `origin`):
0163
0164 ```bash
0165 git push origin pr/your_benchmark_<mylastname>
0166 ```
0167
0168 *(Replace `<mylastname>` with your last name.)*
0169
0170 1. This should instruct you to go to `https://github.com/eic/physics_benchmarks/pull/new/pr/your_benchmark_<mylastname>` to create a PR. Follow that link.
0171 3.  Provide a title like "Adding benchmark for ...".
0172 4.  Since this work is not yet complete, open dropdown menu of the "Create pull requst" button and select "Create draft pull request"
0173 5.  Click "Draft pull request"
0174
0175 Your newly created Pull Request will show up.
0176
0177 ## Examine CI output on eicweb GitLab
0178
0179 You can now scroll to the bottom of the page and see what checks are running. You may need to wait a bit and/or refresh the page to see a `eicweb/physics_benchmarks (epic_craterlake)` check running.
0180
0181 
0182
0183 Click "Details", it will take you to eicweb GitLab instance. The pipeline will show all the existing jobs. The [physics benchmark pipelines](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines) and [detector benchmark pipelines](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines) are viewable on eicweb GitLab. You should be able to see your new jobs. Each stage of the pipeline shown here corresponds to a rule in the `config.yml`:
0184
0185 
0186
0187 - View [this example pipeline](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/102686).
0188 - All physics benchmark pipelines are here: [https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines)
0189 - All detector benchmark pipelines are here: [https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines)
0190
0191 You can click on individual jobs and see output they produce during running. Our newly created jobs should produce messages in the output. Real scripts could return errors and those would appear as CI failures.
0192
0193 
0194
0195 There is another important feature that jobs can produce artifacts. They can be any file. Take a look at [this pipeline](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/103955). Go to the "your_benchmark:results" job, click "Browse" button in the right column, then navigate to "results", some of the plots from the benchmark are visible here.
0196
0197 Right now, our benchmark will not create these plots. We've just set it up to print statements for each job. In the next lesson, we'll learn how to add everything we need to produce these artifacts to our pipelines!
0198
0199 ## Conclusion
0200
0201 We've practiced contributing code that runs within eicweb Continuous Integration system. Now that we have a good container for our benchmark, in the next lesson we'll start to fill out that shell to make the benchmark actually run an analysis.
0202
0203 You can view these pipelines here:
0204
0205 - [physics benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines)
0206 - [detector benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines)
0207
0208 ::::::::::::::::::::::::::::::::::::::::::::::: keypoints
0209
0210 - Benchmarks live in the `detector_benchmarks` and `physics_benchmarks` repositories
0211 - A benchmark is added to GitLab CI by creating a `config.yml` and including it from `.gitlab-ci.yml`
0212 - Benchmarks are submitted and tested through GitHub pull requests that trigger eicweb GitLab pipelines
0213
0214 :::::::::::::::::::::::::::::::::::::::::::::::