Skip to content

Commit

Permalink
Fix origin of run_multiple issue by returning copies of sv/dm as ap…
Browse files Browse the repository at this point in the history
…propriate (#33)
  • Loading branch information
kshyatt-aws authored Jul 5, 2024
1 parent 458596c commit 4127749
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/BraketSimulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ end
n_task_threads = min(max_parallel_threads, n_tasks)

results = Vector{Braket.GateModelTaskResult}(undef, n_tasks)
function process_work()
my_sim = copy(simulator)
function process_work(my_sim)
while isready(todo_tasks_ch)
my_ix = -1
# need to lock the channel as it may become empty
Expand All @@ -374,7 +373,7 @@ end
tasks = Vector{Task}(undef, n_task_threads)
# need sync here to ensure all the spawns launch
@sync for worker in 1:n_task_threads
tasks[worker] = Threads.@spawn process_work()
tasks[worker] = Threads.@spawn process_work(similar(simulator))
end
# tasks don't return anything so we can wait rather than fetch
wait.(tasks)
Expand Down
2 changes: 1 addition & 1 deletion src/dm_simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function expectation(
return real(sum(diag(dm_copy)))
end
state_vector(dms::DensityMatrixSimulator) = diag(dms.density_matrix)
density_matrix(dms::DensityMatrixSimulator) = dms.density_matrix
density_matrix(dms::DensityMatrixSimulator) = copy(dms.density_matrix)
probabilities(dms::DensityMatrixSimulator) = real.(diag(dms.density_matrix))

function swap_bits(ix::Int, qubit_map::Dict{Int,Int})
Expand Down
2 changes: 1 addition & 1 deletion src/sv_simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function evolve!(
return svs
end

state_vector(svs::StateVectorSimulator) = svs.state_vector
state_vector(svs::StateVectorSimulator) = copy(svs.state_vector)
density_matrix(svs::StateVectorSimulator) =
kron(svs.state_vector, adjoint(svs.state_vector))

Expand Down

0 comments on commit 4127749

Please sign in to comment.