-
-
Notifications
You must be signed in to change notification settings - Fork 28
✨ Add Structured Program Benchmarks #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| !*.qasm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| OPENQASM 3.0; | ||
| include "qelib1.inc"; | ||
|
|
||
| input int n; | ||
|
|
||
| qubit[n] q; | ||
|
|
||
| h q[0]; | ||
| for int i in [1:n-1] { | ||
| cx q[i - 1], q[i]; | ||
| } | ||
|
Comment on lines
+4
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Guard against n == 0 (q[0] access) Program assumes n ≥ 1 due to Example guard: input int n;
qubit[n] q;
+// Require n >= 1
+if (n == 0) {
+ // no-op or raise, depending on your bench conventions
+}
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| OPENQASM 3.0; | ||||||
| include "qelib1.inc"; | ||||||
|
|
||||||
| input int n; | ||||||
|
|
||||||
| qubit[n-1] q; | ||||||
| qubit flag; | ||||||
|
|
||||||
| h q; | ||||||
| x flag; | ||||||
|
|
||||||
| int num_iterations = int(pi / 4 * 2**(n-1)**0.5); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the operator precedence in the Grover iteration formula. The expression For example, with n=5 (4 search qubits):
While these happen to match for n=5, they diverge for other values:
Apply this diff to fix the formula: -int num_iterations = int(pi / 4 * 2**(n-1)**0.5);
+int num_iterations = int(pi / 4 * sqrt(2**(n-1)));Or equivalently: -int num_iterations = int(pi / 4 * 2**(n-1)**0.5);
+int num_iterations = int(pi / 4 * 2**((n-1)/2.0));📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| for int i in [1:num_iterations] { | ||||||
| // oracle | ||||||
| ctrl(n-1) @ z q[0:n-1], flag; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out-of-bounds array access on line 16. The register Apply this diff to fix the indexing: - ctrl(n-1) @ z q[0:n-1], flag;
+ ctrl(n-1) @ z q, flag;Note: In OpenQASM 3.0, using the register name 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| // diffusion | ||||||
| h q; | ||||||
| x q; | ||||||
| ctrl(n-2) @ z q[0:n-2], q[n-1]; | ||||||
| x q; | ||||||
| h q; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||
| OPENQASM 3.0; | ||||||||||||||||
| include "qelib1.inc"; | ||||||||||||||||
|
|
||||||||||||||||
| input int n; | ||||||||||||||||
|
|
||||||||||||||||
| qubit q; | ||||||||||||||||
| bit[n] res; | ||||||||||||||||
|
|
||||||||||||||||
| for int i in [0:n-1] { | ||||||||||||||||
| for int j in [0:i-1] { | ||||||||||||||||
| if (res[n - 1 - j]) { | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use explicit comparison for bit conditions Make - if (res[n - 1 - j]) {
+ if (res[n - 1 - j] == 1) {🤖 Prompt for AI Agents |
||||||||||||||||
| p(2*pi/2**(i-j+1)) q; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| h q; | ||||||||||||||||
| res[n - 1 - i] = measure q; | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reset after measurement to avoid state carryover Unlike iqpe, this program doesn’t reset - res[n - 1 - i] = measure q;
+ res[n - 1 - i] = measure q;
+ reset q;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||||||||||||||||
| OPENQASM 3.0; | ||||||||||||||||||||||||
| include "qelib1.inc"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| input int precision; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| qubit q; | ||||||||||||||||||||||||
| qubit anc; | ||||||||||||||||||||||||
| bit[precision] res; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| x anc; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for int i in [precision - 1:0:-1] { | ||||||||||||||||||||||||
| h q; | ||||||||||||||||||||||||
| pow(2**i) @ cp(3*pi/8) q, anc; | ||||||||||||||||||||||||
| for int j in [i + 1:precision - 1] { | ||||||||||||||||||||||||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Verify support for Some parsers (e.g., current Qiskit) may not support - pow(2**i) @ cp(3*pi/8) q, anc;
+ // Fallback for parsers without pow(@) support:
+ for int k in [0:2**i-1] {
+ cp(3*pi/8) q, anc;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| if (res[j]) { | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use explicit comparison for bit conditions Many toolchains require - if (res[j]) {
+ if (res[j] == 1) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| p(2*pi/2**(j-i+1)) q; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| h q; | ||||||||||||||||||||||||
| res[i] = measure q; | ||||||||||||||||||||||||
| reset q; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||||
| OPENQASM 3.0; | ||||||||
|
|
||||||||
| // Quantum Multiplexer (Uniformly Controlled RY Gates) | ||||||||
| // Applies 2^n different RY rotations based on n control qubits | ||||||||
|
|
||||||||
| input int n; | ||||||||
| int num_controls = n - 1; | ||||||||
| input angle[2**num_controls] angles; | ||||||||
|
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify OpenQASM 3.0 support for runtime-sized array declarations. Line 8 declares an input array with size Run the following verification to check OpenQASM 3.0 specification and test with available parsers: 🌐 Web query: 💡 Result: Short answer: No — OpenQASM 3.0 requires array/register sizes to be compile‑time constants. You cannot declare a global array with a size computed only at runtime (e.g. input angle[2**num_controls] where num_controls is a non-const input). See the specification passages that sizes must be compile‑time const and examples showing invalid runtime-sized declarations. [1][2] References
Require compile-time constant for array dimensions 🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
|
|
||||||||
| qubit[num_controls] controls; | ||||||||
| qubit target; | ||||||||
| bit[num_controls + 1] c; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Remove unused classical bit register. The classical bit register Apply this diff: qubit[num_controls] controls;
qubit target;
-bit[num_controls + 1] c;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| int num_states = 2**num_controls; | ||||||||
|
|
||||||||
| for int state in [0:num_states-1] { | ||||||||
| // We want to apply angles[state] when controls equal 'state' | ||||||||
| // State is a binary number: e.g., state=5 = 0b101 for 3 controls | ||||||||
| // means control[0]=1, control[1]=0, control[2]=1 | ||||||||
|
|
||||||||
| // Extract each bit: if 0, we need to flip the corresponding qubit | ||||||||
| // Bit i is: (state >> i) & 1 | ||||||||
| for int bit_pos in [0:num_controls-1] { | ||||||||
| int bit_value = (state >> bit_pos) & 1; | ||||||||
| if (bit_value == 0) { | ||||||||
| x controls[bit_pos]; // Flip this control | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Apply fully-controlled gate (all controls must be |1⟩) | ||||||||
| ctrl(num_controls) @ ry(angles[state]) controls[0:num_controls-1], target; | ||||||||
|
|
||||||||
| // Flip controls back | ||||||||
| for int bit_pos in [0:num_controls-1] { | ||||||||
| int bit_value = (state >> bit_pos) & 1; | ||||||||
| if (bit_value == 0) { | ||||||||
| x controls[bit_pos]; // Flip back | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||||
| OPENQASM 3.0; | ||||||||||||||||||||||||||||||
| include "qelib1.inc"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| input int n; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| qubit[n] q; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| for int i in [0:n-1] { | ||||||||||||||||||||||||||||||
| h q[i]; | ||||||||||||||||||||||||||||||
| for int j in [i+1:n-1] { | ||||||||||||||||||||||||||||||
| cp(2*pi/2**(j-i+1)) q[j], q[i]; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| for int i in [0:(n-1)/2] { | ||||||||||||||||||||||||||||||
| swap q[i], q[n - 1 - i]; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix swap loop bound to avoid non-integer/end-inclusive pitfalls
-for int i in [0:(n-1)/2] {
+for int i in [0:n/2 - 1] {
swap q[i], q[n - 1 - i];
}Alternatively (more robust to integer semantics): -for int i in [0:(n-1)/2] {
- swap q[i], q[n - 1 - i];
-}
+for int i in [0:n-1] {
+ if (i < n - 1 - i) {
+ swap q[i], q[n - 1 - i];
+ }
+}📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| OPENQASM 3.0; | ||
| include "qelib1.inc"; | ||
|
|
||
| input int n; | ||
|
|
||
| qubit[n-1] q; | ||
| qubit anc; | ||
|
|
||
| h q; | ||
| x anc; | ||
|
|
||
| // Iteratively apply gates | ||
| for int i in [0:n-2] { | ||
| pow(2**i) @ cp(3*pi/8) q[i], anc; | ||
| } | ||
|
|
||
| // Apply reverse QFT | ||
| for int i in [0:(n-2)/2] { | ||
| swap q[i], q[n - 2 - i]; | ||
| } | ||
| for int i in [0:n-2] { | ||
| h q[i]; | ||
| for int j in [i+1:n-2] { | ||
| cp(2*pi/2**(j-i+1)) q[j], q[i]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||||||||||||||||||
| OPENQASM 3.0; | ||||||||||||||||||||||||||
| include "qelib1.inc"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| qubit psi; | ||||||||||||||||||||||||||
| qubit q1; | ||||||||||||||||||||||||||
| qubit q2; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Alice has a qubit in an unknown state. | ||||||||||||||||||||||||||
| h psi; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Alice and Bob share an entangled Bell pair. | ||||||||||||||||||||||||||
| h q1; | ||||||||||||||||||||||||||
| cx q1, q2; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Alice prepares the teleport operation. | ||||||||||||||||||||||||||
| cx psi, q1; | ||||||||||||||||||||||||||
| h psi; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Alice then measures her qubits. | ||||||||||||||||||||||||||
| bit a = measure psi; | ||||||||||||||||||||||||||
| bit b1 = measure q1; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Bob applies corrections based on the measurement result. | ||||||||||||||||||||||||||
| if (b1) { | ||||||||||||||||||||||||||
| x q2; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (a) { | ||||||||||||||||||||||||||
| z q2; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+24
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use explicit comparisons for bit-controlled corrections Ensure conditionals on measured bits are explicit. -if (b1) {
+if (b1 == 1) {
x q2;
}
-if (a) {
+if (a == 1) {
z q2;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Now q2 is in the previous state of a. | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment nit: variable name “previous state of a” should be “previous state of psi”. -// Now q2 is in the previous state of a.
+// Now q2 is in the previous state of psi.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Negation won’t catch nested .qasm files
!*.qasmonly re-includes files directly under this folder, not nested ones (e.g., benchmarks/structured/**). If the parent .gitignore ignores*.qasm, nested files remain ignored. Use a recursive pattern.If the parent doesn’t ignore
*.qasm, consider removing this file altogether to avoid confusion.🏁 Script executed:
Length of output: 54
Include nested .qasm files
Root .gitignore ignores
*.qasm, so!*.qasmhere only re-includes files directly under this folder. Add a recursive pattern:!*.qasm +!**/*.qasm📝 Committable suggestion
🤖 Prompt for AI Agents