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

misc CI updates #93

Merged
merged 8 commits into from
Jan 27, 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
11 changes: 1 addition & 10 deletions .github/workflows/ci-julia-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/downgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Downgrade
on:
pull_request:
branches: [master, main]
paths-ignore:
- 'docs/**'
push:
branches: [master, main]
paths-ignore:
- 'docs/**'
env:
PYTHON: ~
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['1.9']
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
- uses: cjdoris/julia-downgrade-compat-action@v1
with:
skip: Pkg,TOML,InteractiveUtils,Random,LinearAlgebra
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
7 changes: 7 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
QuantumClifford = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c"
QuantumOpticsBase = "4f57444f-1401-5e15-980d-4471b28d5678"
QuantumSavory = "2de2e421-972c-4cb5-a0c3-999c85908079"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
125 changes: 125 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using BenchmarkTools
using Pkg
using StableRNGs
using QuantumSavory
using QuantumSavory: tag_types
using QuantumOpticsBase: Ket, Operator
using QuantumClifford: MixedDestabilizer

const SUITE = BenchmarkGroup()

rng = StableRNG(42)

M = Pkg.Operations.Context().env.manifest
V = M[findfirst(v -> v.name == "QuantumSavory", M)].version

SUITE["register"] = BenchmarkGroup(["register"])
SUITE["register"]["creation_and_initialization"] = BenchmarkGroup(["creation_and_initialization"])
function register_creation_and_initialization()
traits = [Qubit(), Qubit(), Qubit()]
reg1 = Register(traits)
qc_repr = [QuantumOpticsRepr(), CliffordRepr(), CliffordRepr()]
reg2 = Register(traits, qc_repr)
qmc_repr = [QuantumOpticsRepr(), QuantumMCRepr(), QuantumMCRepr()]
reg3 = Register(traits, qmc_repr)
net = RegisterNet([reg1, reg2, reg3])

i = 1
initialize!(net[i,2])
@assert nsubsystems(net[i].staterefs[2]) == 1
initialize!(net[i,3],X1)
@assert nsubsystems(net[i].staterefs[2]) == 1
apply!([net[i,2], net[i,3]], CNOT)
@assert net[i].staterefs[2].state[] isa Ket
@assert nsubsystems(net[i].staterefs[2]) == 2

i = 2
initialize!(net[i,2])
@assert nsubsystems(net[i].staterefs[2]) == 1
initialize!(net[i,3],X1)
@assert nsubsystems(net[i].staterefs[2]) == 1
apply!([net[i,2], net[i,3]], CNOT)
@assert net[i].staterefs[2].state[] isa MixedDestabilizer
@assert nsubsystems(net[i].staterefs[2]) == 2

i = 3
initialize!(net[i,2])
@assert nsubsystems(net[i].staterefs[2]) == 1
initialize!(net[i,3],X1)
@assert nsubsystems(net[i].staterefs[2]) == 1
apply!([net[i,2], net[i,3]], CNOT)
@assert net[i].staterefs[2].state[] isa Ket
@assert nsubsystems(net[i].staterefs[2]) == 2

##
# with backgrounds
traits = [Qubit(), Qubit(), Qubit()]
backgrounds = [T2Dephasing(1.0),T2Dephasing(1.0),T2Dephasing(1.0)]
reg1 = Register(traits, backgrounds)
qc_repr = [QuantumOpticsRepr(), CliffordRepr(), CliffordRepr()]
reg2 = Register(traits, qc_repr, backgrounds)
qmc_repr = [QuantumOpticsRepr(), QuantumMCRepr(), QuantumMCRepr()]
reg3 = Register(traits, qmc_repr, backgrounds)
net = RegisterNet([reg1, reg2, reg3])

i = 1
initialize!(net[i,2], time=1.0)
@assert nsubsystems(net[i].staterefs[2]) == 1
initialize!(net[i,3],X1, time=2.0)
@assert nsubsystems(net[i].staterefs[2]) == 1
apply!([net[i,2], net[i,3]], CNOT, time=3.0)
@assert net[i].staterefs[2].state[] isa Operator
@assert nsubsystems(net[i].staterefs[2]) == 2

i = 2
initialize!(net[i,2], time=1.0)
@assert nsubsystems(net[i].staterefs[2]) == 1
initialize!(net[i,3],X1, time=2.0)
@assert nsubsystems(net[i].staterefs[2]) == 1
apply!([net[i,2], net[i,3]], CNOT, time=3.0)
@assert net[i].staterefs[2].state[] isa MixedDestabilizer
@assert nsubsystems(net[i].staterefs[2]) == 2

