"""Use an asymmetric circuit to inspect bit order and compare Bell coherence."""

from __future__ import annotations

import json

import numpy as np

from cascaqit import Circuit


def experiment() -> dict[str, object]:
    result = (
        Circuit(2).x(0).measure_all().run(shots=16, seed=21, return_probabilities=True)
    )
    bell = np.array([1, 0, 0, 1], dtype=complex) / np.sqrt(2)
    coherent = np.outer(bell, bell.conj())
    mixture = np.diag([0.5, 0.0, 0.0, 0.5])
    x = np.array([[0, 1], [1, 0]])
    xx = np.kron(x, x)
    return {
        "asymmetric_counts": result.counts,
        "bit_order": result.metadata["bitstring_ordering"]["qubit_order"],
        "bell_z_probabilities": np.diag(coherent).real.tolist(),
        "mixture_z_probabilities": np.diag(mixture).tolist(),
        "bell_xx": float(np.trace(coherent @ xx).real),
        "mixture_xx": float(np.trace(mixture @ xx).real),
    }


if __name__ == "__main__":
    print(json.dumps(experiment(), sort_keys=True))
