Skip to content

Commit 134fb94

Browse files
authored
Support for Coq 8.20 (#63)
1 parent 9081860 commit 134fb94

File tree

8 files changed

+69
-56
lines changed

8 files changed

+69
-56
lines changed

.github/workflows/coq-action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
- '8.16'
1616
- '8.17'
1717
- '8.18'
18+
- '8.19'
19+
- '8.20'
1820
ocaml_version:
1921
- 'default'
2022
fail-fast: false # don't stop jobs if one fails
@@ -33,6 +35,8 @@ jobs:
3335
- '8.16'
3436
- '8.17'
3537
- '8.18'
38+
- '8.19'
39+
- '8.20'
3640
ocaml_version:
3741
- 'default'
3842
fail-fast: false # don't stop jobs if one fails

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ If you are interested in learning more about formal verification of quantum prog
2828

2929
## Setup
3030

31-
To compile SQIR and VOQC, you will need [Coq](https://coq.inria.fr/) and [QuantumLib](https://github.com/inQWIRE/QuantumLib) (version 1.1.0). In order to build the Shor proof, you will also need the [Coq Interval package](http://coq-interval.gforge.inria.fr/) and the [coq-euler](https://github.com/taorunz/euler) library. We strongly recommend using [opam](https://opam.ocaml.org/doc/Install.html) to install Coq and `opam switch` to manage Coq versions. We currently support Coq **versions 8.12-8.16**. If you run into errors when compiling our proofs, first check your version of Coq (`coqc -v`).
31+
To compile SQIR and VOQC, you will need [Coq](https://coq.inria.fr/) and [QuantumLib](https://github.com/inQWIRE/QuantumLib) (version 1.7.0). In order to build the Shor proof, you will also need the [Coq Interval package](http://coq-interval.gforge.inria.fr/) and the [coq-euler](https://github.com/taorunz/euler) library. We strongly recommend using [opam](https://opam.ocaml.org/doc/Install.html) to install Coq and `opam switch` to manage Coq versions. We currently support Coq **versions 8.16-8.20**. If you run into errors when compiling our proofs, first check your version of Coq (`coqc -v`).
3232

3333
Assuming you have opam installed (following the instructions in the link above), follow the steps below to set up your environment.
3434
```
@@ -46,7 +46,7 @@ opam install coq
4646
# install the QuantumLib library
4747
opam repo add coq-released https://coq.inria.fr/opam/released
4848
opam update
49-
opam install coq-quantumlib.1.1.0
49+
opam install coq-quantumlib.1.7.0
5050
5151
# Optional, if you want to compile the proofs in examples/shor
5252
opam install coq-interval
@@ -55,7 +55,7 @@ opam pin coq-euler https://github.com/taorunz/euler.git
5555

5656
*Notes*:
5757
* Depending on your system, you may need to replace 4.13.1 in the instructions above with something like "ocaml-base-compiler.4.13.1". Any recent version of OCaml should be fine.
58-
* We require Coq version >= 8.12.
58+
* We require Coq version >= 8.16.
5959
* opam error messages and warnings are typically informative, so if you run into trouble then make sure you read the console output.
6060

6161
## Compilation

VOQC/ConnectivityGraph.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ Proof.
11581158
rewrite (Nat.mul_comm (n1 / numCols)).
11591159
rewrite (Nat.mul_comm (n2 / numCols)).
11601160
assert (numCols * (n1 / numCols) < numCols * (n2 / numCols)).
1161-
{ apply mult_lt_compat_l; assumption. }
1161+
{ nia. }
11621162
remember (numCols * (n1 / numCols)) as x.
11631163
remember (numCols * (n2 / numCols)) as y.
11641164
clear - Haux1 Haux2 H1 H2.
@@ -1183,7 +1183,7 @@ Proof.
11831183
rewrite (Nat.mul_comm (n1 / numCols)).
11841184
rewrite (Nat.mul_comm (n2 / numCols)).
11851185
assert (numCols * (n1 / numCols) <= numCols * (n2 / numCols)).
1186-
{ apply mult_le_compat_l; lia. }
1186+
{ nia. }
11871187
remember (numCols * (n1 / numCols)) as x.
11881188
remember (numCols * (n2 / numCols)) as y.
11891189
clear - Haux1 Haux2 H2 H3.
@@ -1202,7 +1202,7 @@ Proof.
12021202
rewrite (Nat.mul_comm (n1 / numCols)).
12031203
rewrite (Nat.mul_comm (n2 / numCols)).
12041204
assert (numCols * (n1 / numCols) < numCols * (n2 / numCols)).
1205-
{ apply mult_lt_compat_l; assumption. }
1205+
{ nia. }
12061206
remember (numCols * (n1 / numCols)) as x.
12071207
remember (numCols * (n2 / numCols)) as y.
12081208
clear - Haux1 Haux2 H1 H4.
@@ -1223,7 +1223,7 @@ Proof.
12231223
(* In Coq v8.10, the goal is solved by the previous line. *)
12241224
try (rewrite Nat.add_sub_assoc; try assumption;
12251225
assert (numCols * (n2 / numCols) < numCols * (n1 / numCols));
1226-
[ apply mult_lt_compat_l; assumption
1226+
[ nia
12271227
| remember (numCols * (n1 / numCols)) as x;
12281228
remember (numCols * (n2 / numCols)) as y;
12291229
clear - Haux1 Haux2 H0 H1;
@@ -1270,7 +1270,7 @@ Proof.
12701270
rewrite (Nat.mul_comm (n1 / numCols)).
12711271
rewrite (Nat.mul_comm (n2 / numCols)).
12721272
assert (numCols * (n2 / numCols) <= numCols * (n1 / numCols)).
1273-
{ apply mult_le_compat_l; lia. }
1273+
{ nia. }
12741274
remember (numCols * (n1 / numCols)) as x.
12751275
remember (numCols * (n2 / numCols)) as y.
12761276
clear - Haux1 Haux2 H1 H2.

VOQC/Main.v

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,13 @@ Proof.
997997
contradiction.
998998
Qed.
999999

1000+
Section with_permutations.
1001+
1002+
Import Permutations.
1003+
1004+
Local Hint Resolve get_phys_perm get_log_perm : perm_db.
1005+
1006+
10001007
Lemma check_swap_equivalence_correct : forall dim (c1 c2 : circ dim) (lay1 lay2 : layout),
10011008
uc_well_typed_l c1 ->
10021009
uc_well_typed_l c2 ->
@@ -1013,21 +1020,23 @@ Proof.
10131020
(fun n : nat => MappingGateSet.match_gate match_gate)) eqn:mv.
10141021
assert (mvWF:=mv).
10151022
destruct p.
1016-
2: inversion H.
1017-
apply MVP.check_swap_equivalence_implies_equivalence in mv;
1018-
auto using full_to_map_WT.
1019-
apply MVP.check_swap_equivalence_layouts_WF in mvWF as [? ?];
1020-
auto using full_to_map_WT.
1023+
2: { inversion H. }
1024+
apply MVP.check_swap_equivalence_implies_equivalence in mv;
1025+
[|solve [auto using full_to_map_WT]..].
1026+
apply MVP.check_swap_equivalence_layouts_WF in mvWF as [? ?];
1027+
[|solve [auto using full_to_map_WT]..].
10211028
unfold MVP.SRP.uc_equiv_perm_ex in mv.
10221029
exists (get_phys lay1 ∘ get_log lay2)%prg.
10231030
exists (get_phys l0 ∘ get_log l)%prg.
1024-
repeat split; [auto with perm_db..|].
1031+
repeat split; [PermutationAutomation.auto_perm..|].
10251032
unfold eval.
10261033
unfold MVP.SRP.MapList.eval in mv.
10271034
rewrite <- 2 list_to_ucom_full_to_map in mv.
10281035
apply mv.
10291036
Qed.
10301037

1038+
End with_permutations.
1039+
10311040
Lemma check_constraints_correct : forall dim (c : circ dim) (cg : c_graph),
10321041
check_constraints c cg = true ->
10331042
respects_constraints_directed (is_in_graph cg) MappingGateSet.UMap_CNOT (full_to_map c).

VOQC/MappingValidation.v

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ Module MappingValidationProofs (G : GateSet).
114114
Module SRP := SwapRouteProofs G.
115115
Import SRP.
116116

117+
Local Hint Resolve get_phys_perm get_log_perm : perm_db.
118+
117119
Lemma remove_swaps'_sound : forall {dim} (l l' : ucom_l dim) m m' acc,
118120
uc_well_typed_l l ->
119121
layout_bijective dim m ->
@@ -165,7 +167,7 @@ Proof.
165167
constructor.
166168
apply uc_well_typed_l_implies_dim_nonzero in WT.
167169
assumption.
168-
* apply IHl in H; auto with perm_db.
170+
* apply IHl in H; [|solve [auto using swap_log_preserves_bij with perm_db]..].
169171
destruct H as [l0 [? ?]].
170172
exists l0. subst. split; auto.
171173
rewrite (cons_to_app _ l).
@@ -183,7 +185,8 @@ Proof.
183185
repeat rewrite Mmult_assoc.
184186
rewrite f_to_vec_SWAP by assumption.
185187
Msimpl.
186-
rewrite perm_to_matrix_permutes_qubits by auto with perm_db.
188+
rewrite perm_to_matrix_permutes_qubits
189+
by auto using swap_log_preserves_bij with perm_db.
187190
apply f_to_vec_eq.
188191
intros x Hx.
189192
rewrite fswap_swap_log with (dim:=dim) by assumption.
@@ -256,6 +259,7 @@ Proof.
256259
apply remove_swaps_WF in rs2; auto.
257260
Qed.
258261

262+
259263
(** If check_swap_equivalence returns Some then l1 and l2 are equivalent programs
260264
wrt to layouts m1 and m2. *)
261265
Lemma check_swap_equivalence_implies_equivalence : forall {dim} (l1 l2 : ucom_l dim) m1 m2 m1' m2',
@@ -275,22 +279,23 @@ Proof.
275279
apply remove_swaps'_bijective in rs1'; auto.
276280
apply remove_swaps'_bijective in rs2'; auto.
277281
destruct (equalb m m0 (fun n : nat => MapG.match_gate)) eqn:eq.
278-
inversion H; subst.
279-
apply MapList.equalb_correct in eq.
280-
unfold uc_equiv_perm_ex, MapList.eval in *.
281-
unfold MapList.uc_equiv_l, uc_equiv in *.
282-
rewrite rs1, rs2, eq.
283-
rewrite <- 2 perm_to_matrix_Mmult by auto with perm_db.
284-
repeat rewrite Mmult_assoc.
285-
apply f_equal2; try reflexivity.
286-
repeat rewrite <- Mmult_assoc.
287-
apply f_equal2; try reflexivity.
288-
rewrite perm_to_matrix_Mmult by auto with perm_db.
289-
repeat rewrite Mmult_assoc.
290-
rewrite perm_to_matrix_Mmult by auto with perm_db.
291-
rewrite 2 perm_to_matrix_I by eauto with perm_inv_db.
292-
Msimpl. reflexivity.
293-
inversion H.
282+
- inversion H; subst.
283+
apply MapList.equalb_correct in eq.
284+
unfold uc_equiv_perm_ex, MapList.eval in *.
285+
unfold MapList.uc_equiv_l, uc_equiv in *.
286+
rewrite rs1, rs2, eq.
287+
rewrite 2 perm_to_matrix_compose by auto_perm.
288+
repeat rewrite Mmult_assoc.
289+
apply f_equal2; try reflexivity.
290+
repeat rewrite <- Mmult_assoc.
291+
apply f_equal2; try reflexivity.
292+
rewrite <- perm_to_matrix_compose by auto_perm.
293+
repeat rewrite Mmult_assoc.
294+
rewrite <- perm_to_matrix_compose by auto_perm.
295+
rewrite 2 perm_to_matrix_I by
296+
(intros; apply get_log_phys_inv with (n:=dim); auto).
297+
Msimpl. reflexivity.
298+
- inversion H.
294299
Qed.
295300

296301
Lemma check_constraints_implies_respect_constraints : forall {dim} (l : ucom_l dim) is_in_graph,

VOQC/SwapRoute.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Proof.
170170
- apply equal_on_basis_states_implies_equal; auto with wf_db.
171171
intro f.
172172
repeat rewrite Mmult_assoc.
173-
rewrite perm_to_matrix_permutes_qubits by auto with perm_bounded_db.
173+
rewrite perm_to_matrix_permutes_qubits by auto_perm.
174174
assert (p2 n < dim).
175175
{ destruct H1 as [? H1].
176176
specialize (H1 n H5).
@@ -196,7 +196,7 @@ Proof.
196196
with (f_to_vec (dim - (n + 1)) (shift f0 (n + 1))).
197197
replace (dim - (n + 1)) with (dim - 1 - n) by lia.
198198
rewrite <- f_to_vec_split by auto.
199-
rewrite perm_to_matrix_permutes_qubits by auto with perm_bounded_db.
199+
rewrite perm_to_matrix_permutes_qubits by auto_perm.
200200
remember (update (fun x : nat => f (p1 x)) (p2 n) false) as f0'.
201201
replace (f_to_vec dim (fun x : nat => f0 (p1 x))) with (f_to_vec dim f0').
202202
rewrite (f_to_vec_split 0 dim (p2 n)) by auto.
@@ -223,7 +223,7 @@ Proof.
223223
with (f_to_vec (dim - (n + 1)) (shift f1 (n + 1))).
224224
replace (dim - (n + 1)) with (dim - 1 - n) by lia.
225225
rewrite <- f_to_vec_split by auto.
226-
rewrite perm_to_matrix_permutes_qubits by auto with perm_bounded_db.
226+
rewrite perm_to_matrix_permutes_qubits by auto_perm.
227227
remember (update (fun x : nat => f (p1 x)) (p2 n) true) as f1'.
228228
replace (f_to_vec dim (fun x : nat => f1 (p1 x))) with (f_to_vec dim f1').
229229
rewrite (f_to_vec_split 0 dim (p2 n)) by auto.
@@ -246,10 +246,10 @@ Proof.
246246
- apply equal_on_basis_states_implies_equal; auto with wf_db.
247247
intro f.
248248
repeat rewrite Mmult_assoc.
249-
rewrite perm_to_matrix_permutes_qubits by auto with perm_bounded_db.
249+
rewrite perm_to_matrix_permutes_qubits by auto_perm.
250250
replace (ueval_cnot dim n n0) with (uc_eval (@SQIR.CNOT dim n n0)) by reflexivity.
251251
rewrite f_to_vec_CNOT by assumption.
252-
rewrite perm_to_matrix_permutes_qubits by auto with perm_bounded_db.
252+
rewrite perm_to_matrix_permutes_qubits by auto_perm.
253253
replace (ueval_cnot dim (p2 n) (p2 n0))
254254
with (uc_eval (@SQIR.CNOT dim (p2 n) (p2 n0))) by reflexivity.
255255
assert (p2 n < dim).
@@ -303,7 +303,7 @@ Proof.
303303
unfold eval; simpl.
304304
rewrite denote_SKIP by assumption.
305305
Msimpl.
306-
rewrite perm_to_matrix_Mmult, perm_to_matrix_I; auto.
306+
rewrite <- perm_to_matrix_compose, perm_to_matrix_I; auto_perm.
307307
Qed.
308308

309309
Lemma SWAP_well_typed : forall dim a b,
@@ -505,7 +505,7 @@ Proof.
505505
rewrite (perm_to_matrix_I _ (p1inv ∘ p1)%prg).
506506
Msimpl.
507507
reflexivity.
508-
auto.
508+
unfold eval; auto with wf_db.
509509
Qed.
510510

511511
Lemma uc_equiv_perm_ex_app2 : forall {dim} (l1 l2 : ucom_l dim) (g : gate_app (Map_Unitary (G.U 1)) dim) p1 p2 p3,

VOQC/UnitaryListRepresentation.v

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,15 +1321,12 @@ Proof.
13211321
exists (perm_inv dim p2).
13221322
repeat split; auto with perm_db.
13231323
rewrite H.
1324-
rewrite <- !perm_to_matrix_transpose_eq by easy.
1325-
rewrite !Mmult_assoc.
1326-
restore_dims.
1327-
rewrite 2!perm_to_matrix_transpose_eq,
1328-
<- perm_to_matrix_compose by auto with perm_bounded_db.
1329-
rewrite <- !Mmult_assoc.
1330-
rewrite <- perm_to_matrix_compose by auto with perm_bounded_db.
1331-
rewrite 2!perm_to_matrix_I by (intros; cleanup_perm_inv).
1332-
now Msimpl.
1324+
repeat rewrite Mmult_assoc.
1325+
rewrite <- perm_to_matrix_compose by auto_perm.
1326+
repeat rewrite <- Mmult_assoc.
1327+
rewrite <- perm_to_matrix_compose by auto_perm.
1328+
rewrite 2 perm_to_matrix_I by (intros; cleanup_perm_inv).
1329+
unfold eval. Msimpl. reflexivity.
13331330
Qed.
13341331

13351332
Lemma uc_equiv_perm_trans : forall {dim} (l1 l2 l3 : gate_list G.U dim),
@@ -1342,10 +1339,8 @@ Proof.
13421339
rewrite H1, H2.
13431340
exists (p1 ∘ p3)%prg.
13441341
exists (p4 ∘ p2)%prg.
1345-
repeat split.
1346-
apply permutation_compose; auto.
1347-
apply permutation_compose; auto.
1348-
rewrite <- 2 perm_to_matrix_Mmult; auto with perm_bounded_db.
1342+
repeat split; [solve [auto using permutation_compose]..|].
1343+
rewrite 2 perm_to_matrix_compose; auto using permutation_is_bounded.
13491344
repeat rewrite Mmult_assoc.
13501345
reflexivity.
13511346
Qed.

dune-project

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(lang dune 3.8)
22
(name coq-sqirvoqc)
3-
(version 1.3.1)
3+
(version 1.4.0)
44
(using coq 0.7)
55
(generate_opam_files true)
66

@@ -17,7 +17,7 @@
1717
)
1818
(depends
1919
(coq-interval (>= 4.9.0))
20-
(coq-quantumlib (>= 1.5.0))
20+
(coq-quantumlib (>= 1.7.0))
2121
(coq (>= 8.16))))
2222

2323
(package
@@ -28,6 +28,6 @@
2828
)
2929
(depends
3030
(coq-interval (>= 4.9.0))
31-
(coq-quantumlib (>= 1.5.0))
32-
(coq-sqir (>= 1.3.0))
31+
(coq-quantumlib (>= 1.7.0))
32+
(coq-sqir (>= 1.4.0))
3333
(coq (>= 8.16))))

0 commit comments

Comments
 (0)