Ansatz generation (qiskit_addon_aqc_tensor.ansatz_generation
)¶
Utility for generating a general, parametrized, ansatz circuit which matches the two-qubit connectivity of an input circuit.
Ansatz block. |
|
One-qubit ansatz block. |
|
Two-qubit ansatz block. |
|
One-qubit ansatz block based on the ZXZ decomposition. |
|
Two-qubit ansatz block based on the KAK decomposition. |
- generate_ansatz_from_circuit(qc, /, *, qubits_initially_zero=False, parameter_name='theta')[source][source]¶
Generate an ansatz from the two-qubit connectivity structure of a circuit.
See the explanatatory material for motivation.
- Parameters:
qc (
QuantumCircuit
) – A circuit, which is assumed to be unitary. Barriers are ignored.qubits_initially_zero (
bool
) – IfTrue
, the first Z rotation on each qubit is fixed to zero because such a rotation has no effect on the state \(|0\rangle\).parameter_name (
str
) – Name for theParameterVector
representing the free parameters in the returned ansatz circuit.
- Return type:
- Returns:
(ansatz, parameter_values)
such thatansatz.assign_parameters(parameter_values)
is equivalent toqc
up to a global phase.
Example:¶
Consider the following circuit as an example:
from qiskit import QuantumCircuit qc = QuantumCircuit(6) qc.rx(0.4, 0) qc.ryy(0.2, 2, 3) qc.h(2) qc.rz(0.1, 2) qc.rxx(0.3, 0, 1) qc.rzz(0.3, 0, 1) qc.cx(2, 1) qc.s(1) qc.h(4) qc.draw("mpl")
If the above circuit is passed to
generate_ansatz_from_circuit()
, it will return an ansatz with parametrized two-qubit KAK rotations in the same locations as the input:from qiskit_addon_aqc_tensor import generate_ansatz_from_circuit ansatz, initial_params = generate_ansatz_from_circuit( qc, qubits_initially_zero=True, parameter_name="x" ) ansatz.draw("mpl")
Note that in the generated ansatz, all consecutive single-qubit gates are collapsed into the same ZXZ block, and all consecutive two-qubit gates are collapsed into a single KAK block, up to single-qubit rotations.
Further, the
generate_ansatz_from_circuit()
function provides parameters which, when bound to the ansatz, will result in a circuit equivalent to the original one, up to a global phase:ansatz.assign_parameters(initial_params).draw("mpl")