RealAmplitudesAnsatz#
- class pyqit.ansatzes.RealAmplitudesAnsatz(n_qubits: int, n_layers: int = 3, entanglement: str = 'reverse_linear', skip_final_rotation_layer: bool = False)[source]#
Bases:
BaseAnsatzQiskit’s RealAmplitudes: RY layers separated by CX entanglers.
The hardware-efficient ansatz of Kandala et al. 2017 (Nature) as Qiskit’s circuit library builds it, and the default ansatz of Qiskit ML’s VQC. The circuit is Qiskit’s own, converted through the pennylane-qiskit plugin, so it needs the qiskit extra and Python 3.11 or newer.
The weights are Qiskit’s flat parameter vector, weights, of shape (n_qubits * (n_layers + 1),). With skip_final_rotation_layer it is (n_qubits * n_layers,).
- Parameters:
n_qubits (int)
n_layers (int, default 3) – Qiskit’s reps: the number of entangling blocks. Rotation layers number n_layers + 1 unless skip_final_rotation_layer.
entanglement (str, default "reverse_linear") – Any entanglement Qiskit accepts, e.g. “linear”, “full”, “circular”.
skip_final_rotation_layer (bool, default False)
References
Kandala et al., “Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets”, Nature 549, 242 (2017).
Examples
>>> from pyqit.ansatzes import RealAmplitudesAnsatz >>> from pyqit.core import ZZFeatureMap >>> from pyqit.models import VQCClassifier >>> model = VQCClassifier( ... n_qubits=2, ansatz=RealAmplitudesAnsatz, encoder=ZZFeatureMap ... )
- build_circuit(weights)[source]#
Apply the circuit. Expects weights[“weights”] as a flat vector in the order of circuit.parameters.
- get_circuit_func()#
Returns the bound method to be passed to a QNode.