Quantum Counting#

quantum_counting(qv, oracle, precision)[source]#

This algorithm estimates the amount of solutions for a given Grover oracle.

Parameters:
qvQuantumVariable

The QuantumVariable on which to evaluate.

oraclefunction

The oracle function.

precisionint

The precision to perform the quantum phase estimation with.

Returns:
Mfloat

An estimate of the amount of solutions.

Examples

We create an oracle, which performs a simple phase flip on the last qubit.

from qrisp import quantum_counting, z, QuantumVariable

def oracle(qv):
    z(qv[-1])

We expect half of the state-space of the input to be a solution.

For 3 qubits, the state space is \(2^3 = 8\) dimensional.

>>> quantum_counting(QuantumVariable(3), oracle, 3)
3.999999999999999

For 4 qubits, the state space is \(2^4 = 16\) dimensional.

>>> quantum_counting(QuantumVariable(4), oracle, 3)
7.999999999999998