# Exercice 1 : un qubit préparé dans |1⟩, T1 = 150 µs, 30 µs d'attente
import numpy as np
from qiskit import QuantumCircuit
from qiskit_aer.noise import thermal_relaxation_error
from qiskit_aer.primitives import SamplerV2 as AerSampler

T1, T2 = 150e-6, 100e-6
wait = 30e-6
SHOTS = 2000

qc = QuantumCircuit(1)
qc.x(0)
qc.append(thermal_relaxation_error(T1, T2, wait).to_instruction(), [0])
qc.measure_all()

counts = AerSampler(seed=42).run([qc], shots=SHOTS).result()[0].data.meas.get_counts()
print("Counts :", dict(sorted(counts.items())))
print("P(1) mesurée :", round(counts.get("1", 0) / SHOTS, 3))
print("exp(-t/T1)   :", round(float(np.exp(-wait / T1)), 3))
