0
$\begingroup$

I have been trying to implement quantum counting using my own oracle, however I've been unsuccessful getting results that make sense. The circuit I'm using looks like this (I'm only showing the variation with 3 counting qubits here to save on space)

      ┌───┐                                                                                    ┌───────┐┌─┐      
 q_0: ┤ H ├─────■──────────────────────────────────────────────────────────────────────────────┤0      ├┤M├──────
      ├───┤     │                                                                              │       │└╥┘┌─┐   
 q_1: ┤ H ├─────┼───────────■───────────■──────────────────────────────────────────────────────┤1 IQFT ├─╫─┤M├───
      ├───┤     │           │           │                                                      │       │ ║ └╥┘┌─┐
 q_2: ┤ H ├─────┼───────────┼───────────┼───────────■───────────■───────────■───────────■──────┤2      ├─╫──╫─┤M├
      ├───┤┌────┴─────┐┌────┴─────┐┌────┴─────┐┌────┴─────┐┌────┴─────┐┌────┴─────┐┌────┴─────┐└───────┘ ║  ║ └╥┘
 q_3: ┤ H ├┤0         ├┤0         ├┤0         ├┤0         ├┤0         ├┤0         ├┤0         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
 q_4: ┤ H ├┤1         ├┤1         ├┤1         ├┤1         ├┤1         ├┤1         ├┤1         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
 q_5: ┤ H ├┤2         ├┤2         ├┤2         ├┤2         ├┤2         ├┤2         ├┤2         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
 q_6: ┤ H ├┤3         ├┤3         ├┤3         ├┤3         ├┤3         ├┤3         ├┤3         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
 q_7: ┤ H ├┤4         ├┤4         ├┤4         ├┤4         ├┤4         ├┤4         ├┤4         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
 q_8: ┤ H ├┤5         ├┤5         ├┤5         ├┤5         ├┤5         ├┤5         ├┤5         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
 q_9: ┤ H ├┤6         ├┤6         ├┤6         ├┤6         ├┤6         ├┤6         ├┤6         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_10: ┤ H ├┤7         ├┤7         ├┤7         ├┤7         ├┤7         ├┤7         ├┤7         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_11: ┤ H ├┤8  Grover ├┤8  Grover ├┤8  Grover ├┤8  Grover ├┤8  Grover ├┤8  Grover ├┤8  Grover ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_12: ┤ H ├┤9         ├┤9         ├┤9         ├┤9         ├┤9         ├┤9         ├┤9         ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_13: ┤ H ├┤10        ├┤10        ├┤10        ├┤10        ├┤10        ├┤10        ├┤10        ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_14: ┤ H ├┤11        ├┤11        ├┤11        ├┤11        ├┤11        ├┤11        ├┤11        ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_15: ┤ H ├┤12        ├┤12        ├┤12        ├┤12        ├┤12        ├┤12        ├┤12        ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_16: ┤ H ├┤13        ├┤13        ├┤13        ├┤13        ├┤13        ├┤13        ├┤13        ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_17: ┤ H ├┤14        ├┤14        ├┤14        ├┤14        ├┤14        ├┤14        ├┤14        ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_18: ┤ H ├┤15        ├┤15        ├┤15        ├┤15        ├┤15        ├┤15        ├┤15        ├──────────╫──╫──╫─
      ├───┤│          ││          ││          ││          ││          ││          ││          │          ║  ║  ║ 
q_19: ┤ H ├┤16        ├┤16        ├┤16        ├┤16        ├┤16        ├┤16        ├┤16        ├──────────╫──╫──╫─
      └───┘└──────────┘└──────────┘└──────────┘└──────────┘└──────────┘└──────────┘└──────────┘          ║  ║  ║ 
 c: 3/═══════════════════════════════════════════════════════════════════════════════════════════════════╩══╩══╩═
                                                                                                         0  1  2 

IQFT is Qiskit's own IQFT implementation. Solutions to the search problem consist of 9 qubits, with the other 8 qubits of the Grover iteration being ancillary qubits. The only result I'm getting (with 100% probability) from this circuit is 100, (for more counting qubits, the result is always a 1 followed by only 0's) - and so the resulting phase is always $\pi$.

The oracle I'm using seems to work fine when using Grover's algorithm. My question is, do I also need to apply Hadamard gates to the ancilla qubits? There is more randomness to the answer when I don't, but the there is still a single maxima at 100. In addition, does the oracle qubit need to get initialized to $|-\rangle$ as with Grover's algorithm? Could it be a problem with my oracle?

$\endgroup$
2
  • $\begingroup$ The circuit looks Ok to me, as long as the Grover operator takes all 17 qubits. There should be no Hadamards on the ancillas. Quantum counting works well with a small number of solutions. How many did you encode in the Grover operator? I suspect that 100 corresponds to the binary fraction $1/2$ or $1/8$. Still, the number of solutions to 2 digits is computed via M = round(n * math.sin(phi_estimate * math.pi)**2, 2). Your Grover operator has 17 qubits, that would be very large n and correspondingly, a very large number of solutions. Again, I'd check the G first. $\endgroup$
    – rhundt
    Feb 17 at 16:14
  • $\begingroup$ To clarify, solutions only consist of 9 qubits hence 2^9 = 512 possible solutions. There are only 14 correct solutions which easily found after sufficient shots of Grover's algorithm. Putting Hadamards on the ancillas seems to be a mistake, thank you. I'll change that and report back. $\endgroup$
    – Lucas
    Feb 17 at 16:22

1 Answer 1

1
$\begingroup$

Found the answer thanks to rhundt's comment. The solution was to remove the Hadamard gates from the ancillary qubits, and to initialize the "oracle qubit" to the usual state ($|-\rangle$). Additionally, if there are no two clear solutions, consider increasing the number of counting qubits until you get two clear results (corresponding to $\pm$ the phase)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.