Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I put together this code for IBM's 5 qubit processor as an implementation of Grover's search algorithm, but for an unknown number of solutions:

h q[0];
h q[1];
x q[2];
s q[0];
cx q[1], q[2];
t q[3];
cx q[0], q[2];
s q[3];
x q[0];
z q[1];
s q[2];
tdg q[3];
cx q[0], q[2];
id q[3];
cx q[1], q[2];
h q[0];
h q[1];
h q[2];
x q[0];
x q[1];
x q[2];
cx q[0], q[2];
h q[0];
cx q[1], q[2];
s q[2];
h q[2];
tdg q[2];
h q[2];
measure q[0];
measure q[1];
measure q[2];
measure q[3];
measure q[4];

For successful implementations of Grover's algorithm, there has to be a bias towards |0> outputs, while the output of |1> only occurs upon a successful query of the qubit oracle.

In line with this, the output produces a probabilistic distribution across all possible output permutations of the 5-qubit system, with a |0> bias. Since I am using the "amplitude amplification" method, or "reflection about the mean" the output value will generate a fluctuation in probabilities based on the solution to the problem presented. The fifth qubit Q4 is unused, and is reserved for problem encoding.

While IBM allows anyone to publicly access their 5 qubit processor, you will need to be upgraded to Expert User status to copy/paste the QASM code provided. Otherwise, as a Standard User you can build this same algorithm by following the drag and drop operations provided. I've already run this experiment on their live system using 4096 shots, as I do with all tests I run live.

I'd like feedback on suggestions of whether I need to keep the Q4 qubit reserved strictly for problem encoding, or if a problem would be more optimally encoded distributed across all qubits.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.