Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kron and repeat over unitary channel #482

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/YaoBlocks/src/channel/unitary_channel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function YaoAPI.unsafe_apply!(r::DensityMatrix{D,T},
for (locs, block) in zip(k.locs, k.blocks)
YaoAPI.unsafe_apply!(r, put(k.n, locs => block))
end
return r
end

function mat(::Type{T}, x::UnitaryChannel) where {T}
Expand Down
3 changes: 1 addition & 2 deletions lib/YaoBlocks/src/composite/repeated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ mat(::Type{T}, rb::RepeatedBlock{D}) where {T,D} =
mat(::Type{T}, rb::RepeatedBlock{D,0,GT}) where {T,D,GT} = IMatrix{T}(D^nqudits(rb))

function YaoAPI.unsafe_apply!(r::AbstractRegister, rp::RepeatedBlock)
m = mat_matchreg(r, rp.content)
for addr in rp.locs
instruct!(r, m, Tuple(addr:addr+nqudits(rp.content)-1))
YaoAPI.unsafe_apply!(r, put(nqudits(rp), addr:addr+nqudits(rp.content)-1=>rp.content))
end
return r
end
Expand Down
12 changes: 11 additions & 1 deletion lib/YaoBlocks/test/channel/unitary_channel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ end
ops = unitary_channel([put(2, 1=>chain(Rx(0.4), Ry(0.5), Rz(0.4))), put(2,2=>Y), put(2,1=>Z)], [0.3, 0.1, 0.6])
channel2 = put(6, (2,3)=>ops)
@test apply(r, channel1) ≈ apply(r, channel2)
end
end

@testset "kron and repeat" begin
dm = density_matrix(ghz_state(5), 1:3)
dpolarizing = single_qubit_depolarizing_channel(0.1)
dmkron = apply(dm, kron(3, 1=>dpolarizing, 2=>dpolarizing))
dmrepeat = apply(dm, repeat(3, dpolarizing, (1, 2)))
dmput = apply(apply(dm, put(3, 1=>dpolarizing)), put(3, 2=>dpolarizing))
@test dmkron ≈ dmrepeat
@test dmkron ≈ dmput
end
Loading