5 edited body; edited title

# Grover's Algorithmalgorithm returns skewed probability distribution

Furthermore, these results do not obtain when I actually run the circuit. Instead of a step-function for the probabilities, when I run 1024 shots I tend to get between 30 and 50 for the unsuccessful results and the successful results are spread between 200 and 460. While it's obvious that the successful results have been selected, the spread is concerning because the math seems to indicate that they should be fairly close together. Moreover, the successful results always fall in the same order, which is also counter intuitive-intuitive given that results are probabilistic. This implies one of two things to me:

# Grover's Algorithm returns skewed probability distribution

Furthermore, these results do not obtain when I actually run the circuit. Instead of a step-function for the probabilities, when I run 1024 shots I tend to get between 30 and 50 for the unsuccessful results and the successful results are spread between 200 and 460. While it's obvious that the successful results have been selected, the spread is concerning because the math seems to indicate that they should be fairly close together. Moreover, the successful results always fall in the same order, which is also counter intuitive given that results are probabilistic. This implies one of two things to me:

# Grover's algorithm returns skewed probability distribution

Furthermore, these results do not obtain when I actually run the circuit. Instead of a step-function for the probabilities, when I run 1024 shots I tend to get between 30 and 50 for the unsuccessful results and the successful results are spread between 200 and 460. While it's obvious that the successful results have been selected, the spread is concerning because the math seems to indicate that they should be fairly close together. Moreover, the successful results always fall in the same order, which is also counter-intuitive given that results are probabilistic. This implies one of two things to me:

4 Fixed issue with the code so that the oracle is as I described
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, Aer, execute

# Initialize circuit
m_qubit = QuantumRegister(1)
search_register = QuantumRegister(4)
result_register = ClassicalRegister(4)
ancillaries = QuantumRegister(3)
circuit = QuantumCircuit(search_register, result_register, m_qubit, ancillaries)

# Put M qubit into 1-superposition
circuit.x(m_qubit)
circuit.h(m_qubit)

# Put search qubits into superposition
circuit.h(search_register)

for _ in range(2):

# Encode S1 * !S2 * S3
circuit.x( search_register )
circuit.ccx( search_register, search_register, ancillaries )
circuit.ccx( search_register, ancillaries, ancillaries )
circuit.x( search_register )

# Encode S0 +* S1
circuit.xccx( search_register, search_register, ancillaries )

