mindquantum.core.circuit.controlled

View Source On Gitee
mindquantum.core.circuit.controlled(circuit_fn)[source]

Add control qubits on a quantum circuit or a quantum operator.

(a function that can generate a quantum circuit)

Parameters

circuit_fn (Union[Circuit, FunctionType, MethodType]) – A quantum circuit, or a function that can generate a quantum circuit.

Returns

function that can generate a Circuit.

Raises

TypeErrorcircuit_fn is not a Circuit or can not return a Circuit.

Examples

>>> from mindquantum.algorithm.library import qft
>>> from mindquantum.core.circuit import controlled
>>> u1 = qft([0, 1])
>>> u2 = controlled(u1)
>>> u3 = controlled(qft)
>>> u3 = u3(2, [0, 1])
>>> u2(2)
      ┏━━━┓ ┏━━━━━━━━━┓
q0: ──┨ H ┠─┨ PS(π/2) ┠───────╳───
      ┗━┳━┛ ┗━━━━┳━━━━┛       ┃
        ┃        ┃      ┏━━━┓ ┃
q1: ────╂────────■──────┨ H ┠─╳───
        ┃        ┃      ┗━┳━┛ ┃
        ┃        ┃        ┃   ┃
q2: ────■────────■────────■───■───
>>> u3
      ┏━━━┓ ┏━━━━━━━━━┓
q0: ──┨ H ┠─┨ PS(π/2) ┠───────╳───
      ┗━┳━┛ ┗━━━━┳━━━━┛       ┃
        ┃        ┃      ┏━━━┓ ┃
q1: ────╂────────■──────┨ H ┠─╳───
        ┃        ┃      ┗━┳━┛ ┃
        ┃        ┃        ┃   ┃
q2: ────■────────■────────■───■───