qcert 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qcert-0.1.0/.github/actions/qcert-action/action.yml +166 -0
- qcert-0.1.0/.github/workflows/action-test.yml +117 -0
- qcert-0.1.0/.github/workflows/ci.yml +83 -0
- qcert-0.1.0/.github/workflows/docker-lean435.yml +137 -0
- qcert-0.1.0/.github/workflows/publish-pypi.yml +91 -0
- qcert-0.1.0/.gitignore +8 -0
- qcert-0.1.0/LAUNCH_KIT_V01.md +79 -0
- qcert-0.1.0/LICENSE +201 -0
- qcert-0.1.0/PKG-INFO +147 -0
- qcert-0.1.0/README.md +120 -0
- qcert-0.1.0/docker/Dockerfile.bwrap-lean435 +19 -0
- qcert-0.1.0/examples/adaptive_branch.qasm +18 -0
- qcert-0.1.0/examples/bell_t.qasm +7 -0
- qcert-0.1.0/examples/rus_loop.qasm +14 -0
- qcert-0.1.0/pyproject.toml +60 -0
- qcert-0.1.0/qcert/__init__.py +26 -0
- qcert-0.1.0/qcert/analysis/__init__.py +1 -0
- qcert-0.1.0/qcert/analysis/tail_sim.py +183 -0
- qcert-0.1.0/qcert/backends/__init__.py +1 -0
- qcert-0.1.0/qcert/backends/lean4.py +313 -0
- qcert-0.1.0/qcert/cli.py +217 -0
- qcert-0.1.0/qcert/extractors/__init__.py +1 -0
- qcert-0.1.0/qcert/extractors/lean4_parser.py +556 -0
- qcert-0.1.0/qcert/frontends/__init__.py +1 -0
- qcert-0.1.0/qcert/frontends/adapters.py +348 -0
- qcert-0.1.0/qcert/frontends/openqasm.py +379 -0
- qcert-0.1.0/qcert/ir.py +347 -0
- qcert-0.1.0/qcert/reporting.py +223 -0
- qcert-0.1.0/qcert/verifier/__init__.py +17 -0
- qcert-0.1.0/qcert/verifier/runner.py +755 -0
- qcert-0.1.0/tailbounds_certificate.json +58 -0
- qcert-0.1.0/tests/conftest.py +34 -0
- qcert-0.1.0/tests/fixtures/bad_syntax.lean +1 -0
- qcert-0.1.0/tests/fixtures/custom_axiom_silent.lean +3 -0
- qcert-0.1.0/tests/fixtures/private_local_axiom.lean +5 -0
- qcert-0.1.0/tests/fixtures/unsound_sorry.lean +3 -0
- qcert-0.1.0/tests/fixtures/unused_local_axiom.lean +3 -0
- qcert-0.1.0/tests/fixtures/valid_def_only.lean +1 -0
- qcert-0.1.0/tests/fixtures/valid_no_print.lean +1 -0
- qcert-0.1.0/tests/test_action.py +332 -0
- qcert-0.1.0/tests/test_adapters.py +305 -0
- qcert-0.1.0/tests/test_docker_cli.py +257 -0
- qcert-0.1.0/tests/test_extractor.py +205 -0
- qcert-0.1.0/tests/test_packaging.py +123 -0
- qcert-0.1.0/tests/test_qcert.py +150 -0
- qcert-0.1.0/tests/test_verifier.py +239 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
name: qcert verification
|
|
2
|
+
description: Verify a Lean file and publish reports using the runner's Python 3.11 or later.
|
|
3
|
+
inputs:
|
|
4
|
+
lean-file:
|
|
5
|
+
description: Lean source file to verify.
|
|
6
|
+
required: true
|
|
7
|
+
repo-path:
|
|
8
|
+
description: Path to an existing, built formal-quantum-computation checkout.
|
|
9
|
+
repo-ref:
|
|
10
|
+
description: Upstream ref to build, or exact expected HEAD SHA for a supplied checkout.
|
|
11
|
+
default: a88de8ff65d78af564b2373088ca369dc95f6547
|
|
12
|
+
mode:
|
|
13
|
+
description: Verifier mode (local or sandbox). Defaults to the verifier's platform selection.
|
|
14
|
+
require-sandbox:
|
|
15
|
+
description: Require sandboxed kernel replay (true or false).
|
|
16
|
+
default: "true"
|
|
17
|
+
docker-image:
|
|
18
|
+
description: Optional locally available Linux sandbox image.
|
|
19
|
+
targets:
|
|
20
|
+
description: Newline- or comma-separated declarations that must be audited.
|
|
21
|
+
cert-out:
|
|
22
|
+
description: JSON certificate path.
|
|
23
|
+
default: qcert-certificate.json
|
|
24
|
+
badge-out:
|
|
25
|
+
description: SVG badge path.
|
|
26
|
+
default: qcert-badge.svg
|
|
27
|
+
badge-url:
|
|
28
|
+
description: Optional HTTP(S) link for the badge.
|
|
29
|
+
summary-out:
|
|
30
|
+
description: Markdown summary path.
|
|
31
|
+
default: qcert-summary.md
|
|
32
|
+
outputs:
|
|
33
|
+
status:
|
|
34
|
+
description: Receipt status, or ERROR when the receipt cannot be used.
|
|
35
|
+
value: ${{ steps.verify.outputs.status }}
|
|
36
|
+
reason-code:
|
|
37
|
+
description: Reason code from the verifier or reporter.
|
|
38
|
+
value: ${{ steps.verify.outputs.reason-code }}
|
|
39
|
+
exit-code:
|
|
40
|
+
description: Verification exit code.
|
|
41
|
+
value: ${{ steps.verify.outputs.exit-code }}
|
|
42
|
+
trust-level:
|
|
43
|
+
description: Trust level recorded by the verifier.
|
|
44
|
+
value: ${{ steps.verify.outputs.trust-level }}
|
|
45
|
+
authoritative:
|
|
46
|
+
description: Whether the receipt establishes authoritative sandboxed kernel replay.
|
|
47
|
+
value: ${{ steps.verify.outputs.authoritative }}
|
|
48
|
+
input-sha256:
|
|
49
|
+
description: SHA-256 of the Lean source snapshot, when available.
|
|
50
|
+
value: ${{ steps.verify.outputs.input-sha256 }}
|
|
51
|
+
export-sha256:
|
|
52
|
+
description: SHA-256 of the kernel replay export, when available.
|
|
53
|
+
value: ${{ steps.verify.outputs.export-sha256 }}
|
|
54
|
+
cert-path:
|
|
55
|
+
description: Requested certificate path.
|
|
56
|
+
value: ${{ steps.verify.outputs.cert-path }}
|
|
57
|
+
badge-path:
|
|
58
|
+
description: SVG badge path.
|
|
59
|
+
value: ${{ steps.verify.outputs.badge-path }}
|
|
60
|
+
summary-path:
|
|
61
|
+
description: Markdown summary path.
|
|
62
|
+
value: ${{ steps.verify.outputs.summary-path }}
|
|
63
|
+
runs:
|
|
64
|
+
using: composite
|
|
65
|
+
steps:
|
|
66
|
+
- id: verify
|
|
67
|
+
name: Verify Lean and render reports
|
|
68
|
+
shell: bash
|
|
69
|
+
env:
|
|
70
|
+
QCERT_ACTION_PATH: ${{ github.action_path }}
|
|
71
|
+
LEAN_FILE: ${{ inputs.lean-file }}
|
|
72
|
+
REPO_PATH: ${{ inputs.repo-path }}
|
|
73
|
+
REPO_REF: ${{ inputs.repo-ref }}
|
|
74
|
+
MODE: ${{ inputs.mode }}
|
|
75
|
+
REQUIRE_SANDBOX: ${{ inputs.require-sandbox }}
|
|
76
|
+
DOCKER_IMAGE: ${{ inputs.docker-image }}
|
|
77
|
+
TARGETS: ${{ inputs.targets }}
|
|
78
|
+
CERT_OUT: ${{ inputs.cert-out }}
|
|
79
|
+
BADGE_OUT: ${{ inputs.badge-out }}
|
|
80
|
+
BADGE_URL: ${{ inputs.badge-url }}
|
|
81
|
+
SUMMARY_OUT: ${{ inputs.summary-out }}
|
|
82
|
+
run: |
|
|
83
|
+
# Load qcert from this action's checkout using the runner's Python 3.11+.
|
|
84
|
+
export PYTHONPATH="$QCERT_ACTION_PATH/../../.."
|
|
85
|
+
export PATH="$HOME/.elan/bin:$PATH"
|
|
86
|
+
|
|
87
|
+
qcert() { python -B -P -m qcert.cli "$@"; }
|
|
88
|
+
|
|
89
|
+
clear_certificate() {
|
|
90
|
+
# Apply the verifier's output restrictions before unlinking a stale file.
|
|
91
|
+
python -B -P - "$CERT_OUT" "$LEAN_FILE" "$REPO_PATH" <<'PY'
|
|
92
|
+
import sys
|
|
93
|
+
from pathlib import Path
|
|
94
|
+
|
|
95
|
+
cert, source = map(Path, sys.argv[1:3])
|
|
96
|
+
repo = sys.argv[3]
|
|
97
|
+
destination = cert.resolve()
|
|
98
|
+
if destination == source.resolve() or (repo and destination.is_relative_to(Path(repo).resolve())):
|
|
99
|
+
raise SystemExit("The certificate destination overlaps the Lean input or reference checkout")
|
|
100
|
+
cert.unlink(missing_ok=True)
|
|
101
|
+
PY
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
prepare_reference() {
|
|
105
|
+
if [[ -n "$REPO_PATH" ]]; then
|
|
106
|
+
local head
|
|
107
|
+
head=$(git -C "$REPO_PATH" rev-parse --verify HEAD) || return 2
|
|
108
|
+
if [[ -n "$REPO_REF" && "$head" != "$REPO_REF" ]]; then
|
|
109
|
+
printf 'Reference HEAD mismatch: expected %s, got %s\n' "$REPO_REF" "$head" >&2
|
|
110
|
+
return 2
|
|
111
|
+
fi
|
|
112
|
+
return 0
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
REPO_PATH="$scratch/reference"
|
|
116
|
+
git init --quiet "$REPO_PATH" &&
|
|
117
|
+
git -C "$REPO_PATH" fetch --quiet --depth 1 -- \
|
|
118
|
+
https://github.com/google-deepmind/formal-quantum-computation.git "$REPO_REF" &&
|
|
119
|
+
git -C "$REPO_PATH" checkout --quiet --detach FETCH_HEAD || return 2
|
|
120
|
+
if ! command -v lake >/dev/null; then
|
|
121
|
+
curl -fsSLo "$scratch/elan-init.sh" \
|
|
122
|
+
https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh &&
|
|
123
|
+
sh "$scratch/elan-init.sh" -y --no-modify-path --default-toolchain none || return 2
|
|
124
|
+
fi
|
|
125
|
+
(cd "$REPO_PATH" && lake exe cache get && lake build QuantumComputation) || return 2
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
run_verifier() {
|
|
129
|
+
local target
|
|
130
|
+
local -a args=(--repo="$REPO_PATH" --cert="$CERT_OUT")
|
|
131
|
+
if [[ -n "$MODE" ]]; then args+=(--mode="$MODE"); fi
|
|
132
|
+
if [[ -n "$DOCKER_IMAGE" ]]; then args+=(--docker-image="$DOCKER_IMAGE"); fi
|
|
133
|
+
case "$REQUIRE_SANDBOX" in
|
|
134
|
+
true) args+=(--require-sandbox) ;;
|
|
135
|
+
false) ;;
|
|
136
|
+
*) printf 'require-sandbox must be true or false\n' >&2; return 2 ;;
|
|
137
|
+
esac
|
|
138
|
+
while IFS= read -r target; do
|
|
139
|
+
target="${target#"${target%%[![:space:]]*}"}"
|
|
140
|
+
target="${target%"${target##*[![:space:]]}"}"
|
|
141
|
+
if [[ -n "$target" ]]; then args+=(--target="$target"); fi
|
|
142
|
+
done <<< "${TARGETS//,/$'\n'}"
|
|
143
|
+
qcert verify "${args[@]}" -- "$LEAN_FILE"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
EXIT_CODE=2
|
|
147
|
+
receipt="$CERT_OUT"
|
|
148
|
+
if ! clear_certificate; then
|
|
149
|
+
printf 'Could not clear the certificate destination: %s\n' "$CERT_OUT" >&2
|
|
150
|
+
# An uncleared destination must never be read as the receipt for this run.
|
|
151
|
+
receipt=""
|
|
152
|
+
fi
|
|
153
|
+
scratch=$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/qcert-action.XXXXXXXX")
|
|
154
|
+
trap 'rm -rf -- "$scratch"' EXIT
|
|
155
|
+
if [[ -z "$receipt" ]]; then
|
|
156
|
+
receipt="$scratch/missing-receipt.json"
|
|
157
|
+
elif mkdir -p -- "$(dirname -- "$CERT_OUT")" && prepare_reference; then
|
|
158
|
+
EXIT_CODE=0
|
|
159
|
+
run_verifier || EXIT_CODE=$?
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
python -B -P -m qcert.reporting --cert "$receipt" --exit-code "$EXIT_CODE" \
|
|
163
|
+
--badge-out "$BADGE_OUT" --badge-url="$BADGE_URL" --summary-out "$SUMMARY_OUT" \
|
|
164
|
+
--github-step-summary "$GITHUB_STEP_SUMMARY" --github-output "$GITHUB_OUTPUT" ||
|
|
165
|
+
printf '::error::Could not write qcert verification reports\n' >&2
|
|
166
|
+
exit "$EXIT_CODE"
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
name: qcert composite action test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
action-test:
|
|
13
|
+
runs-on: ubuntu-24.04
|
|
14
|
+
env:
|
|
15
|
+
QCERT_SANDBOX_IMAGE: qcert-bwrap-lean435:v4.35.0
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
persist-credentials: false
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- name: Check out the pinned Lean reference
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
with:
|
|
26
|
+
repository: google-deepmind/formal-quantum-computation
|
|
27
|
+
ref: a88de8ff65d78af564b2373088ca369dc95f6547
|
|
28
|
+
path: formal-quantum-computation
|
|
29
|
+
persist-credentials: false
|
|
30
|
+
- name: Build the Lean reference
|
|
31
|
+
working-directory: formal-quantum-computation
|
|
32
|
+
run: |
|
|
33
|
+
curl -fsSLo "$RUNNER_TEMP/elan-init.sh" \
|
|
34
|
+
https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh
|
|
35
|
+
sh "$RUNNER_TEMP/elan-init.sh" -y --no-modify-path --default-toolchain none
|
|
36
|
+
export PATH="$HOME/.elan/bin:$PATH"
|
|
37
|
+
elan toolchain install "$(cat lean-toolchain)"
|
|
38
|
+
lake exe cache get
|
|
39
|
+
lake build QuantumComputation
|
|
40
|
+
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
|
|
41
|
+
- name: Build the sandbox image
|
|
42
|
+
run: docker build -f docker/Dockerfile.bwrap-lean435 -t "$QCERT_SANDBOX_IMAGE" docker
|
|
43
|
+
|
|
44
|
+
- name: Verify a valid Lean file
|
|
45
|
+
id: verified
|
|
46
|
+
uses: ./.github/actions/qcert-action
|
|
47
|
+
with:
|
|
48
|
+
lean-file: tests/fixtures/valid_no_print.lean
|
|
49
|
+
repo-path: formal-quantum-computation
|
|
50
|
+
docker-image: ${{ env.QCERT_SANDBOX_IMAGE }}
|
|
51
|
+
targets: arithmetic
|
|
52
|
+
badge-url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
53
|
+
cert-out: reports/verified.json
|
|
54
|
+
badge-out: reports/verified.svg
|
|
55
|
+
summary-out: reports/verified.md
|
|
56
|
+
|
|
57
|
+
- name: Reject an unsound Lean file
|
|
58
|
+
id: rejected
|
|
59
|
+
continue-on-error: true
|
|
60
|
+
uses: ./.github/actions/qcert-action
|
|
61
|
+
with:
|
|
62
|
+
lean-file: tests/fixtures/unsound_sorry.lean
|
|
63
|
+
repo-path: formal-quantum-computation
|
|
64
|
+
mode: local
|
|
65
|
+
require-sandbox: "false"
|
|
66
|
+
cert-out: reports/rejected.json
|
|
67
|
+
badge-out: reports/rejected.svg
|
|
68
|
+
summary-out: reports/rejected.md
|
|
69
|
+
|
|
70
|
+
- name: Reject a reference SHA mismatch
|
|
71
|
+
id: mismatch
|
|
72
|
+
continue-on-error: true
|
|
73
|
+
uses: ./.github/actions/qcert-action
|
|
74
|
+
with:
|
|
75
|
+
lean-file: tests/fixtures/valid_no_print.lean
|
|
76
|
+
repo-path: formal-quantum-computation
|
|
77
|
+
repo-ref: "0000000000000000000000000000000000000000"
|
|
78
|
+
cert-out: reports/mismatch.json
|
|
79
|
+
badge-out: reports/mismatch.svg
|
|
80
|
+
summary-out: reports/mismatch.md
|
|
81
|
+
|
|
82
|
+
- name: Seed the missing-file case with a previous green receipt
|
|
83
|
+
run: cp reports/verified.json reports/missing.json
|
|
84
|
+
- name: Report a missing Lean file
|
|
85
|
+
id: missing
|
|
86
|
+
continue-on-error: true
|
|
87
|
+
uses: ./.github/actions/qcert-action
|
|
88
|
+
with:
|
|
89
|
+
lean-file: tests/fixtures/missing.lean
|
|
90
|
+
repo-path: formal-quantum-computation
|
|
91
|
+
cert-out: reports/missing.json
|
|
92
|
+
badge-out: reports/missing.svg
|
|
93
|
+
summary-out: reports/missing.md
|
|
94
|
+
|
|
95
|
+
- name: Check action outcomes and artifacts
|
|
96
|
+
env:
|
|
97
|
+
VERIFIED: ${{ steps.verified.outputs.exit-code }}
|
|
98
|
+
VERIFIED_AUTHORITATIVE: ${{ steps.verified.outputs.authoritative }}
|
|
99
|
+
REJECTED: ${{ steps.rejected.outcome }}:${{ steps.rejected.outputs.exit-code }}
|
|
100
|
+
MISMATCH: ${{ steps.mismatch.outcome }}:${{ steps.mismatch.outputs.exit-code }}
|
|
101
|
+
MISSING: ${{ steps.missing.outcome }}:${{ steps.missing.outputs.exit-code }}
|
|
102
|
+
MISSING_STATUS: ${{ steps.missing.outputs.status }}
|
|
103
|
+
MISSING_AUTHORITATIVE: ${{ steps.missing.outputs.authoritative }}
|
|
104
|
+
run: |
|
|
105
|
+
test "$VERIFIED" = 0
|
|
106
|
+
test "$VERIFIED_AUTHORITATIVE" = true
|
|
107
|
+
test "$REJECTED" = failure:1
|
|
108
|
+
test "$MISMATCH" = failure:2
|
|
109
|
+
test "$MISSING" = failure:2
|
|
110
|
+
test "$MISSING_STATUS" = INVALID_INPUT
|
|
111
|
+
test "$MISSING_AUTHORITATIVE" = false
|
|
112
|
+
grep -Fq '#2da44e' reports/verified.svg
|
|
113
|
+
grep -Fq '#cf222e' reports/rejected.svg
|
|
114
|
+
grep -Fq '#6e7781' reports/mismatch.svg
|
|
115
|
+
grep -Fq '#6e7781' reports/missing.svg
|
|
116
|
+
test ! -e reports/mismatch.json
|
|
117
|
+
python -c 'import json; from pathlib import Path; result = json.loads(Path("reports/missing.json").read_bytes()); assert result["exit_code"] == 2 and result["authoritative"] is False'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
name: qcert CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
verify:
|
|
13
|
+
runs-on: ubuntu-24.04
|
|
14
|
+
env:
|
|
15
|
+
QCERT_SANDBOX_IMAGE: qcert-bwrap-lean435:v4.35.0
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
- name: Install qcert and test dependencies
|
|
22
|
+
run: python -m pip install -e ".[dev,qiskit,cirq]"
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: ruff check qcert tests
|
|
25
|
+
|
|
26
|
+
- name: Check out the pinned Lean reference
|
|
27
|
+
uses: actions/checkout@v4
|
|
28
|
+
with:
|
|
29
|
+
repository: google-deepmind/formal-quantum-computation
|
|
30
|
+
ref: a88de8ff65d78af564b2373088ca369dc95f6547
|
|
31
|
+
path: formal-quantum-computation
|
|
32
|
+
persist-credentials: false
|
|
33
|
+
- name: Install elan
|
|
34
|
+
run: |
|
|
35
|
+
curl -fsSLo "$RUNNER_TEMP/elan-init.sh" https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh
|
|
36
|
+
sh "$RUNNER_TEMP/elan-init.sh" -y --no-modify-path --default-toolchain none
|
|
37
|
+
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
|
|
38
|
+
- name: Build the Lean reference
|
|
39
|
+
working-directory: formal-quantum-computation
|
|
40
|
+
run: |
|
|
41
|
+
elan toolchain install "$(cat lean-toolchain)"
|
|
42
|
+
lake exe cache get
|
|
43
|
+
lake build QuantumComputation
|
|
44
|
+
# Cached imports can be owner-readable only. The replay sandbox reads
|
|
45
|
+
# these libraries through a read-only mount in a separate user namespace.
|
|
46
|
+
chmod -R a+rX .lake/build/lib/lean .lake/packages/*/.lake/build/lib/lean
|
|
47
|
+
- name: Build the Linux kernel replay image
|
|
48
|
+
run: docker build -f docker/Dockerfile.bwrap-lean435 -t "$QCERT_SANDBOX_IMAGE" docker
|
|
49
|
+
|
|
50
|
+
- name: Run the integration suite
|
|
51
|
+
env:
|
|
52
|
+
QCERT_FQC_REPO: ${{ github.workspace }}/formal-quantum-computation
|
|
53
|
+
run: pytest -q --require-live-lean
|
|
54
|
+
|
|
55
|
+
- name: Check CLI exit codes and sandboxed replay of an upstream import
|
|
56
|
+
env:
|
|
57
|
+
QCERT_FQC_REPO: ${{ github.workspace }}/formal-quantum-computation
|
|
58
|
+
run: |
|
|
59
|
+
expect_exit() {
|
|
60
|
+
local expected="$1" actual=0
|
|
61
|
+
shift
|
|
62
|
+
"$@" || actual=$?
|
|
63
|
+
test "$actual" -eq "$expected"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for fixture in valid_no_print valid_def_only; do
|
|
67
|
+
expect_exit 0 qcert verify "tests/fixtures/$fixture.lean" --repo "$QCERT_FQC_REPO" --mode local
|
|
68
|
+
done
|
|
69
|
+
for fixture in unsound_sorry unused_local_axiom private_local_axiom custom_axiom_silent bad_syntax; do
|
|
70
|
+
expect_exit 1 qcert verify "tests/fixtures/$fixture.lean" --repo "$QCERT_FQC_REPO" --mode local
|
|
71
|
+
done
|
|
72
|
+
expect_exit 2 qcert verify tests/fixtures/missing.lean --repo "$QCERT_FQC_REPO" --mode local
|
|
73
|
+
|
|
74
|
+
candidate="$(mktemp --suffix=.lean)"
|
|
75
|
+
trap 'rm -f "$candidate"' EXIT
|
|
76
|
+
cat > "$candidate" <<'LEAN'
|
|
77
|
+
import QuantumComputation.Circuits.Basic
|
|
78
|
+
open Operator
|
|
79
|
+
|
|
80
|
+
theorem import_control (c : Circuit 1) : c = c := rfl
|
|
81
|
+
LEAN
|
|
82
|
+
qcert verify "$candidate" --repo "$QCERT_FQC_REPO" --require-sandbox \
|
|
83
|
+
--docker-image "$QCERT_SANDBOX_IMAGE" --target import_control
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
name: Lean 4.35 replay image
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ['v*']
|
|
7
|
+
paths:
|
|
8
|
+
- docker/Dockerfile.bwrap-lean435
|
|
9
|
+
- .github/workflows/docker-lean435.yml
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
inputs:
|
|
12
|
+
push:
|
|
13
|
+
description: Publish the verified images to GHCR
|
|
14
|
+
type: boolean
|
|
15
|
+
default: false
|
|
16
|
+
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
packages: write
|
|
20
|
+
|
|
21
|
+
defaults:
|
|
22
|
+
run:
|
|
23
|
+
shell: bash
|
|
24
|
+
|
|
25
|
+
env:
|
|
26
|
+
IMAGE: ghcr.io/${{ vars.QCERT_GHCR_OWNER || github.repository_owner }}/qcert-bwrap-lean435
|
|
27
|
+
LOCAL_IMAGE: qcert-bwrap-lean435:v4.35.0
|
|
28
|
+
PUBLISH: ${{ github.event_name == 'push' || inputs.push }}
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
build-and-verify:
|
|
32
|
+
strategy:
|
|
33
|
+
matrix:
|
|
34
|
+
include:
|
|
35
|
+
- arch: amd64
|
|
36
|
+
platform: linux/amd64
|
|
37
|
+
runner: ubuntu-24.04
|
|
38
|
+
- arch: arm64
|
|
39
|
+
platform: linux/arm64
|
|
40
|
+
runner: ubuntu-24.04-arm
|
|
41
|
+
runs-on: ${{ matrix.runner }}
|
|
42
|
+
env:
|
|
43
|
+
PLATFORM: ${{ matrix.platform }}
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v4
|
|
46
|
+
with:
|
|
47
|
+
persist-credentials: false
|
|
48
|
+
- uses: docker/setup-buildx-action@v3
|
|
49
|
+
|
|
50
|
+
# At runtime qcert mounts formal-quantum-computation read-only and reuses its .lake
|
|
51
|
+
# cache (0 GB extra local .lake cache). Hosted build storage and pulled image bytes
|
|
52
|
+
# are separate (913,632,968 bytes measured for the local arm64 image).
|
|
53
|
+
- name: Build and load the platform image
|
|
54
|
+
run: |
|
|
55
|
+
# The Docker archive contains an OCI layout alongside the Docker load metadata.
|
|
56
|
+
docker buildx build --platform "$PLATFORM" --tag "$LOCAL_IMAGE" \
|
|
57
|
+
--provenance=false --sbom=false \
|
|
58
|
+
--output "type=docker,oci-mediatypes=true,dest=$RUNNER_TEMP/platform.tar" \
|
|
59
|
+
-f docker/Dockerfile.bwrap-lean435 docker/
|
|
60
|
+
docker image load --input "$RUNNER_TEMP/platform.tar"
|
|
61
|
+
|
|
62
|
+
- name: Match the OCI manifest to the local image and run preflight
|
|
63
|
+
run: |
|
|
64
|
+
archive="$RUNNER_TEMP/platform.tar"
|
|
65
|
+
digest=$(tar -xOf "$archive" index.json | jq -er '
|
|
66
|
+
.manifests | select(length == 1) | .[0] |
|
|
67
|
+
select(.mediaType == "application/vnd.oci.image.manifest.v1+json") | .digest
|
|
68
|
+
')
|
|
69
|
+
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
|
|
70
|
+
config=$(tar -xOf "$archive" "blobs/sha256/${digest#sha256:}" | jq -er '.config.digest')
|
|
71
|
+
image_id=$(docker image inspect --format '{{.Id}}' "$LOCAL_IMAGE")
|
|
72
|
+
# Docker's classic store reports the config digest and containerd reports the manifest.
|
|
73
|
+
[[ "$image_id" == "$config" || "$image_id" == "$digest" ]]
|
|
74
|
+
test "$(docker image inspect --format '{{.Os}}/{{.Architecture}}' "$image_id")" = "$PLATFORM"
|
|
75
|
+
IMAGE_ID="$image_id" python3 - <<'PY'
|
|
76
|
+
import os
|
|
77
|
+
from qcert.verifier.runner import check_linux_bwrap_preflight
|
|
78
|
+
|
|
79
|
+
preflight = check_linux_bwrap_preflight(docker_image=os.environ["IMAGE_ID"])
|
|
80
|
+
assert preflight.exit_code == 0, preflight.stderr
|
|
81
|
+
PY
|
|
82
|
+
printf '%s\n' "$digest" > "$RUNNER_TEMP/digest.txt"
|
|
83
|
+
|
|
84
|
+
- name: Push the tested platform by digest
|
|
85
|
+
if: env.PUBLISH == 'true'
|
|
86
|
+
env:
|
|
87
|
+
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
88
|
+
run: |
|
|
89
|
+
sudo apt-get update
|
|
90
|
+
sudo apt-get install -y skopeo
|
|
91
|
+
printf '%s' "$GHCR_TOKEN" | skopeo login --username "$GITHUB_ACTOR" --password-stdin ghcr.io
|
|
92
|
+
digest=$(cat "$RUNNER_TEMP/digest.txt")
|
|
93
|
+
skopeo copy --preserve-digests "oci-archive:$RUNNER_TEMP/platform.tar" \
|
|
94
|
+
"docker://${IMAGE,,}@$digest"
|
|
95
|
+
|
|
96
|
+
- uses: actions/upload-artifact@v4
|
|
97
|
+
with:
|
|
98
|
+
name: tested-digest-${{ matrix.arch }}
|
|
99
|
+
path: ${{ runner.temp }}/digest.txt
|
|
100
|
+
if-no-files-found: error
|
|
101
|
+
overwrite: true
|
|
102
|
+
|
|
103
|
+
publish-manifest:
|
|
104
|
+
needs: build-and-verify
|
|
105
|
+
if: github.event_name == 'push' || inputs.push
|
|
106
|
+
runs-on: ubuntu-24.04
|
|
107
|
+
concurrency:
|
|
108
|
+
group: docker-lean435-manifest
|
|
109
|
+
cancel-in-progress: false
|
|
110
|
+
steps:
|
|
111
|
+
- uses: docker/setup-buildx-action@v3
|
|
112
|
+
- uses: docker/login-action@v3
|
|
113
|
+
with:
|
|
114
|
+
registry: ghcr.io
|
|
115
|
+
username: ${{ github.actor }}
|
|
116
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
117
|
+
- uses: actions/download-artifact@v4
|
|
118
|
+
with:
|
|
119
|
+
pattern: tested-digest-*
|
|
120
|
+
path: digests
|
|
121
|
+
- name: Assemble and verify the published manifest
|
|
122
|
+
run: |
|
|
123
|
+
image=${IMAGE,,}
|
|
124
|
+
amd64=$(cat digests/tested-digest-amd64/digest.txt)
|
|
125
|
+
arm64=$(cat digests/tested-digest-arm64/digest.txt)
|
|
126
|
+
[[ "$amd64" =~ ^sha256:[0-9a-f]{64}$ ]]
|
|
127
|
+
[[ "$arm64" =~ ^sha256:[0-9a-f]{64}$ ]]
|
|
128
|
+
docker buildx imagetools create --tag "$image:v4.35.0" \
|
|
129
|
+
"$image@$amd64" "$image@$arm64"
|
|
130
|
+
docker buildx imagetools inspect --raw "$image:v4.35.0" | \
|
|
131
|
+
jq -e --arg amd64 "$amd64" --arg arm64 "$arm64" '
|
|
132
|
+
[.manifests[] | {digest, os: .platform.os, arch: .platform.architecture}]
|
|
133
|
+
| sort_by(.arch) == [
|
|
134
|
+
{digest: $amd64, os: "linux", arch: "amd64"},
|
|
135
|
+
{digest: $arm64, os: "linux", arch: "arm64"}
|
|
136
|
+
]
|
|
137
|
+
'
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
name: Publish qcert to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
inputs:
|
|
8
|
+
dry_run:
|
|
9
|
+
description: Build and smoke-test the distributions. Manual runs never publish.
|
|
10
|
+
type: boolean
|
|
11
|
+
default: true
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build-and-smoke:
|
|
18
|
+
runs-on: ubuntu-24.04
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
persist-credentials: false
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.12"
|
|
26
|
+
- uses: astral-sh/setup-uv@v6
|
|
27
|
+
- name: Build and inspect distributions
|
|
28
|
+
run: |
|
|
29
|
+
uv build
|
|
30
|
+
python tests/test_packaging.py dist
|
|
31
|
+
- name: Smoke-test the installed wheel from an empty directory
|
|
32
|
+
shell: bash
|
|
33
|
+
run: |
|
|
34
|
+
wheel=( "$PWD"/dist/qcert-*.whl )
|
|
35
|
+
test "${#wheel[@]}" -eq 1
|
|
36
|
+
venv="$(mktemp -d)"
|
|
37
|
+
smoke="$(mktemp -d)"
|
|
38
|
+
trap 'rm -rf "$venv" "$smoke"' EXIT
|
|
39
|
+
|
|
40
|
+
unset PYTHONPATH PYTHONHOME
|
|
41
|
+
python -m venv "$venv"
|
|
42
|
+
"$venv/bin/python" -m pip install --no-index "${wheel[0]}"
|
|
43
|
+
export PATH="$venv/bin:$PATH"
|
|
44
|
+
cd "$smoke"
|
|
45
|
+
test "$(which qcert)" = "$venv/bin/qcert"
|
|
46
|
+
|
|
47
|
+
qcert --help
|
|
48
|
+
qcert demo rus --budget 3 --cost-per-attempt 1
|
|
49
|
+
cat > bell.qasm <<'QASM'
|
|
50
|
+
OPENQASM 3.0;
|
|
51
|
+
include "stdgates.inc";
|
|
52
|
+
qubit[2] q;
|
|
53
|
+
h q[0];
|
|
54
|
+
cx q[0], q[1];
|
|
55
|
+
QASM
|
|
56
|
+
qcert transpile bell.qasm -o Bell.lean --namespace Bell
|
|
57
|
+
test -s Bell.lean
|
|
58
|
+
- uses: actions/upload-artifact@v4
|
|
59
|
+
with:
|
|
60
|
+
name: qcert-distributions
|
|
61
|
+
path: dist/
|
|
62
|
+
if-no-files-found: error
|
|
63
|
+
|
|
64
|
+
publish-pypi:
|
|
65
|
+
if: github.event_name == 'release'
|
|
66
|
+
needs: [build-and-smoke]
|
|
67
|
+
runs-on: ubuntu-24.04
|
|
68
|
+
permissions:
|
|
69
|
+
id-token: write
|
|
70
|
+
environment:
|
|
71
|
+
name: pypi
|
|
72
|
+
steps:
|
|
73
|
+
- uses: actions/download-artifact@v4
|
|
74
|
+
with:
|
|
75
|
+
name: qcert-distributions
|
|
76
|
+
path: dist/
|
|
77
|
+
# Register this binding on PyPI (as a pending publisher for the first release).
|
|
78
|
+
# project: qcert
|
|
79
|
+
# repository: gouthamaenugu/qcert
|
|
80
|
+
# workflow: publish-pypi.yml
|
|
81
|
+
# environment: pypi
|
|
82
|
+
- name: Check the release matches the Trusted Publisher binding
|
|
83
|
+
shell: bash
|
|
84
|
+
run: |
|
|
85
|
+
test "$GITHUB_REPOSITORY" = "gouthamaenugu/qcert"
|
|
86
|
+
test "${GITHUB_WORKFLOW_REF%@*}" = "$GITHUB_REPOSITORY/.github/workflows/publish-pypi.yml"
|
|
87
|
+
[[ "$GITHUB_REF" == refs/tags/v* ]]
|
|
88
|
+
version="${GITHUB_REF#refs/tags/v}"
|
|
89
|
+
test -f "dist/qcert-$version.tar.gz"
|
|
90
|
+
test -f "dist/qcert-$version-py3-none-any.whl"
|
|
91
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
qcert-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# qcert v0.1.0 launch drafts
|
|
2
|
+
|
|
3
|
+
## Show HN
|
|
4
|
+
|
|
5
|
+
**Show HN: qcert, a bridge from OpenQASM circuits to DeepMind's Lean library**
|
|
6
|
+
|
|
7
|
+
I built qcert to take a small circuit I already have and produce a Lean
|
|
8
|
+
module I can inspect and check. The Apache-2.0 Python core has zero runtime
|
|
9
|
+
dependencies. It takes supported OpenQASM 3 circuits, and optional Python
|
|
10
|
+
adapters let you import and export supported Qiskit and Cirq circuits. A
|
|
11
|
+
strict static extractor takes supported Lean circuits back to OpenQASM 3.
|
|
12
|
+
`qcert extract --discoveries` inspects supported discovery files at a pinned
|
|
13
|
+
DeepMind commit.
|
|
14
|
+
|
|
15
|
+
The verifier captures an immutable input snapshot and emits a receipt for
|
|
16
|
+
Lean v4.35.0. `qcert verify --docker` runs isolated Linux kernel replay
|
|
17
|
+
(`SANDBOXED_KERNEL_REPLAY`). The local option reports
|
|
18
|
+
`LOCAL_ELABORATION_AUDIT`, with `authoritative=false`.
|
|
19
|
+
|
|
20
|
+
The quickest thing to try is `qcert demo rus --budget 3 --cost-per-attempt 1`.
|
|
21
|
+
The model is a 5/8 success coin with one unit of cost per attempt. The
|
|
22
|
+
over-budget probability is exactly 27/512. The `equal-mean`, `correlated`,
|
|
23
|
+
and `rus` demos are calibration cases. Evaluation benchmarks are
|
|
24
|
+
pre-registered and held-out results remain unreported.
|
|
25
|
+
|
|
26
|
+
I'd like to hear where the supported circuit syntax gets in your way.
|
|
27
|
+
|
|
28
|
+
https://github.com/gouthamaenugu/qcert
|
|
29
|
+
|
|
30
|
+
## r/QuantumComputing
|
|
31
|
+
|
|
32
|
+
**qcert v0.1.0 for trying small OpenQASM circuits in Lean**
|
|
33
|
+
|
|
34
|
+
If you have a small circuit in OpenQASM 3, qcert can generate a Lean module
|
|
35
|
+
for DeepMind's `formal-quantum-computation` library on Lean v4.35.0. The
|
|
36
|
+
Qiskit and Cirq adapters are optional, and the Apache-2.0 Python core has zero
|
|
37
|
+
runtime dependencies. For supported static Lean circuits, extraction
|
|
38
|
+
produces OpenQASM 3 and a resource audit. Discovery inspection reads from
|
|
39
|
+
a pinned upstream commit.
|
|
40
|
+
|
|
41
|
+
I included three exact rational tail-risk demos, `equal-mean`,
|
|
42
|
+
`correlated`, and `rus`. For RUS, each independent attempt is a 5/8
|
|
43
|
+
success coin. At unit cost per attempt and budget 3, exceeding the budget
|
|
44
|
+
means all three attempts failed, which has probability 27/512. These are
|
|
45
|
+
calibration examples. The evaluation benchmarks are pre-registered, with
|
|
46
|
+
held-out results still unreported.
|
|
47
|
+
|
|
48
|
+
The verifier checks an immutable source snapshot. Use
|
|
49
|
+
`qcert verify --docker` for the Linux `SANDBOXED_KERNEL_REPLAY` tier or
|
|
50
|
+
`qcert verify --mode local` for a `LOCAL_ELABORATION_AUDIT`.
|
|
51
|
+
|
|
52
|
+
If you try a small circuit, I'd be interested in which gates or control
|
|
53
|
+
constructs you need next.
|
|
54
|
+
|
|
55
|
+
https://github.com/gouthamaenugu/qcert
|
|
56
|
+
|
|
57
|
+
## Lean Zulip (`#announce` or `#quantum`)
|
|
58
|
+
|
|
59
|
+
**qcert v0.1.0 for `formal-quantum-computation` on Lean v4.35.0**
|
|
60
|
+
|
|
61
|
+
I've put together an Apache-2.0 tool that lowers supported OpenQASM 3
|
|
62
|
+
circuits into modules for DeepMind's `formal-quantum-computation` library.
|
|
63
|
+
The Python core has zero runtime dependencies, with optional Qiskit and
|
|
64
|
+
Cirq adapters. The strict static extractor emits OpenQASM 3 from supported
|
|
65
|
+
`Circuit n` definitions and can inspect discovery files at a pinned commit.
|
|
66
|
+
|
|
67
|
+
The verifier uses an immutable input snapshot. A successful
|
|
68
|
+
`qcert verify --docker` run records `SANDBOXED_KERNEL_REPLAY` and
|
|
69
|
+
`authoritative=true` after Linux `bwrap` isolation and
|
|
70
|
+
`leanexport`/`leanchecker` replay. Local mode reports
|
|
71
|
+
`LOCAL_ELABORATION_AUDIT` with `authoritative=false`.
|
|
72
|
+
|
|
73
|
+
The `equal-mean`, `correlated`, and one-dimensional 5/8 RUS coin examples
|
|
74
|
+
are exact rational calibration cases. The evaluation benchmarks are
|
|
75
|
+
pre-registered and held-out results remain unreported.
|
|
76
|
+
|
|
77
|
+
Feedback on the declaration audit and replay receipt would be welcome.
|
|
78
|
+
|
|
79
|
+
https://github.com/gouthamaenugu/qcert
|