Skip to content

Commit

Permalink
check slot availability after the delay
Browse files Browse the repository at this point in the history
  • Loading branch information
ba2tro committed Nov 5, 2023
1 parent 37cc012 commit 96b6bf2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/quantumchannel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ end

@resumable function post_take(env, take_event, rref)
channel_reg = @yield take_event
QuantumSavory.swap!(channel_reg[1], rref)
if isassigned(rref)
error("A take! operation is being performed on a QuantumChannel in order to swap the state into a Register, but the target register slot is not empty (it is already initialized).")
end
swap!(channel_reg[1], rref)
end

function Base.take!(qc::QuantumChannel, rref::RegRef)
if isassigned(rref)
error("A take! operation is being performed on a QuantumChannel in order to swap the state into a Register, but the target register slot is not empty (it is already initialized).")
end
take_event = take!(qc.queue)
@process post_take(qc.queue.store.env, take_event, rref)
end
11 changes: 10 additions & 1 deletion test/test_quantumchannel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@ uptotime!(reg[1], 10.0)

@test observable(reg[1:2], projector(bell)) == observable(regB[1:2], projector(bell))

@test_throws "A take! operation is being performed on a QuantumChannel in order to swap the state into a Register, but the target register slot is not empty (it is already initialized)." take!(qc, regB[1])
## Test for slot availability

sim = Simulation()
qc = QuantumChannel(sim, 10.0, T2Dephasing(0.1))
regC = Register(1)
initialize!(regC[1], Z1)
put!(qc, regC[1])
take!(qc, regB[1])

@test_throws "A take! operation is being performed on a QuantumChannel in order to swap the state into a Register, but the target register slot is not empty (it is already initialized)." run(sim)

0 comments on commit 96b6bf2

Please sign in to comment.