circuit.x(# search_registerEncode )
oracle ((S0 * S1) circuit.ccx+ (S1 search_register,* search_register,!S2 ancillaries* S3))
circuit.x( search_register ancillaries)
circuit.xccx( search_registerancillaries, ancillaries, m_qubit )
circuit.x( ancillaries ancillaries)

# Encode oracle
circuit.ccxx( ancillaries, ancillaries, m_qubit m_qubit)

# Reset ancillaries to be used later
circuit.reset(ancillaries)

# Do rotation about the average
circuit.h(search_register)
circuit.x(search_register)
circuit.ccx( search_register, search_register, ancillaries )
circuit.ccx( search_register, ancillaries, ancillaries )
circuit.ccx( search_register, ancillaries, m_qubit )
circuit.x(search_register)
circuit.x(m_qubit)
circuit.h(search_register)

# Reset ancillaries for use later
circuit.reset(ancillaries)

circuit.measure(search_register, result_register)

# Run the circuit with a given number of shots
backend_sim = Aer.get_backend('qasm_simulator')
job_sim = execute(circuit, backend_sim, shots = 1024)
result_sim = job_sim.result()

# get_counts returns a dictionary with the bit-strings as keys
# and the number of times the string resulted as the value
print(result_sim.get_counts(circuit))

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, Aer, execute

# Initialize circuit
m_qubit = QuantumRegister(1)
search_register = QuantumRegister(4)
result_register = ClassicalRegister(4)
ancillaries = QuantumRegister(3)
circuit = QuantumCircuit(search_register, result_register, m_qubit, ancillaries)

# Put M qubit into 1-superposition
circuit.x(m_qubit)
circuit.h(m_qubit)

# Put search qubits into superposition
circuit.h(search_register)

for _ in range(2):

# Encode S1 * !S2 * S3
circuit.x( search_register )
circuit.ccx( search_register, search_register, ancillaries )
circuit.ccx( search_register, ancillaries, ancillaries )
circuit.x( search_register )

# Encode S0 + S1
circuit.x( search_register )
circuit.x( search_register )
circuit.ccx( search_register, search_register, ancillaries )
circuit.x( search_register )
circuit.x( search_register )
circuit.x( ancillaries )

# Encode oracle
circuit.ccx( ancillaries, ancillaries, m_qubit )

# Reset ancillaries to be used later
circuit.reset(ancillaries)

# Do rotation about the average
circuit.h(search_register)
circuit.x(search_register)
circuit.ccx( search_register, search_register, ancillaries )
circuit.ccx( search_register, ancillaries, ancillaries )
circuit.ccx( search_register, ancillaries, m_qubit )
circuit.x(search_register)
circuit.x(m_qubit)
circuit.h(search_register)

# Reset ancillaries for use later
circuit.reset(ancillaries)

circuit.measure(search_register, result_register)

# Run the circuit with a given number of shots
backend_sim = Aer.get_backend('qasm_simulator')
job_sim = execute(circuit, backend_sim, shots = 1024)
result_sim = job_sim.result()

# get_counts returns a dictionary with the bit-strings as keys
# and the number of times the string resulted as the value
print(result_sim.get_counts(circuit))

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, Aer, execute

# Initialize circuit
m_qubit = QuantumRegister(1)
search_register = QuantumRegister(4)
result_register = ClassicalRegister(4)
ancillaries = QuantumRegister(3)
circuit = QuantumCircuit(search_register, result_register, m_qubit, ancillaries)

# Put M qubit into 1-superposition
circuit.x(m_qubit)
circuit.h(m_qubit)

# Put search qubits into superposition
circuit.h(search_register)

for _ in range(2):

# Encode S1 * !S2 * S3
circuit.x( search_register )
circuit.ccx( search_register, search_register, ancillaries )
circuit.ccx( search_register, ancillaries, ancillaries )
circuit.x( search_register )

# Encode S0 * S1
circuit.ccx( search_register, search_register, ancillaries )

# Encode oracle ((S0 * S1) + (S1 * !S2 * S3))
circuit.x(ancillaries)
circuit.ccx( ancillaries, ancillaries, m_qubit )
circuit.x(ancillaries)
circuit.x(m_qubit)

# Reset ancillaries to be used later
circuit.reset(ancillaries)

# Do rotation about the average
circuit.h(search_register)
circuit.x(search_register)
circuit.ccx( search_register, search_register, ancillaries )
circuit.ccx( search_register, ancillaries, ancillaries )
circuit.ccx( search_register, ancillaries, m_qubit )
circuit.x(search_register)
circuit.x(m_qubit)
circuit.h(search_register)

# Reset ancillaries for use later
circuit.reset(ancillaries)

circuit.measure(search_register, result_register)

# Run the circuit with a given number of shots
backend_sim = Aer.get_backend('qasm_simulator')
job_sim = execute(circuit, backend_sim, shots = 1024)
result_sim = job_sim.result()

# get_counts returns a dictionary with the bit-strings as keys
# and the number of times the string resulted as the value
print(result_sim.get_counts(circuit))

3 edited tags

$$\frac{1}{1024 \sqrt{2}} \left( -304 \left( \sum_{x \in \{00, 01, 11\}} \left| x \right> \left( \left|00\right> + \left|01\right> + \left|10\right> \right) + \left|1000\right> + \left|1001\right> \right) + 80 \left( \sum_{x = 00}^{11} \left|x\right> \left|11\right> + \left|1010\right> \right) \right) \left( \left|0\right> - \left|1\right> \right)$$$$\frac{1}{1024 \sqrt{2}} \left( -304 \left( \sum_{x \in \{00, 01, 11\}} \left| x \right> \left( \left|00\right> + \left|01\right> + \left|10\right> \right) + \left|1000\right> + \left|1001\right> \right) + 80 \left( \sum_{x = 00}^{11} \left|x\right> \left|11\right> + \left|1010\right> \right) \right) \left( \left|0\right> - \left|1\right> \right)$$

$$\frac{1}{1024 \sqrt{2}} \left( -304 \left( \sum_{x \in \{00, 01, 11\}} \left| x \right> \left( \left|00\right> + \left|01\right> + \left|10\right> \right) + \left|1000\right> + \left|1001\right> \right) + 80 \left( \sum_{x = 00}^{11} \left|x\right> \left|11\right> + \left|1010\right> \right) \right) \left( \left|0\right> - \left|1\right> \right)$$

$$\frac{1}{1024 \sqrt{2}} \left( -304 \left( \sum_{x \in \{00, 01, 11\}} \left| x \right> \left( \left|00\right> + \left|01\right> + \left|10\right> \right) + \left|1000\right> + \left|1001\right> \right) + 80 \left( \sum_{x = 00}^{11} \left|x\right> \left|11\right> + \left|1010\right> \right) \right) \left( \left|0\right> - \left|1\right> \right)$$