i = 3
initialize!(net[i,2], time=1.0)
@assert nsubsystems(net[i].staterefs[2]) == 1
initialize!(net[i,3],X1, time=2.0)
@assert nsubsystems(net[i].staterefs[2]) == 1
apply!([net[i,2], net[i,3]], CNOT, time=3.0)
@assert nsubsystems(net[i].staterefs[2]) == 2
end
SUITE["register"]["creation_and_initialization"]["from_tests"] = @benchmarkable register_creation_and_initialization()

SUITE["tagquery"] = BenchmarkGroup(["tagquery"])
SUITE["tagquery"]["misc"] = BenchmarkGroup(["misc"])
function tagquery_interfacetest()
r = Register(10)
tag!(r[1], :symbol1, 2, 3)
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 query(r, :symbol2, ❓, ❓) == nothing
@assert query(r, Int, 4, 5) == (slot=r[5], tag=tag_types.TypeIntInt(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 queryall(r, :symbol1, ❓, ❓) == [(slot=r[1], tag=tag_types.SymbolIntInt(:symbol1, 2, 3)), (slot=r[2], tag=tag_types.SymbolIntInt(:symbol1, 4, 5))]
@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], :symbol1, 4, ❓) == (depth=1, tag=Tag(:symbol1, 4, 5))
@assert queryall(r[2], :symbol1, 4, ❓) == [(depth=1, tag=Tag(:symbol1, 4, 5))]

@assert querydelete!(r[2], :symbol1, 4, ❓) == Tag(:symbol1, 4, 5)
@assert querydelete!(r[2], :symbol1, 4, ❓) === nothing
end
SUITE["tagquery"]["misc"]["from_tests"] = @benchmarkable tagquery_interfacetest()
4 changes: 2 additions & 2 deletions src/queries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ for (tagsymbol, tagvariant) in pairs(tag_types)
sig_wild = collect(sig)
sig_wild[idx] .= Union{Wildcard,Function}
argssig_wild = [:($a::$t) for (a,t) in zip(args, sig_wild)]
wild_checks = [:(isa($(args[i]),Wildcard) || $(args[i])(tag.data[$i])) for i in idx]
nonwild_checks = [:(tag.data[$i]==$(args[i])) for i in complement_idx]
wild_checks = [:(isa($(args[i]),Wildcard) || $(args[i])(tag[$i])) for i in idx]
nonwild_checks = [:(tag[$i]==$(args[i])) for i in complement_idx]
newmethod_reg = quote function query(reg::Register, $(argssig_wild...), ::Val{allB}=Val{false}(); locked::Union{Nothing,Bool}=nothing, assigned::Union{Nothing,Bool}=nothing) where {allB}
res = NamedTuple{(:slot, :tag), Tuple{RegRef, Tag}}[]
for (reg_idx, tags) in enumerate(reg.tags)
Expand Down
6 changes: 3 additions & 3 deletions src/tags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ end
See also: [`query`](@ref), [`tag!`](@ref), [`Wildcard`](@ref)"""
const tag_types = Tag'

Base.getindex(tag::Tag, i::Int) = tag.data[i]
Base.length(tag::Tag) = length(tag.data.data)
Base.iterate(tag::Tag, state=1) = state > length(tag) ? nothing : (tag[state],state+1)
Base.getindex(tag::Tag, i::Int) = SumTypes.unwrap(tag)[i]
Base.length(tag::Tag) = length(SumTypes.unwrap(tag).data)
Base.iterate(tag::Tag, state=1) = state > length(tag) ? nothing : (SumTypes.unwrap(tag)[state],state+1)

function SumTypes.show_sumtype(io::IO, x::Tag)
data = SumTypes.unwrap(x)
Expand Down
7 changes: 7 additions & 0 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ end
end
end

@safetestset "firstgenrepeater_v2" begin
if get(ENV,"QUANTUMSAVORY_PLOT_TEST","")=="true"
include("../examples/firstgenrepeater_v2/1_entangler_example.jl")
include("../examples/firstgenrepeater_v2/2_swapper_example.jl")
end
end

@safetestset "colorcentermodularcluster" begin
include("../examples/colorcentermodularcluster/1_time_to_connected.jl")
if get(ENV,"QUANTUMSAVORY_PLOT_TEST","")=="true"
Expand Down
Loading