# Le point de Bloch de |+⟩ pendant l'attente : il quitte la surface de la sphère
import numpy as np
from qiskit.quantum_info import DensityMatrix, Pauli
from qiskit_aer.noise import thermal_relaxation_error

T1 = 100e-6  # 100 µs
T2 = 80e-6  # 80 µs

start = DensityMatrix.from_label("+")  # point (1, 0, 0) de la sphère

print("attente    x       y       z     longueur")
for wait_us in [0, 25, 50, 100, 200, 400, 1000]:
    state = start
    if wait_us > 0:
        channel = thermal_relaxation_error(T1, T2, wait_us * 1e-6).to_quantumchannel()
        state = start.evolve(channel)
    vector = [float(state.expectation_value(Pauli(p)).real) for p in "XYZ"]
    length = float(np.linalg.norm(vector))
    # arrondi, puis + 0.0 : évite d'afficher -0.000 pour un résidu de calcul
    x, y, z, length = (round(v, 3) + 0.0 for v in [*vector, length])
    print(f"{wait_us:>4} µs  {x:6.3f}  {y:6.3f}  {z:6.3f}  {length:6.3f}")
