diff --git a/src/ProtocolZoo/ProtocolZoo.jl b/src/ProtocolZoo/ProtocolZoo.jl index c661e511..dee968ac 100644 --- a/src/ProtocolZoo/ProtocolZoo.jl +++ b/src/ProtocolZoo/ProtocolZoo.jl @@ -24,7 +24,7 @@ export abstract type AbstractProtocol end -get_time_tracker(prot::AbstractProtocol) = prot.sim +get_time_tracker(prot::AbstractProtocol) = prot.sim::Simulation Process(prot::AbstractProtocol, args...; kwargs...) = Process((e,a...;k...)->prot(a...;k...), get_time_tracker(prot), args...; kwargs...) @@ -204,15 +204,19 @@ end while rounds != 0 isentangled = !isnothing(query(prot.net[prot.nodeA], EntanglementCounterpart, prot.nodeB, ❓; assigned=true)) margin = isentangled ? prot.margin : prot.hardmargin - a = findfreeslot(prot.net[prot.nodeA]; randomize=prot.randomize, margin=margin) - b = findfreeslot(prot.net[prot.nodeB]; randomize=prot.randomize, margin=margin) + a_ = findfreeslot(prot.net[prot.nodeA]; randomize=prot.randomize, margin=margin) + b_ = findfreeslot(prot.net[prot.nodeB]; randomize=prot.randomize, margin=margin) - if isnothing(a) || isnothing(b) + if isnothing(a_) || isnothing(b_) isnothing(prot.retry_lock_time) && error("We do not yet support waiting on register to make qubits available") # TODO - @debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a \n2.\t $b \n retrying..." + @debug "EntanglerProt between $(prot.nodeA) and $(prot.nodeB)|round $(round): Failed to find free slots. \nGot:\n1. \t $a_ \n2.\t $b_ \n retrying..." @yield timeout(prot.sim, prot.retry_lock_time) continue end + # we are now certain that a_ and b_ are not nothing. The compiler is not smart enough to figure this out + # on its own, so we need to tell it explicitly. A new variable name is needed due to @resumable. + a = a_::RegRef + b = b_::RegRef @yield lock(a) & lock(b) # this yield is expected to return immediately diff --git a/src/ProtocolZoo/swapping.jl b/src/ProtocolZoo/swapping.jl index fec23c85..e7330604 100644 --- a/src/ProtocolZoo/swapping.jl +++ b/src/ProtocolZoo/swapping.jl @@ -66,12 +66,14 @@ end rounds = prot.rounds round = 1 while rounds != 0 - qubit_pair = findswapablequbits(prot.net, prot.node, prot.nodeL, prot.nodeH, prot.chooseL, prot.chooseH; agelimit=prot.agelimit) - if isnothing(qubit_pair) + qubit_pair_ = findswapablequbits(prot.net, prot.node, prot.nodeL, prot.nodeH, prot.chooseL, prot.chooseH; agelimit=prot.agelimit) + if isnothing(qubit_pair_) isnothing(prot.retry_lock_time) && error("We do not yet support waiting on register to make qubits available") # TODO @yield timeout(prot.sim, prot.retry_lock_time) continue end + # The compiler is not smart enough to figure out that qubit_pair_ is not nothing, so we need to tell it explicitly. A new variable name is needed due to @resumable. + qubit_pair = qubit_pair_::NTuple{2, Base.NamedTuple{(:slot, :id, :tag), Base.Tuple{RegRef, Int128, Tag}}} # TODO: replace by `NTuple{2, @NamedTuple{slot::RegRef, id::Int128, tag::Tag}}` once https://github.com/JuliaDynamics/ResumableFunctions.jl/issues/104 is resolved (q1, id1, tag1) = qubit_pair[1].slot, qubit_pair[1].id, qubit_pair[1].tag (q2, id2, tag2) = qubit_pair[2].slot, qubit_pair[2].id, qubit_pair[2].tag diff --git a/src/backends/clifford/should_upstream.jl b/src/backends/clifford/should_upstream.jl index 9f8d2688..7bef8dd7 100644 --- a/src/backends/clifford/should_upstream.jl +++ b/src/backends/clifford/should_upstream.jl @@ -3,7 +3,7 @@ struct QCGateSequence <: QuantumClifford.AbstractSymbolicOperator gates # TODO constructor that flattens nested QCGateSequence end function QuantumClifford.apply!(state::QuantumClifford.MixedDestabilizer, gseq::QCGateSequence, indices) - for g in gseq[end:-1:begin] + for g in gseq.gates[end:-1:begin] apply_popindex!(state, g, indices) end state diff --git a/src/baseops/traceout.jl b/src/baseops/traceout.jl index f8049e67..e3e570f7 100644 --- a/src/baseops/traceout.jl +++ b/src/baseops/traceout.jl @@ -66,7 +66,7 @@ function project_traceout! end function project_traceout!(reg::Register, i::Int, basis; time=nothing) project_traceout!(identity, reg, i, basis; time=time) end -project_traceout!(r::RegRef, basis; time=nothing) = project_traceout!(r.reg, r.idx, basis; time=nothing) +project_traceout!(r::RegRef, basis; time=nothing) = project_traceout!(r.reg, r.idx, basis; time) function project_traceout!(f, reg::Register, i::Int, basis; time=nothing) !isnothing(time) && uptotime!([reg], [i], time) @@ -79,4 +79,4 @@ function project_traceout!(f, reg::Register, i::Int, basis; time=nothing) removebackref!(stateref, stateindex) f(j) end -project_traceout!(f, r::RegRef, basis; time=nothing) = project_traceout!(f, r.reg, r.idx, basis; time=nothing) +project_traceout!(f, r::RegRef, basis; time=nothing) = project_traceout!(f, r.reg, r.idx, basis; time) diff --git a/src/concurrentsim.jl b/src/concurrentsim.jl index c79cacb0..ed96b13f 100644 --- a/src/concurrentsim.jl +++ b/src/concurrentsim.jl @@ -42,7 +42,7 @@ function get_time_tracker(rn::RegisterNet) return get_time_tracker(rn.registers[1]) end function get_time_tracker(r::Register) - r.locks[1].env + r.locks[1].env::Simulation end function get_time_tracker(r::RegRef) get_time_tracker(r.reg) diff --git a/src/states_registers_networks_getset.jl b/src/states_registers_networks_getset.jl index 9bc46658..d8b83156 100644 --- a/src/states_registers_networks_getset.jl +++ b/src/states_registers_networks_getset.jl @@ -8,7 +8,7 @@ Base.iterate(r::Register, state=1) = state > length(r) ? nothing : (r[state],sta ## Networks # Graph interface -Graphs.add_vertex!(net::RegisterNet, a, b) = add_vertex!(net.graph, a, b) +Graphs.add_vertex!(net::RegisterNet) = add_vertex!(net.graph) Graphs.vertices(net::RegisterNet) = vertices(net.graph) Graphs.edges(net::RegisterNet) = edges(net.graph) Graphs.neighbors(net::RegisterNet, v) = neighbors(net.graph, v) @@ -43,8 +43,8 @@ Base.setindex!(net::RegisterNet, val, ij::Graphs.SimpleEdge, k::Symbol) = begin Base.getindex(net::RegisterNet, ::Colon) = net.registers Base.getindex(net::RegisterNet, ::Colon, j::Int) = [r[j] for r in net.registers] Base.getindex(net::RegisterNet, ::Colon, k::Symbol) = [m[k] for m in net.vertex_metadata] -Base.getindex(net::RegisterNet, ::Tuple{Colon,Colon}, k::Symbol) = [net.edge_metadata[minmax(ij)...][k] for ij in edges(net)] -Base.getindex(net::RegisterNet, ::Pair{Colon,Colon}, k::Symbol) = [net.directed_edge_metadata[ij][k] for ij in edges(net)] +Base.getindex(net::RegisterNet, ::Tuple{Colon,Colon}, k::Symbol) = [net.edge_metadata[minmax(Tuple(ij)...)][k] for ij in edges(net)] +Base.getindex(net::RegisterNet, ::Pair{Colon,Colon}, k::Symbol) = [net.directed_edge_metadata[Pair(ij)][k] for ij in edges(net)] function Base.setindex!(net::RegisterNet, v, ::Colon, k::Symbol) for m in net.vertex_metadata diff --git a/test/Project.toml b/test/Project.toml index 744b5544..a00a13b6 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -8,9 +8,11 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" +GraphsMatching = "c3af3a8c-b79e-4b01-bf44-c718d7e0e0d6" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -29,6 +31,7 @@ Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +SumTypes = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2" SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" diff --git a/test/test_jet.jl b/test/test_jet.jl index d29580f5..80f17f4c 100644 --- a/test/test_jet.jl +++ b/test/test_jet.jl @@ -1,6 +1,6 @@ using Test using QuantumSavory, JET -using DiffEqBase, Graphs, JumpProcesses, Makie, ResumableFunctions, ConcurrentSim, QuantumOptics, QuantumOpticsBase, QuantumClifford, Symbolics, WignerSymbols +using DiffEqBase, Graphs, JumpProcesses, Makie, ResumableFunctions, ConcurrentSim, QuantumOptics, QuantumOpticsBase, QuantumClifford, Symbolics, WignerSymbols, GraphsMatching, JuMP, SumTypes rep = report_package("QuantumSavory"; ignored_modules=( @@ -16,10 +16,13 @@ rep = report_package("QuantumSavory"; AnyFrameModule(ResumableFunctions), AnyFrameModule(ConcurrentSim), AnyFrameModule(WignerSymbols), + AnyFrameModule(GraphsMatching), + AnyFrameModule(JuMP.Containers), + AnyFrameModule(SumTypes), )) @show length(JET.get_reports(rep)) @show rep -@test length(JET.get_reports(rep)) <= 85 +@test length(JET.get_reports(rep)) <= 33 @test_broken length(JET.get_reports(rep)) == 0