mindquantum.core.circuit.add_suffix

View Source On Gitee
mindquantum.core.circuit.add_suffix(circuit_fn, suffix: str)[source]

Add a suffix on the parameter of a parameterized quantum circuit or a parameterized quantum operator.

(a function that can generate a parameterized quantum circuit).

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

  • suffix (str) – The suffix you want to add to every parameters.

Returns

Circuit or a function that can generate a Circuit.

Raises
  • TypeError – If suffix is not a string.

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

Examples

>>> from mindquantum.algorithm.library import qft
>>> from mindquantum.core.circuit import add_suffix
>>> from mindquantum import RX, H, Circuit
>>> u = lambda qubit: Circuit([H.on(0), RX('a').on(qubit)])
>>> u1 = u(0)
>>> u2 = add_suffix(u1, '1')
>>> u3 = add_suffix(u, '1')
>>> u3 = u3(0)
>>> u2
      ┏━━━┓ ┏━━━━━━━━━┓
q0: ──┨ H ┠─┨ RX(a_1) ┠───
      ┗━━━┛ ┗━━━━━━━━━┛
>>> u3
      ┏━━━┓ ┏━━━━━━━━━┓
q0: ──┨ H ┠─┨ RX(a_1) ┠───
      ┗━━━┛ ┗━━━━━━━━━┛