# Retrouver les deux angles θ et φ d'un état, puis reconstruire l'état à partir d'eux
import cmath

import numpy as np
from common import bloch_angles
from qsim.etape1_un_qubit import make_state

state = make_state(0.6, 0.8j)
theta, phi = bloch_angles(state)
print("θ =", round(theta, 3), "  φ =", round(phi, 3))
print("cos(θ/2) =", round(np.cos(theta / 2), 3), "  sin(θ/2) =", round(np.sin(theta / 2), 3))

rebuilt = make_state(np.cos(theta / 2), cmath.exp(1j * phi) * np.sin(theta / 2))
print("même vecteur :", np.allclose(rebuilt, state))
