Commit 01b530d8 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Clean up the conditional measurement example



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent dd9a1546
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -2,41 +2,42 @@ OPENQASM 3;
include "qelib1.inc";

qubit q[2];
bit c[4];
const bits_precision = 4;
bit c[bits_precision];

h q[0];
// Prepare the eigen-state: |1>
x q[1];

// Prepare the state:
// First bit
h q[0];
// Controlled rotation: CU^k
for i in [0:8] {
  cphase(-5*pi/8) q[0], q[1];
}
h q[0];

// Measure and reset
measure q[0] -> c[0];
reset q[0];

// Second bit
h q[0];
for i in [0:4] {
  cphase(-5*pi/8) q[0], q[1];
}

// Conditional rotation
if (c[0] == 1) {
  rz(-pi/2) q[0];
}

h q[0];
// Measure and reset
measure q[0] -> c[1];
reset q[0];

// Third bit
h q[0];
for i in [0:2] {
  cphase(-5*pi/8) q[0], q[1];
}

// Conditional rotation
if (c[0] == 1) {
  rz(-pi/4) q[0];
@@ -45,15 +46,13 @@ if (c[1] == 1) {
  rz(-pi/2) q[0];
}
h q[0];


// Measure and reset
measure q[0] -> c[2];
reset q[0];

// Fourth bit
h q[0];
cphase(-5*pi/8) q[0], q[1];

// Conditional rotation
if (c[0] == 1) {
  rz(-pi/8) q[0];
@@ -64,6 +63,5 @@ if (c[1] == 1) {
if (c[2] == 1) {
  rz(-pi/2) q[0];
}

h q[0];
measure q[0] -> c[3];
 No newline at end of file