diff --git a/src/mqt/bench/.gitignore b/src/mqt/bench/.gitignore new file mode 100644 index 000000000..adba0bef5 --- /dev/null +++ b/src/mqt/bench/.gitignore @@ -0,0 +1 @@ +!*.qasm diff --git a/src/mqt/bench/benchmarks/structured/ghz/ghz.qasm b/src/mqt/bench/benchmarks/structured/ghz/ghz.qasm new file mode 100644 index 000000000..5d4ab3789 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/ghz/ghz.qasm @@ -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]; +} diff --git a/src/mqt/bench/benchmarks/structured/grover/grover.qasm b/src/mqt/bench/benchmarks/structured/grover/grover.qasm new file mode 100644 index 000000000..23e6a0305 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/grover/grover.qasm @@ -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); + +for int i in [1:num_iterations] { + // oracle + ctrl(n-1) @ z q[0:n-1], flag; + + // diffusion + h q; + x q; + ctrl(n-2) @ z q[0:n-2], q[n-1]; + x q; + h q; +} diff --git a/src/mqt/bench/benchmarks/structured/iqft/iqft.qasm b/src/mqt/bench/benchmarks/structured/iqft/iqft.qasm new file mode 100644 index 000000000..6bfc28e83 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/iqft/iqft.qasm @@ -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]) { + p(2*pi/2**(i-j+1)) q; + } + } + h q; + res[n - 1 - i] = measure q; +} diff --git a/src/mqt/bench/benchmarks/structured/iqpe/iqpe.qasm b/src/mqt/bench/benchmarks/structured/iqpe/iqpe.qasm new file mode 100644 index 000000000..2c5952588 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/iqpe/iqpe.qasm @@ -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] { + if (res[j]) { + p(2*pi/2**(j-i+1)) q; + } + } + h q; + res[i] = measure q; + reset q; +} diff --git a/src/mqt/bench/benchmarks/structured/multiplexer/multiplexer.qasm b/src/mqt/bench/benchmarks/structured/multiplexer/multiplexer.qasm new file mode 100644 index 000000000..1914ef1e1 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/multiplexer/multiplexer.qasm @@ -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; + + +qubit[num_controls] controls; +qubit target; +bit[num_controls + 1] c; + +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 + } + } +} diff --git a/src/mqt/bench/benchmarks/structured/qft/qft.qasm b/src/mqt/bench/benchmarks/structured/qft/qft.qasm new file mode 100644 index 000000000..d95768a58 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/qft/qft.qasm @@ -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]; +} diff --git a/src/mqt/bench/benchmarks/structured/qpe/qpe.qasm b/src/mqt/bench/benchmarks/structured/qpe/qpe.qasm new file mode 100644 index 000000000..d04901051 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/qpe/qpe.qasm @@ -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]; + } +} diff --git a/src/mqt/bench/benchmarks/structured/teleportation/teleportation.qasm b/src/mqt/bench/benchmarks/structured/teleportation/teleportation.qasm new file mode 100644 index 000000000..aa0b9fc19 --- /dev/null +++ b/src/mqt/bench/benchmarks/structured/teleportation/teleportation.qasm @@ -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; +} + +// Now q2 is in the previous state of a.