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 and to follow along with this tutorial, 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 script:
0073 - echo "I will collect results here!"
0074
0075 ~~~
0076 {: .language-yaml }
0077
0078 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).
0079
0080 A few things to note about the `config.yml`:
0081 - 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.
0082 - Each rule does not need to do something. In the example `config.yml` given here, each rule is just printing a statement.
0083 - 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).
0084
0085 Since we've just created a new file, we need to let git know about it by staging it:
0086
0087 ```shell
0088 git add benchmarks/your_benchmark/config.yml
0089 ```
0090
0091 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:
0092
0093 ```yaml
0094 include:
0095 - local: 'benchmarks/diffractive_vm/config.yml'
0096 - local: 'benchmarks/dis/config.yml'
0097 - local: 'benchmarks/dvmp/config.yml'
0098 - local: 'benchmarks/dvcs/config.yml'
0099 - local: 'benchmarks/tcs/config.yml'
0100 - local: 'benchmarks/u_omega/config.yml'
0101 - local: 'benchmarks/backgrounds/config.yml'
0102 ```
0103
0104 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:
0105 ```yaml
0106 include:
0107 #- local: 'benchmarks/diffractive_vm/config.yml'
0108 - local: 'benchmarks/dis/config.yml'
0109 #- local: 'benchmarks/dvmp/config.yml'
0110 #- local: 'benchmarks/dvcs/config.yml'
0111 #- local: 'benchmarks/tcs/config.yml'
0112 #- local: 'benchmarks/u_omega/config.yml'
0113 #- local: 'benchmarks/backgrounds/config.yml'
0114 - local: 'benchmarks/your_benchmark/config.yml'
0115 ```
0116
0117 In order to make your benchmark produce artifacts, also add your benchmark to this section, and comment out any benchmarks you commented out above:
0118 ```yaml
0119 summary:
0120 stage: finish
0121 needs:
0122 #- "diffractive_vm:results"
0123 - "dis:results"
0124 #- "dvcs:results"
0125 #- "tcs:results"
0126 #- "u_omega:results"
0127 #- "backgrounds:results"
0128 - "your_benchmark:results"
0129 ```
0130 Save and close the file.
0131
0132
0133 The change that you've just made needs to be also staged. We will now learn a cool git trick. Run this:
0134
0135 ```shell
0136 git add -p
0137 ```
0138
0139 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>.
0140
0141 ## Submit a GitHub Pull Request
0142
0143 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:
0144
0145 ```shell
0146 git commit -m "add benchmarks/your_benchmark"
0147 ```
0148
0149 And push that branch from the local repository to the shared repository on GitHub (referenced to as `origin`):
0150
0151 ```shell
0152 git push origin pr/your_benchmark_<mylastname>
0153 ```
0154 *(Replace `<mylastname>` with your last name.)*
0155
0156 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.
0157 3. ![Add a title]({{ page.root }}/fig/github_add_a_title.png) Provide a title like "Adding benchmark for ...".
0158 4. ![Create draft pull request]({{ page.root }}/fig/github_switch_to_draft.png) Since this work is not yet complete, open dropdown menu of the "Create pull requst" button and select "Create draft pull request"
0159 5. ![Draft pull request]({{ page.root }}/fig/github_draft_pull_request.png) Click "Draft pull request"
0160
0161 Your newly created Pull Request will show up.
0162
0163 ## Examine CI output on eicweb GitLab
0164
0165 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.
0166
0167 ![Check running on GitHub]({{ page.root }}/fig/github_running_check.png)
0168
0169 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`:
0170
0171 ![Check running on eicweb]({{ page.root }}/fig/configToPipelines.png)
0172
0173 - This example pipeline is viewable [here](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines/102686).
0174 - 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)
0175 - 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)
0176
0177 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.
0178
0179 ![Job output on eicweb]({{ page.root }}/fig/eicweb_job_output.png)
0180
0181 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.
0182
0183 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!
0184
0185 ## Conclusion
0186
0187 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.
0188
0189 You can view these pipelines here:
0190 - [physics benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/physics_benchmarks/-/pipelines)
0191 - [detector benchmarks](https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/pipelines)
0192
0193 {% include links.md %}
0194