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

simplify the query implementation #121

Merged
merged 6 commits into from
Jun 5, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: 'nightly'
version: '1'
- uses: julia-actions/julia-buildpkg@latest
- name: install dependencies
run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkCI@0.1"'
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# News

## v0.4.1 - 2024-06-05

- Significant improvements to the performance of `query`.

## v0.4.0 - 2024-06-03

- Establishing `ProtocolZoo`, `CircuitZoo`, and `StateZoo`
- Establishing `Register`, `RegRef`, and `RegisterNet`
- Establishing the symbolic expression capabilities
- Establishing plotting and visualization capabilities
- Establishing plotting and visualization capabilities

## older versions were not tracked
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumSavory"
uuid = "2de2e421-972c-4cb5-a0c3-999c85908079"
authors = ["Stefan Krastanov <stefan@krastanov.org>"]
version = "0.4.0"
version = "0.4.1"

[deps]
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
Expand Down
56 changes: 42 additions & 14 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using BenchmarkTools
using Pkg
using StableRNGs
using QuantumSavory
using QuantumSavory.ProtocolZoo
using QuantumSavory: tag_types
using QuantumOpticsBase: Ket, Operator
using QuantumClifford: MixedDestabilizer
Expand Down Expand Up @@ -98,28 +99,55 @@ function tagquery_interfacetest()
tag!(r[2], :symbol1, 4, 5)
tag!(r[5], Int, 4, 5)

@assert Tag(:symbol1, 2, 3) == tag_types.SymbolIntInt(:symbol1, 2, 3)
@assert query(r, :symbol1, 4, ❓) == (slot=r[2], tag=tag_types.SymbolIntInt(:symbol1, 4, 5))
@assert query(r, :symbol1, 4, 5) == (slot=r[2], tag=tag_types.SymbolIntInt(:symbol1, 4, 5))
@assert query(r, :symbol1, ❓, ❓) == (slot=r[1], tag=tag_types.SymbolIntInt(:symbol1, 2, 3))
@assert Tag(:symbol1, 2, 3) == Tag(:symbol1, 2, 3)
@assert query(r, :symbol1, 4, ❓).tag == Tag(:symbol1, 4, 5)
@assert query(r, :symbol1, 4, 5).tag == Tag(:symbol1, 4, 5)
@assert query(r, :symbol1, ❓, ❓).tag == Tag(:symbol1, 4, 5)
@assert query(r, :symbol2, ❓, ❓) == nothing
@assert query(r, Int, 4, 5) == (slot=r[5], tag=tag_types.TypeIntInt(Int, 4, 5))
@assert query(r, Int, 4, 5).tag == Tag(Int, 4, 5)
@assert query(r, Float32, 4, 5) == nothing
@assert query(r, Int, 4, >(5)) == nothing
@assert query(r, Int, 4, <(6)) == (slot=r[5], tag=tag_types.TypeIntInt(Int, 4, 5))
@assert query(r, Int, 4, <(6)).tag == Tag(Int, 4, 5)

@assert queryall(r, :symbol1, ❓, ❓) == [(slot=r[1], tag=tag_types.SymbolIntInt(:symbol1, 2, 3)), (slot=r[2], tag=tag_types.SymbolIntInt(:symbol1, 4, 5))]
@assert [r.tag for r in queryall(r, :symbol1, ❓, ❓)] == [Tag(:symbol1, 4, 5),Tag(:symbol1, 2, 3)]
@assert isempty(queryall(r, :symbol2, ❓, ❓))

@assert query(r[2], Tag(:symbol1, 4, 5)) == (depth=1, tag=Tag(:symbol1, 4, 5))
@assert queryall(r[2], Tag(:symbol1, 4, 5)) == [(depth=1, tag=Tag(:symbol1, 4, 5))]
@assert query(r[2], :symbol1, 4, 5) == (depth=1, tag=Tag(:symbol1, 4, 5))
@assert queryall(r[2], :symbol1, 4, 5) == [(depth=1, tag=Tag(:symbol1, 4, 5))]
@assert query(r[2], Tag(:symbol1, 4, 5)).tag == Tag(:symbol1, 4, 5)
@assert [r.tag for r in queryall(r[2], Tag(:symbol1, 4, 5))] == [Tag(:symbol1, 4, 5)]
@assert query(r[2], :symbol1, 4, 5).tag == Tag(:symbol1, 4, 5)
@assert [r.tag for r in queryall(r[2], :symbol1, 4, 5)] == [Tag(:symbol1, 4, 5)]

