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 questions: How do we create a new pipeline with GitLab CI?
0006 objectives:
0007 - "Go through the process of contributing benchmarks on GitHub"
0008 - "Learn basics of running on eicweb GitLab CI"
0009 keypoints:
0010 ---
0011
0012 ## Setting up a repository
0013
0014 Let's now put our analysis workflow on GitLab's Continuous Integration (CI) system!
0015
0016 Benchmarks are currently organized into two repositories:
0017
0018 - [https://github.com/eic/detector_benchmarks](https://github.com/eic/detector_benchmarks)
0019 - [https://github.com/eic/physics_benchmarks](https://github.com/eic/physics_benchmarks)
0020
0021 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:
0022
0023 ```bash
0024 git clone git@github.com:eic/physics_benchmarks.git
0025 cd physics_benchmarks
0026 ```
0027
0028 (If you get an error here, you might need to set up your SSH keys.)
0029
0030 Please create a feature branch in your local repository:
0031
0032 ```bash
0033 git checkout -b pr/your_benchmark_<mylastname>
0034 ```
0035
0036 *(Replace `<mylastname>` with your last name or any other nickname.)*
0037
0038 ## Defining GitLab Continuous Integration jobs
0039
0040 Let's see what kind of bechmarks are available:
0041
0042 ```output
0043 # ls benchmarks
0044 backgrounds benchmarks.json demp diffractive_vm dis dvcs dvmp tcs u_omega
0045 ```
0046
0047 Now, create a new directory for your benchmark
0048
0049 ```bash
0050 mkdir benchmarks/your_benchmark
0051 ```
0052
0053 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`.
0054
0055 For a physics benchmark, create a `config.yml` with the following contents:
0056 ~~~
0057 your_benchmark:compile:
0058 extends: .phy_benchmark
0059 stage: compile
0060 script:
0061 - echo "You can compile your code here!"
0062
0063 your_benchmark:simulate:
0064 extends: .phy_benchmark
0065 stage: simulate
0066 script:
0067 - echo "I will simulate detector response here!"
0068
0069 your_benchmark:results:
0070 extends: .phy_benchmark
0071 stage: collect
0072 needs:
0073 - ["your_benchmark:simulate"]
0074 script:
0075 - echo "I will collect results here!"
0076
0077 ~~~
0078 {: .language-yaml }
0079
0080 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).
0081
0082 A few things to note about the `config.yml`:
0083 - 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.
0084 - Each rule does not need to do something. In the example `config.yml` given here, each rule is just printing a statement.
0085 - 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).
0086
0087 Since we've just created a new file, we need to let git know about it by staging it:
0088
0089 ```shell
0090 git add benchmarks/your_benchmark/config.yml
0091 ```
0092
0093 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:
0094
0095 ```yaml
0096 include:
0097 - local: 'benchmarks/diffractive_vm/config.yml'
0098 - local: 'benchmarks/dis/config.yml'
0099 - local: 'benchmarks/dvmp/config.yml'
0100 - local: 'benchmarks/dvcs/config.yml'
0101 - local: 'benchmarks/tcs/config.yml'
0102 - local: 'benchmarks/u_omega/config.yml'
0103 - local: 'benchmarks/backgrounds/config.yml'
0104 ```
0105
0106 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:
0107 ```yaml
0108 include:
0109 #- local: 'benchmarks/diffractive_vm/config.yml'
0110 - local: 'benchmarks/dis/config.yml'
0111 #- local: 'benchmarks/dvmp/config.yml'
0112 #- local: 'benchmarks/dvcs/config.yml'
0113 #- local: 'benchmarks/tcs/config.yml'
0114 #- local: 'benchmarks/u_omega/config.yml'
0115 #- local: 'benchmarks/backgrounds/config.yml'
0116 - local: 'benchmarks/your_benchmark/config.yml'
0117 ```
0118
0119 In order to make your benchmark produce artifacts, also add your benchmark to this section, and comment out any benchmarks you commented out above:
0120 ```yaml
0121 summary:
0122 stage: finish
0123 needs:
0124 #- "diffractive_vm:results"
0125 - "dis:results"
0126 #- "dvcs:results"
0127 #- "tcs:results"
0128 #- "u_omega:results"
0129 #- "backgrounds:results"
0130 - "your_benchmark:results"
0131 ```
0132 Save and close the file.
0133
0134
0135 The change that you've just made needs to be also staged. We will now learn a cool git trick. Run this:
0136
0137 ```shell
0138 git add -p
0139 ```
0140
0141 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>.
0142
0143 ## Submit a GitHub Pull Request
0144
0145 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:
0146
0147 ```shell
0148 git commit -m "add benchmarks/your_benchmark"
0149 ```
0150
0151 And push that branch from the local repository to the shared repository on GitHub (referenced to as `origin`):
0152
0153 ```shell
0154 git push origin pr/your_benchmark_<mylastname>
0155 ```
0156 *(Replace `<mylastname>` with your last name.)*
0157
0158 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.
0159 3.  Provide a title like "Adding benchmark for ...".
0160 4.  Since this work is not yet complete, open dropdown menu of the "Create pull requst" button and select "Create draft pull request"
0161 5.  Click "Draft pull request"
0162
0163 Your newly created Pull Request will show up.
0164
0165 ## Examine CI output on eicweb GitLab
0166
0167 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.
0168
0169 
0170
0171 Click "Details", it will take you to eicweb GitLab instance. The pipeline will show all the existing jobs. Physics benchmark pipelines are viewable [here](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines) and detector benchmark pipleines are viewable [here](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines). You should be able to see your new jobs. Each stage of the pipeline shown here corresponds to a rule in the `config.yml`:
0172
0173 
0174
0175 - This example pipeline is viewable [here](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/102686).
0176 - 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)
0177 - 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)
0178
0179 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.
0180
0181 
0182
0183 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.
0184
0185 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!
0186
0187 ## Conclusion
0188
0189 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.
0190
0191 You can view these pipelines here:
0192 - [physics benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines)
0193 - [detector benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines)
0194
0195 {% include links.md %}
0196