mindquantum.core.circuit.change_param_name

View Source On Gitee
mindquantum.core.circuit.change_param_name(circuit_fn, name_map)[source]

Change the parameter name 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.

  • name_map (dict) – The parameter name mapping dict.

Returns

Circuit or a function that can generate a Circuit.

Raises
  • TypeError – If name_map is not a map.

  • TypeError – If key of name_map is not string.

  • TypeError – If value of name_map is not string.

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

Examples

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