@assert query(r[2], :symbol1, 4, ❓) == (depth=1, tag=Tag(:symbol1, 4, 5))
@assert queryall(r[2], :symbol1, 4, ❓) == [(depth=1, tag=Tag(:symbol1, 4, 5))]
@assert query(r[2], :symbol1, 4, ❓).tag == Tag(:symbol1, 4, 5)
@assert [r.tag for r in queryall(r[2], :symbol1, 4, ❓)] == [Tag(:symbol1, 4, 5)]

@assert querydelete!(r[2], :symbol1, 4, ❓) == Tag(:symbol1, 4, 5)
@assert querydelete!(r[2], :symbol1, 4, ❓).tag == Tag(:symbol1, 4, 5)
@assert querydelete!(r[2], :symbol1, 4, ❓) === nothing
end
SUITE["tagquery"]["misc"]["from_tests"] = @benchmarkable tagquery_interfacetest()

SUITE["tagquery"]["register"] = BenchmarkGroup(["register"])
reg = Register(5)
tag!(reg[3], EntanglementCounterpart, 1, 10)
tag!(reg[3], EntanglementCounterpart, 2, 21)
tag!(reg[3], EntanglementCounterpart, 3, 30)
tag!(reg[3], EntanglementCounterpart, 2, 22)
tag!(reg[3], EntanglementCounterpart, 1, 10)
tag!(reg[3], EntanglementCounterpart, 6, 60)
tag!(reg[3], EntanglementCounterpart, 2, 23)
tag!(reg[3], EntanglementCounterpart, 1, 10)
SUITE["tagquery"]["register"]["query"] = @benchmarkable @benchmark query(reg, EntanglementCounterpart, 6, ❓; filo=true)
SUITE["tagquery"]["register"]["queryall"] = @benchmarkable @benchmark queryall(reg, EntanglementCounterpart, 6, ❓; filo=true)

SUITE["tagquery"]["messagebuffer"] = BenchmarkGroup(["messagebuffer"])
net = RegisterNet([Register(3), Register(2), Register(3)])
mb = messagebuffer(net, 2)
put!(mb, Tag(EntanglementCounterpart, 1, 10))
put!(mb, Tag(EntanglementCounterpart, 2, 21))
put!(mb, Tag(EntanglementCounterpart, 3, 30))
put!(mb, Tag(EntanglementCounterpart, 2, 22))
put!(mb, Tag(EntanglementCounterpart, 1, 10))
put!(mb, Tag(EntanglementCounterpart, 6, 60))
put!(mb, Tag(EntanglementCounterpart, 2, 23))
put!(mb, Tag(EntanglementCounterpart, 1, 10))
SUITE["tagquery"]["messagebuffer"]["query"] = @benchmarkable query(mb, EntanglementCounterpart, 6, ❓)
SUITE["tagquery"]["messagebuffer"]["querydelete"] = @benchmarkable querydelete!(_mb, EntanglementCounterpart, 6, ❓) setup=(_mb = deepcopy(mb)) evals=1
7 changes: 2 additions & 5 deletions docs/src/tag_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ One can also query by "lock" and "assignment" status of a given slot, by using t
Following is a detailed description of each `query` method

```@docs; canonical=false
query(::Register,::Tag)
query(::RegRef,::Tag)
query(::MessageBuffer,::Tag)
query
```

### Wildcards
Expand All @@ -63,8 +61,7 @@ W
A method on top of [`query`](@ref), which allows to query for tag in a [`RegRef`](@ref) or a [`messagebuffer`](@ref), returning the tag that satisfies the passed predicates and wildcars, **and deleting it from the list at the same time**. It otherwise has the same signature as [`query`](@ref).

```@docs; canonical=false
querydelete!(::RegRef)
querydelete!(::MessageBuffer)
querydelete!
```

### `queryall`
Expand Down
2 changes: 2 additions & 0 deletions src/messagebuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function Base.put!(mb::MessageBuffer, tag)
nothing
end

tag!(::MessageBuffer, args...) = throw(ArgumentError("MessageBuffer does not support `tag!`. Use `put!(::MessageBuffer, Tag(...))` instead."))

function Base.put!(reg::Register, tag)
put!(messagebuffer(reg), tag)
end
Expand Down
Loading
Loading