Skip to content

Commit

Permalink
chore(ci): print protocol circuits gate counts
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Dec 16, 2024
1 parent b3bca76 commit 9597ce9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/scripts/merge-gates-reports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -eu

REPORT_NAME=$1
NAME_PLURAL=""$REPORT_NAME"s"

combined_reports='{"programs": []}'

# Iterate over each report and merge them
for report in ./reports/*; do
# The report is saved under ./$REPORT_NAME_{ matrix_report }/$REPORT_NAME_{ matrix_report }.json
FILE_PATH=$(echo $(ls $report))

# Extract the $NAME_PLURAL array from each report and merge it
combined_reports=$(jq --argjson COMBINED_REPORTS "$combined_reports" '.programs += $COMBINED_REPORTS.programs' <<< "$(cat "$report/$FILE_PATH")")
done

# Wrap the merged memory reports into a new object as to keep the $NAME_PLURAL key

echo "$combined_reports"

12 changes: 12 additions & 0 deletions .github/scripts/single_artifact_gates_report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e

BACKEND=${BACKEND:-bb}

ARTIFACT_PATH=$1
ARTIFACT_NAME=$(basename "$ARTIFACT_PATH")

GATES_INFO=$($BACKEND gates -b $ARTIFACT_PATH)
MAIN_FUNCTION_INFO=$(echo $GATES_INFO | jq -r '.functions[0] | .name = "main"')
echo "{\"programs\": [ {\"package_name\": \"$ARTIFACT_NAME\", \"functions\": [$MAIN_FUNCTION_INFO]} ]}"

60 changes: 58 additions & 2 deletions .github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ jobs:
with:
path: scripts
sparse-checkout: |
.github/scripts/single_artifact_gates_report.sh
test_programs/compilation_report.sh
sparse-checkout-cone-mode: false

Expand All @@ -314,7 +315,6 @@ jobs:
working-directory: ./test-repo/${{ matrix.project.path }}
run: |
mv /home/runner/work/noir/noir/scripts/test_programs/compilation_report.sh ./compilation_report.sh
chmod +x ./compilation_report.sh
./compilation_report.sh 1
- name: Move compilation report
Expand All @@ -334,6 +334,26 @@ jobs:
retention-days: 3
overwrite: true

# While we've got the compiled artifacts, we measure the number of gates in the circuits.

- name: Generate gates report
working-directory: ./test-repo/${{ matrix.project.path }}
run: |
PACKAGE_NAME=${{ matrix.project.path }}
PACKAGE_NAME=$(basename $PACKAGE_NAME)
mv /home/runner/work/noir/noir/.github/scripts/single_artifact_gates_report.sh ./single_artifact_gates_report.sh
./single_artifact_gates_report.sh ./temp/target/* > gates_report_$PACKAGE_NAME.json
echo "gates_report_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
- name: Upload gates report
uses: actions/upload-artifact@v4
with:
name: gates_report_${{ steps.report.outputs.gates_report_name }}
path: gates_report_${{ steps.report.outputs.gates_report_name }}.json
retention-days: 3
overwrite: true

upload_compilation_report:
name: Upload compilation report
needs: [generate_compilation_report, external_repo_compilation_report]
Expand Down Expand Up @@ -378,6 +398,43 @@ jobs:
header: compilation
message: ${{ steps.compilation_report.outputs.markdown }}

upload_gates_report:
name: Upload gates report
needs: [external_repo_compilation_report]
# We want this job to run even if one variation of the matrix in `external_repo_compilation_report` fails
if: always()
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- uses: actions/checkout@v4

- name: Download matrix gates reports
uses: actions/download-artifact@v4
with:
pattern: gates_report_*
path: ./reports

- name: Merge gates reports using jq
run: |
mv ./.github/scripts/merge-gates-reports.sh merge-gates-reports.sh
./merge-gates-reports.sh > protocol_circuits_gates_report.json
- name: Compare gates reports
id: gates_diff
uses: noir-lang/noir-gates-diff@1931aaaa848a1a009363d6115293f7b7fc72bb87
with:
report: protocol_circuits_gates_report.json
summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%)

- name: Add memory report to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: protocol_gates
message: ${{ steps.gates_diff.outputs.markdown }}

external_repo_memory_report:
needs: [build-nargo]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -427,7 +484,6 @@ jobs:
working-directory: ./test-repo/${{ matrix.project.path }}
run: |
mv /home/runner/work/noir/noir/scripts/test_programs/memory_report.sh ./memory_report.sh
chmod +x ./memory_report.sh
./memory_report.sh 1
- name: Move compilation report
Expand Down

0 comments on commit 9597ce9

Please sign in to comment.