Skip to content

Commit

Permalink
fix kron and repeat over unitary channel
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Oct 7, 2023
1 parent 2db9961 commit 207570e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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

0 comments on commit 207570e

Please sign in to comment.