qat.lang.algorithms.amplification_step

qat.lang.algorithms.amplification_step(oracle, state_prep=None)

Builds a routine that performs a single amplification step. By default the diffusion operator is Grover’s diffusion.

If the state_prep argument is specified, it will be used to perform the following Householder transform instead:

\[2\left(U|0\rangle\langle 0|U^\dagger\right) - I\]

where \(U\) is the unitary operator implemented by state_prep.

This method can be used to easily build a Grover search program:

from qat.lang.AQASM import Program, QInt, QRoutine, H
from qat.lang.algorithms import amplification_step


nbits = 2

oracle = QRoutine()
reg1 = oracle.new_wires(nbits, QInt)
reg2 = oracle.new_wires(nbits, QInt)
(reg1 == reg2).phase()

step = amplification_step(oracle)

grover = Program()
reg1 = grover.qalloc(nbits, QInt)
reg2 = grover.qalloc(nbits, QInt)
for qbit in reg1:
    H(qbit)
for qbit in reg2:
    H(qbit)
for _ in range(1):
    step(reg1, reg2)
job = grover.to_circ().to_job(qubits=[reg1, reg2])

from qat.qpus import get_default_qpu
qpu = get_default_qpu()

result = qpu.submit(job)
for sample in result:
    print(sample.state.value, sample.probability)
(0, 0) 0.2499999999999995
(1, 1) 0.2499999999999995
(2, 2) 0.2499999999999995
(3, 3) 0.2499999999999995
Parameters
  • oracle (Gate) – a quantum gate or routine implementing the oracle

  • state_prep (optional, Gate) – a quantum gate or routine

Returns

a routine

Return type

QRoutine