forked from inQWIRE/SQIR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
various updates to build system & directions for extraction
- Loading branch information
Showing
40 changed files
with
126 additions
and
91 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(coq.theory | ||
(name VOQC) | ||
(package coq-voqc)) | ||
(package coq-voqc) | ||
(theories SQIR)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
(coq.theory | ||
(name Examples) | ||
(theories SQIR ghz)) | ||
(theories SQIR)) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# GHZ Example | ||
|
||
This directory contains an implementation and proof of GHZ state preparation, plus an example for how to extract Coq/SQIR programs to OCaml/OpenQASM 2.0. You can use this as a model for extracting other SQIR programs. | ||
|
||
How to "run" GHZ: | ||
1. Run `make examples` in the top-level directory (`../..`). This compiles the GHZ Coq definitions and proofs (along with several other examples) and the extracted OCaml code in the `extraction/` directory. | ||
2. In the current directory, run `dune exec --root extraction -- ./ghz.exe N` where N is the number of qubits you want in the GHZ state. This runs our OCaml executable (`ghz.exe`) on the input `N`. It will produce a file called `ghz.qasm` that contains the generated OpenQASM code. | ||
|
||
The code in the `extraction/` directory was generated using the `./extract.sh` script. You can re-generate the extracted code using this script. Note that it was last tested with Coq version 8.15.2. Other versions of Coq will likely require modifications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
(coq.theory | ||
(name ghz) | ||
(theories SQIR)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Require Coq.extraction.Extraction. | ||
Require Export List. | ||
|
||
(* A few common list functions *) | ||
Extract Constant length => "(fun l -> Z.of_int (List.length l))". | ||
Extract Inlined Constant app => "List.append". | ||
Extract Inlined Constant rev => "List.rev". | ||
Extract Inlined Constant rev_append => "List.rev_append". | ||
Extract Inlined Constant List.map => "List.map". | ||
Extract Inlined Constant fold_right => "(fun f a l -> List.fold_right f l a)". | ||
Extract Inlined Constant forallb => "List.for_all". | ||
Extract Inlined Constant List.tl => "List.tl". | ||
Extract Inlined Constant List.hd_error => "(fun l -> List.nth_opt l 0)". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Require Coq.extraction.Extraction. | ||
Require Import ZArith. | ||
|
||
(* Custom extraction from nat -> OCaml Z (arbitrary precision integers) *) | ||
Extract Inductive nat => "Z.t" [ "Z.zero" "Z.succ" ] | ||
"(fun fO fS n -> if Z.equal n Z.zero then fO () else fS (Z.pred n))". | ||
Extract Constant Nat.pred => "(fun a -> Z.max (Z.pred a) Z.zero)". | ||
Extract Inlined Constant Nat.add => "Z.add". | ||
Extract Constant Nat.sub => "(fun a b -> Z.max (Z.sub a b) Z.zero)". | ||
Extract Inlined Constant Nat.mul => "Z.mul". | ||
Extract Inlined Constant Nat.div => "Z.div". | ||
Extract Inlined Constant Nat.modulo => "Z.rem". | ||
Extract Constant Nat.pow => "(fun a b -> Z.pow a (Z.to_int b))". | ||
Extract Inlined Constant Nat.gcd => "Z.gcd". | ||
Extract Constant Nat.log2 => "fun n -> (Z.of_int (Z.log2 n))". | ||
Extract Inlined Constant Nat.eqb => "Z.equal". | ||
Extract Inlined Constant Nat.leb => "Z.leq". | ||
Extract Inlined Constant Nat.ltb => "Z.lt". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Require Coq.extraction.Extraction. | ||
Require Export Reals. | ||
Require Import ExtractionGateSet. | ||
|
||
(* Custom extraction from R -> OCaml float. *) | ||
Extract Inlined Constant R => "float". | ||
Extract Inlined Constant R0 => "0.0". | ||
Extract Inlined Constant R1 => "1.0". | ||
Extract Inlined Constant R2 => "2.0". | ||
Extract Inlined Constant R4 => "4.0". | ||
Extract Inlined Constant Rplus => "( +. )". | ||
Extract Inlined Constant Rmult => "( *. )". | ||
Extract Inlined Constant Ropp => "((-.) 0.0)". | ||
Extract Inlined Constant Rinv => "((/.) 1.0)". | ||
Extract Inlined Constant Rminus => "( -. )". | ||
Extract Inlined Constant Rdiv => "( /. )". | ||
Extract Inlined Constant pow => "(fun a b -> a ** Z.to_float b)". | ||
Extract Inlined Constant cos => "cos". | ||
Extract Inlined Constant sin => "sin". | ||
Extract Inlined Constant tan => "tan". | ||
Extract Inlined Constant atan => "atan". | ||
Extract Inlined Constant acos => "acos". | ||
Extract Inlined Constant PI => "Float.pi". | ||
Extract Inlined Constant IZR => "Z.to_float". | ||
Extract Inlined Constant INR => "Z.to_float". | ||
|
||
(* Extracting the following to dummy values to supress warnings *) | ||
Extract Constant ClassicalDedekindReals.sig_forall_dec => "failwith ""Invalid extracted value"" ". | ||
Extract Constant ClassicalDedekindReals.DRealRepr => "failwith ""Invalid extracted value"" ". |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(executable | ||
(name ghz) | ||
(libraries Ghz_ml unix)) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/examples/ghz/extraction/ml/dune → examples/ghz/extraction/ml/dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(library | ||
(name ml) | ||
(name Ghz_ml) | ||
(wrapped false) | ||
(flags (:standard -w -3-32-33-34-39)) | ||
(libraries zarith unix)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
(include_subdirs qualified) | ||
|
||
(coq.theory | ||
(name Shor) | ||
(theories SQIR Examples)) |
Submodule euler
deleted from
74df69
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(executable | ||
(name run_shor) | ||
(libraries ml unix)) | ||
(flags (:standard -w -32)) | ||
(libraries Shor_ml unix)) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.