Skip to content

Commit

Permalink
Resolve and test for method ambiguities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Jul 3, 2022
1 parent 910d215 commit 1e5bef2
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci-julia-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ jobs:
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- run: |
julia --project=@. -e '
using Pkg
Pkg.add(PackageSpec(name="JET", rev="master"))'
- uses: julia-actions/julia-runtest@v1
env:
JULIA_NUM_THREADS: ${{ matrix.threads }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
version:
- '1.7'
- '1.6'
- '1'
os:
- ubuntu-latest
threads:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# News

## v0.5.4-dev
## v0.5.4 - 2022-07-03

- Start using `JET.jl` for static analysis during CI.
- The `MixedDestabilizer` constructor now accepts over redundant tableaux (tableaux with redundant rows).
- Resolved multiple method ambiguities and started testing for them with `Aqua.jl` in CI.

## v0.5.3 - 2022-06-11

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumClifford"
uuid = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
authors = ["Stefan Krastanov <stefan@krastanov.org>"]
version = "0.5.3"
version = "0.5.4"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Krastanov/QuantumClifford.jl/CI)](https://github.com/Krastanov/QuantumClifford.jl/actions?query=workflow%3ACI+branch%3Amaster)
[![Test coverage from codecov](https://img.shields.io/codecov/c/gh/Krastanov/QuantumClifford.jl?label=codecov)](https://codecov.io/gh/Krastanov/QuantumClifford.jl)
[![PkgEval](https://juliahub.com/docs/QuantumClifford/pkgeval.svg)](https://juliahub.com/ui/Packages/QuantumClifford/BsGZO)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
<!--[![Build status](https://api.travis-ci.com/Krastanov/QuantumClifford.jl.svg?branch=master)](https://travis-ci.com/Krastanov/QuantumClifford.jl)-->
<!--[![Test coverage from coveralls](https://img.shields.io/coveralls/github/Krastanov/QuantumClifford.jl?label=coveralls)](https://coveralls.io/r/Krastanov/QuantumClifford.jl?branch=master)-->

Expand Down
14 changes: 10 additions & 4 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ Base.copy(p::PauliOperator) = PauliOperator(copy(p.phase),p.nqubits,copy(p.xz))
# Stabilizers
##############################

abstract type AbstractQCState end
abstract type AbstractQCState end # This could include classical bits

abstract type AbstractStabilizer <: AbstractQCState end
abstract type AbstractStabilizer <: AbstractQCState end # This includs only qubits

"""
Stabilizer, i.e. a list of commuting multi-qubit Hermitian Pauli operators.
Expand Down Expand Up @@ -323,7 +323,13 @@ macro S_str(a)
end

Base.getindex(stab::Stabilizer, i::Int) = PauliOperator(stab.phases[i], nqubits(stab), stab.xzs[:,i])
@inline Base.getindex(stab::Stabilizer{Tzv,Tm}, r::Int, c::Int) where {Tzv<:AbstractVector{UInt8}, Tme<:Unsigned, Tm<:AbstractMatrix{Tme}} = (stab.xzs[_div(Tme,c-1)+1,r] & Tme(0x1)<<_mod(Tme,c-1))!=0x0, (stab.xzs[end÷2+_div(Tme,c-1)+1,r] & Tme(0x1)<<_mod(Tme,c-1))!=0x0 # TODO this has code repetition with the Pauli getindex
@inline function Base.getindex(stab::Stabilizer, r::Int, c::Int)
# TODO this has code repetition with the Pauli getindex
Tme = eltype(stab.xzs)
x = (stab.xzs[_div(Tme,c-1)+1,r] & Tme(0x1)<<_mod(Tme,c-1))!=0x0
z = (stab.xzs[end÷2+_div(Tme,c-1)+1,r] & Tme(0x1)<<_mod(Tme,c-1))!=0x0
return (x,z)
end
Base.getindex(stab::Stabilizer, r) = Stabilizer(stab.phases[r], nqubits(stab), stab.xzs[:,r])
Base.getindex(stab::Stabilizer, r, c) = Stabilizer([s[c] for s in stab[r]])
Base.getindex(stab::Stabilizer, r, c::Int) = stab[r,[c]]
Expand Down Expand Up @@ -828,7 +834,7 @@ end

()(l::PauliOperator, r::PauliOperator) = PauliOperator((l.phase[]+r.phase[])&0x3, vcat(xbit(l),xbit(r)), vcat(zbit(l),zbit(r)))

function Base.:(*)(l, r::PauliOperator)
function Base.:(*)(l::Number, r::PauliOperator)
p = copy(r)
if l==1
nothing
Expand Down
14 changes: 7 additions & 7 deletions src/experimental/NoisyCircuits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module NoisyCircuits
#TODO permit the use of alternative RNGs

using QuantumClifford
using QuantumClifford: AbstractQCState, AbstractOperation, AbstractMeasurement, AbstractCliffordOperator, apply_single_x!, apply_single_y!, apply_single_z!
using QuantumClifford: AbstractQCState, AbstractStabilizer, AbstractOperation, AbstractMeasurement, AbstractCliffordOperator, apply_single_x!, apply_single_y!, apply_single_z!

using Combinatorics: combinations

Expand Down Expand Up @@ -100,7 +100,7 @@ affectedqubits(d::DecisionGate) = [(union(affectedqubits.(d.gates))...)...]
affectedqubits(m::AbstractMeasurement) = [m.qubit]


function QuantumClifford.apply!(s::AbstractQCState, g::NoisyGate)
function QuantumClifford.apply!(s::AbstractStabilizer, g::NoisyGate)
s = applynoise!(
apply!(s,g.gate),
g.noise,
Expand Down Expand Up @@ -136,7 +136,7 @@ end
"""A method modifying a given state by applying the corresponding noise model. Non-deterministic, part of the Noise interface."""
function applynoise! end

function applynoise!(s::AbstractQCState,noise::UnbiasedUncorrelatedNoise,indices::AbstractVector{Int})
function applynoise!(s::AbstractStabilizer,noise::UnbiasedUncorrelatedNoise,indices::AbstractVector{Int})
n = nqubits(s)
infid = noise.errprobthird
for i in indices
Expand All @@ -154,17 +154,17 @@ function applynoise!(s::AbstractQCState,noise::UnbiasedUncorrelatedNoise,indices
s
end

function QuantumClifford.apply!(s::AbstractQCState, mr::NoiseOpAll)
function QuantumClifford.apply!(s::AbstractStabilizer, mr::NoiseOpAll)
n = nqubits(s)
return applynoise!(s, mr.noise, 1:n)
end

function QuantumClifford.apply!(s::AbstractQCState, mr::NoiseOp)
function QuantumClifford.apply!(s::AbstractStabilizer, mr::NoiseOp)
return applynoise!(s, mr.noise, affectedqubits(mr))
end

# TODO this one needs more testing
function applywstatus!(s::AbstractQCState, v::VerifyOp) # XXX It assumes the other qubits are measured or traced out
function applywstatus!(s::AbstractStabilizer, v::VerifyOp) # XXX It assumes the other qubits are measured or traced out
# TODO QuantumClifford should implement some submatrix comparison
canonicalize_rref!(quantumstate(s),v.indices) # Document why rref is used
sv = stabilizerview(s)
Expand Down Expand Up @@ -246,7 +246,7 @@ end
"""Compute all possible new states after the application of the given noise model. Reports the probability of each one of them. Deterministic, part of the Noise interface."""
function applynoise_branches end

function applynoise_branches(s::AbstractQCState,noise::UnbiasedUncorrelatedNoise,indices::AbstractVector{Int}; max_order=1)
function applynoise_branches(s::AbstractStabilizer,noise::UnbiasedUncorrelatedNoise,indices::AbstractVector{Int}; max_order=1)
n = nqubits(s)
l = length(indices)
infid = noise.errprobthird
Expand Down
2 changes: 2 additions & 0 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ function tensor_pow(op,power)
end
end

function () zero(Stabilizer, 0, 0) end # defined to avoid method ambiguities (can be tested with Aqua.jl)

function (ops::Stabilizer...)
length(ops)==1 && return ops[1]
ntot = sum(nqubits, ops)
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ doset("allocations") && VERSION >= v"1.7" && include("./test_allocations.
doset("doctests") && VERSION == v"1.7" && include("./doctests.jl")

using Aqua
doset("aqua") && Aqua.test_all(QuantumClifford, ambiguities=false,project_toml_formatting=false)
doset("aqua") && begin
Aqua.test_all(QuantumClifford, ambiguities=false)
Aqua.test_ambiguities([QuantumClifford,Core]) # otherwise Base causes false positives
end

2 comments on commit 1e5bef2

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release Notes:

  • Start using JET.jl for static analysis during CI.
  • The MixedDestabilizer constructor now accepts over redundant tableaux (tableaux with redundant rows).
  • Resolved multiple method ambiguities and started testing for them with Aqua.jl in CI.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/63579

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.4 -m "<description of version>" 1e5bef249d9a8ceed38c642bac667b5d96fa93ef
git push origin v0.5.4

Please sign in to comment.