mindquantum.core.circuit.as_ansatz
- mindquantum.core.circuit.as_ansatz(circuit_fn)[source]
Conversion decorator of a circuit to an ansatz circuit.
- Parameters
circuit_fn (Union[Circuit, FunctionType, MethodType]) – A Circuit or a callable function that can return a Circuit.
- Returns
Function, if circuit_fn is a callable function that will return a Circuit. Circuit, if circuit_fn is already a Circuit.
Examples
>>> from mindquantum.core.circuit import as_ansatz, Circuit >>> from mindquantum.core.gates import RX >>> @as_ansatz ... def create_circuit(): ... circ = Circuit() ... circ += RX('a').on(0) ... return circ >>> circ = create_circuit() >>> circ.ansatz_params_name ['a'] >>> circ.as_encoder() >>> circ.ansatz_params_name [] >>> circ = as_ansatz(circ) >>> circ.ansatz_params_name ['a']