# Exercice 3 : un état GHZ à trois qubits, réécrit pour une machine Heron
from qiskit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager

qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)

pm = generate_preset_pass_manager(optimization_level=1, basis_gates=["rz", "sx", "x", "cz"])
native = pm.run(qc)

print("Avant :", dict(sorted(qc.count_ops().items())), "soit", qc.size(), "portes")
print("Après :", dict(sorted(native.count_ops().items())), "soit", native.size(), "portes")
two_qubit = native.num_nonlocal_gates()
print("Portes à deux qubits :", two_qubit, "; rz, qui ne coûtent rien :", native.count_ops().get("rz", 0))
