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?
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$