mimiqcircuits.operations.gates.generalized.diffusion

Grover diffusion operator.

Classes

Diffusion(*args)

Grover's diffusion operator on num_qubits qubits.

class Diffusion(*args)[source]

Bases: Gate

Grover’s diffusion operator on num_qubits qubits.

Implements the unitary

\[H^{\otimes n} \left(1 - 2 |0^n\rangle\langle 0^n|\right) H^{\otimes n}\]

Diffusion() with no arguments returns a lazy expression that takes the number of qubits later. The gate has no matrix representation: matrix() raises NotImplementedError.

Parameters:

num_qubits (int) – Number of qubits, at least 1.

Raises:

ValueError – If num_qubits is not an integer or is less than 1, or more than one argument is given.

Examples

>>> from mimiqcircuits import *
>>> c = Circuit()
>>> c.push(Diffusion(2), 1, 2)
3-qubit circuit with 1 instruction:
└── Diffusion @ q[1:2]

>>> Diffusion(2).decompose()
2-qubit circuit with 5 instructions:
├── RY((1/2)*pi) @ q[0]
├── RY((1/2)*pi) @ q[1]
├── CZ @ q[0], q[1]
├── RY((-1/2)*pi) @ q[0]
└── RY((-1/2)*pi) @ q[1]
inverse()[source]

Return the inverse of the gate.

Gates with a known inverse return it directly (for example GateS().inverse() is GateSDG()); otherwise the gate is wrapped in Inverse.