def apply_grover(oracle, nqubits, iterations=None):
 if (nqubits <= 0):
  raise QuantumError(("Grover's algorithm needs nqubits > 0, received %r qubits" % nqubits))
 if (iterations is None):
  iterations = floor((sqrt((2 ** nqubits)) * (pi / 4)))
 v = OracleGate(nqubits, oracle)
 iterated = superposition_basis(nqubits)
 for iter in range(iterations):
  iterated = grover_iteration(iterated, v)
  iterated = qapply(iterated)
 return iterated

def apply_grover ( oracle , nqubits , iterations = None ) : if ( nqubits <= 0 ) : raise QuantumError ( ( "Grover's algorithm needs nqubits > 0, received %r qubits" % nqubits ) ) if ( iterations is None ) : iterations = floor ( ( sqrt ( ( 2 ** nqubits ) ) * ( pi / 4 ) ) ) v = OracleGate ( nqubits , oracle ) iterated = superposition_basis ( nqubits ) for iter in range ( iterations ) : iterated = grover_iteration ( iterated , v ) iterated = qapply ( iterated ) return iterated
applies grovers algorithm .