mindquantum.core.circuit.apply

View Source On Gitee
mindquantum.core.circuit.apply(circuit_fn, qubits)[source]

Apply a quantum circuit or a quantum operator (a function that can generate a quantum circuit) to different qubits.

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

  • qubits (list[int]) – The new qubits that you want to apply.

Returns

Circuit or a function that can generate a Circuit.

Raises
  • TypeError – If qubits is not a list.

  • ValueError – If any element of qubits is negative.

  • TypeError – If circuit_fn is not Circuit or can not return a Circuit.

Examples

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