using QuantumInformation
using LinearAlgebra
using Statistics


function teleport(d::Int)
    haar = HaarKet(2)
    Ïˆ = reshuffle(ğ�•€(d))/sqrt(d)
    Ï• = rand(haar)
    had = UnitaryChannel{Matrix{ComplexF64}}(hadamard(d))
    post = [PostSelectionMeasurement(proj(ket(i, d^2)) âŠ— ğ�•€(d)) for i=1:d^2]
    Î¾ = Ï• âŠ— Ïˆ
    Ï� = ((had âŠ— IdentityChannel(4))âˆ˜(cnot âŠ— IdentityChannel(2))âˆ˜(IdentityChannel(4) âŠ— Î¦(Î³)))(Î¾)
    for j=1:d
        Ïƒ = rots[j](ptrace(post[j](Ï�), [2, 2, 2], [1, 2]))
        r[i, k, j] = fidelity(Ï•, Ïƒ/tr(Ïƒ))
    end
end



rots = [UnitaryChannel(ğ�•€(2)), UnitaryChannel(sx), UnitaryChannel(sz), UnitaryChannel(sx*sz)]
cnot = UnitaryChannel{Matrix{ComplexF64}}([1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0])
r = zeros(steps, length(Î³s), 4)
mean(r, dims=1)
