Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions ext/QuantumCliffordGPUExt/QuantumCliffordGPUExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ include("apply.jl")
include("pauli_frames.jl")
include("fastmemlayout.jl")
include("apply_noise.jl")
include("../../src/throws.jl")

end
2 changes: 1 addition & 1 deletion ext/QuantumCliffordGPUExt/utils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
macro run_cuda(call, ndrange)
# destructure the kernel call
Meta.isexpr(call, :call) || throw(ArgumentError("first argument to @run_cuda should be a function call"))
Meta.isexpr(call, :call) || throw(ArgumentError(THROW_INVALID_CUDA_ARG))
f = call.args[1]
args = call.args[2:end]
args = [esc(x) for x in args]
Expand Down
1 change: 1 addition & 0 deletions ext/QuantumCliffordHeckeExt/QuantumCliffordHeckeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ include("types.jl")
include("lifted.jl")
include("lacross.jl")
include("lifted_product.jl")
include("../../src/throws.jl")

end # module
2 changes: 1 addition & 1 deletion ext/QuantumCliffordHeckeExt/lacross.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct LaCross <: AbstractCSSCode
"""A flag indicating whether to use the full-rank rectangular matrix (`true`) or the original circulant matrix (`false`)."""
full_rank::Bool
function LaCross(n, h, full_rank)
n <= 0 && throw(ArgumentError("Block length must be positive."))
n <= 0 && throw(ArgumentError(THROW_REQUIRED_POSITIVE_ARG))
new(n, h, full_rank)
end
end
Expand Down
6 changes: 3 additions & 3 deletions ext/QuantumCliffordHeckeExt/lifted_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct LPCode <: AbstractECC
repr::Union{Function,Nothing}=nothing
)
if repr !== nothing # override the default A_repr/B_repr (exists for backward compat)
is_commutative(GA) || throw(ArgumentError("The group algebra must be commutative when using a single `repr` function, which is not the case here. Please specify separate `A_repr` and `B_repr` instead of a single `repr`. The default choice of `A_repr=right_repr_matrix, B_repr=left_repr_matrix` is frequently sufficient."))
is_commutative(GA) || throw(ArgumentError(THROW_REPR_NEEDS_COMMUTATIVE_ALGEBRA))
A_repr = B_repr = repr
end
all(elem.parent == GA for elem in A) && all(elem.parent == GA for elem in B) || error("The base rings of all elements in both matrices must be the same as the group algebra")
Expand All @@ -181,7 +181,7 @@ struct LPCode <: AbstractECC
repr::Union{Function,Nothing}=nothing
)
if repr !== nothing # override the default A_repr/B_repr (exists for backward compat)
is_commutative(GA) || throw(ArgumentError("The group algebra must be commutative when using a single `repr` function, which is not the case here. Please specify separate `A_repr` and `B_repr` instead of a single `repr`. The default choice of `A_repr=right_repr_matrix, B_repr=left_repr_matrix` is frequently sufficient."))
is_commutative(GA) || throw(ArgumentError(THROW_REPR_NEEDS_COMMUTATIVE_ALGEBRA))
A_repr = B_repr = repr
end
# We are using the representation function of each lifted code.
Expand Down Expand Up @@ -548,7 +548,7 @@ See also: [`bicycle_codes`](@ref), [`generalized_bicycle_codes`](@ref), [`two_bl
[`honeycomb_color_codes`](@ref).
"""
function honeycomb_color_codes(ℓ::Int, m::Int)
(ℓ % 3 == 0 && m % 3 == 0) || throw(ArgumentError("Both ℓ and m must be divisible by 3"))
(ℓ % 3 == 0 && m % 3 == 0) || throw(ArgumentError(THROW_MUST_BE_DIVISIBLE_BY_3))
GA = group_algebra(GF(2), abelian_group([ℓ, m]))
x, y = gens(GA)
c = 1 + x + x*y
Expand Down
1 change: 1 addition & 0 deletions ext/QuantumCliffordJuMPExt/QuantumCliffordJuMPExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ import ILog2: ilog2, RoundUp
export distance

include("min_distance_mixed_integer_programming.jl")
include("../../src/throws.jl")

end
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ are as follows:
"""
function distance(code::AbstractECC, alg::DistanceMIPAlgorithm)
logical_qubits = isnothing(alg.logical_qubit) ? (1:code_k(code)) : (alg.logical_qubit:alg.logical_qubit)
isnothing(alg.logical_qubit) || (1 <= alg.logical_qubit <= code_k(code)) || throw(ArgumentError("Logical qubit out of range"))
isnothing(alg.logical_qubit) || (1 <= alg.logical_qubit <= code_k(code)) || throw(ArgumentError(THROW_BOUNDS))
# Get the appropriate logical operators and matrices based on operator type
logical_operator_type = alg.logical_operator_type
l, H, h = if logical_operator_type == :X
Expand Down Expand Up @@ -254,11 +254,11 @@ function _minimum_distance(hx, lx, opt, opt_summary, time_limit)
# Ensure the model is solved and feasible
if !is_solved_and_feasible(model)
if termination_status(model) == MOI.MEMORY_LIMIT
throw(ErrorException("Model exceeded memory limits"))
throw(ErrorException(THROW_MODEL_MEMORY_LIMIT))
elseif termination_status(model) == MOI.TIME_LIMIT
throw(ErrorException("Model exceeded time limit"))
throw(ErrorException(THROW_MODEL_TIME_LIMIT))
else
throw(ErrorException("Model failed to solve: $(termination_status(model))"))
throw(ErrorException("Model failed to solve :$(termination_status(model))"))
Copy link
Member

Choose a reason for hiding this comment

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

this seems wrong or maybe I am misunderstanding the change?

end
end
opt_val = sum(value(x[i]) for i in 1:n)
Expand Down
3 changes: 2 additions & 1 deletion ext/QuantumCliffordMakieExt/QuantumCliffordMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module QuantumCliffordMakieExt
using Makie
using QuantumClifford
import QuantumClifford: stabilizerplot, stabilizerplot_axis
include("../../src/throws.jl")

# If you want to directly use heatmap
function Makie.convert_arguments(P::Type{<:Makie.Heatmap}, s::Stabilizer)
Expand Down Expand Up @@ -38,7 +39,7 @@ function Makie.plot!(myplot::StabilizerPlot)
h = QuantumClifford.stab_to_gf2(s)
h[:,1:end÷2] + h[:,end÷2+1:end]*2
else
throw(ErrorException("`xzcomponents` should be `:split` or `:together`"))
throw(ErrorException(THROW_INVALID_XZ_COMPONENTS))
end
r = r[end:-1:1,:]'
hm = Makie.heatmap!(myplot, r;
Expand Down
1 change: 1 addition & 0 deletions ext/QuantumCliffordOscarExt/QuantumCliffordOscarExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ include("types.jl")
include("direct_product.jl")
include("group_presentation.jl")
include("d_dimensional_codes.jl")
include("../../src/throws.jl")

end # module
8 changes: 4 additions & 4 deletions ext/QuantumCliffordOscarExt/d_dimensional_codes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ struct DDimensionalSurfaceCode <: DDimensionalCode
L::Int

function DDimensionalSurfaceCode(D::Int, L::Int)
D ≥ 2 || throw(ArgumentError("Dimension of the Surface code must be at least 2 (got D=$D)."))
D ≥ 2 || throw(ArgumentError(THROW_INVALID_CODE_DIMENSION))
new(D, L)
end
end
Expand Down Expand Up @@ -512,7 +512,7 @@ struct DDimensionalToricCode <: DDimensionalCode
L::Int

function DDimensionalToricCode(D::Int, L::Int)
D ≥ 2 || throw(ArgumentError("Dimension of the Toric code must be at least 2 (got D=$D)."))
D ≥ 2 || throw(ArgumentError(THROW_INVALID_CODE_DIMENSION))
new(D, L)
end
end
Expand Down Expand Up @@ -609,12 +609,12 @@ function code_k(c::DDimensionalCode)
end

function metacheck_matrix_x(c::DDimensionalCode)
c.D ≥ 4 || throw(ArgumentError("`X`-metachecks (`Mx`) require `D ≥ 4` (D=$(c.D))"))
c.D ≥ 4 || throw(ArgumentError(THROW_INVALID_X_METACHECKS))
return Matrix(boundary_maps(c)[4]) # Mx
end

function metacheck_matrix_z(c::DDimensionalCode)
c.D ≥ 3 || throw(ArgumentError("`Z`-metachecks (`Mz`) require `D ≥ 3` (D=$(c.D))"))
c.D ≥ 3 || throw(ArgumentError(THROW_INVALID_Z_METACHECKS))
return Matrix(boundary_maps(c)[1]') # Mz
end

Expand Down
3 changes: 2 additions & 1 deletion ext/QuantumCliffordPlotsExt/QuantumCliffordPlotsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module QuantumCliffordPlotsExt

using Plots
using QuantumClifford
include("../../src/throws.jl")

@recipe function f(s::QuantumClifford.Stabilizer; xzcomponents=:together)
seriestype := :heatmap
Expand All @@ -21,7 +22,7 @@ using QuantumClifford
h = QuantumClifford.stab_to_gf2(s)
h[:,1:end÷2] + h[:,end÷2+1:end]*2
else
throw(ErrorException("`xzcomponents` should be `:split` or `:together`"))
throw(ErrorException(THROW_INVALID_XZ_COMPONENTS))
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/QECCore/src/QECCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ include("codes/quantum/delfosse_reichardt_code.jl")
include("codes/quantum/delfosse_reichardt_repcode.jl")
include("codes/quantum/delfosse_reichardt_823_code.jl")

include("../../../src/throws.jl")

function __init__()
if isdefined(Base.Experimental, :register_error_hint)
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
Expand Down
2 changes: 1 addition & 1 deletion lib/QECCore/src/codes/classical/golay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Golay <: AbstractCECC

function Golay(n)
if !(n in (23, 24))
throw(ArgumentError("Invalid parameters: `n` must be either 24 or 23 to obtain a valid code."))
throw(ArgumentError(THROW_INVALID_PARAMETERS_GOLAY))
end
new(n)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/QECCore/src/codes/classical/hamming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Hamming <: AbstractCECC
r::Int
function Hamming(r)
if r < 2
throw(ArgumentError("Invalid parameters: `r` must be ≥ 2 to obtain a valid code."))
throw(ArgumentError(THROW_INVALID_PARAMETERS_HAMMING))
end
new(r)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/QECCore/src/codes/classical/recursivereedmuller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct RecursiveReedMuller <: AbstractCECC

function RecursiveReedMuller(r, m)
if r < 0 || r > m
throw(ArgumentError("Invalid parameters: r must be non-negative and r ≤ m in order to valid code."))
throw(ArgumentError(THROW_INVALID_PARAMETERS_REEDMULLER))
end
new(r, m)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/QECCore/src/codes/classical/reedmuller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ReedMuller <: AbstractCECC

function ReedMuller(r, m)
if r < 0 || r > m
throw(ArgumentError("Invalid parameters: r must be non-negative and r ≤ m in order to valid code."))
throw(ArgumentError(THROW_INVALID_PARAMETERS_REEDMULLER))
end
new(r, m)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/QECCore/src/codes/quantum/color_codes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ struct Triangular488 <: TriangularCode

function Triangular488(d)
if d%2!=1
throw(ArgumentError("Only odd distance triangular color codes are allowed.\nRefer to https://arxiv.org/abs/1108.5738"))
throw(ArgumentError(THROW_COLOR_CODES_ODD))
elseif d<3
throw(ArgumentError("Smallest allowed distance is 3.\nRefer to https://arxiv.org/abs/1108.5738"))
throw(ArgumentError(THROW_COLOR_CODES_MIN_DIST))
end
return new(d)
end
Expand Down Expand Up @@ -110,9 +110,9 @@ struct Triangular666 <: TriangularCode
d::Int
function Triangular666(d)
if d%2!=1
throw(ArgumentError("Only odd distance triangular color codes are allowed.\nRefer to https://arxiv.org/abs/1108.5738"))
throw(ArgumentError(THROW_COLOR_CODES_ODD))
elseif d<3
throw(ArgumentError("Smallest allowed distance is 3.\nRefer to https://arxiv.org/abs/1108.5738"))
throw(ArgumentError(THROW_COLOR_CODES_MIN_DIST))
end
return new(d)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct DelfosseReichardt823 <: AbstractQECC
"""The number of blocks in the Delfosse-Reichardt generalized [[8, 2, 3]] code."""
p::Int
function DelfosseReichardt823(p)
p < 1 && throw(ArgumentError("The number of blocks must be at least 1 to construct a valid code."))
p < 1 && throw(ArgumentError(THROW_DELFOSSE_823_MIN_BLOCKS))
new(p)
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/QECCore/src/codes/quantum/delfosse_reichardt_code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ struct DelfosseReichardt <: AbstractCSSCode
"""The log-length of the classical Reed-Muller code."""
m::Int
function DelfosseReichardt(p,r,m)
p < 2 && throw(ArgumentError("The number of blocks must be at least 2 to construct a valid code."))
p < 2 && throw(ArgumentError(THROW_DELFOSSE_MIN_BLOCKS))
if r < 0 || r > m
throw(ArgumentError("Invalid parameters: r must be non-negative and r ≤ m in order to valid code."))
throw(ArgumentError(THROW_INVALID_PARAMETERS_REEDMULLER))
end
if !iszero(mod.(parity_matrix(ReedMuller(r,m))*parity_matrix(ReedMuller(r,m))',2))
throw(ArgumentError("The `Reed-Muller` parity check matrix must be 'self-orthogonal' to construct a self-dual
CSS `DelfosseReichardt` code. Use `search_self_orthogonal_rm_codes` to search for good parameters for `Reed-Muller` codes
that provide `self-orthogonal` seeds."))
throw(ArgumentError(THROW_DELFOSSE_SELF_ORTHOGONAL))
end
new(p,r,m)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/QECCore/src/codes/quantum/delfosse_reichardt_repcode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct DelfosseReichardtRepCode <: AbstractCSSCode
"""The number of blocks in the Delfosse-Reichardt Repetition code."""
p::Int
function DelfosseReichardtRepCode(p)
p < 2 && throw(ArgumentError("The number of blocks must be at least 2 to construct a valid code."))
p % 2 != 0 && throw(ArgumentError("The number of blocks must be a multiple of 2."))
p < 2 && throw(ArgumentError(THROW_DELFOSSE_MIN_BLOCKS))
p % 2 != 0 && throw(ArgumentError(THROW_DELFOSSE_REP_MULTIPLE))
new(p)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/QECCore/src/codes/quantum/quantumreedmuller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct QuantumReedMuller <: AbstractCSSCode
m::Int
function QuantumReedMuller(m)
if m < 3
throw(DomainError("Invalid parameters: m must be bigger than 2 in order to have a valid code."))
throw(DomainError(THROW_INVALID_QUANTUM_REED_MULLER))
end
new(m)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/QECCore/src/codes/quantum/quantumtannergraphproduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ julia> code_n(c), code_k(c)
struct CyclicQuantumTannerGraphProduct <: AbstractCSSCode
m::Int
function CyclicQuantumTannerGraphProduct(m::Int)
m > 0 || throw(ArgumentError("m must be positive."))
m > 0 || throw(ArgumentError(THROW_REQUIRED_POSITIVE_ARG))
new(m)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/QECCore/src/codes/quantum/tillichzemor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct TillichZemor{M} <: AbstractCSSCode where {M <: Union{Nothing,Tuple{Abstra
matrices::M

function TillichZemor(n::Int, m::Int, r::Int, matrices::M=nothing) where {M <: Union{Nothing,Tuple{AbstractMatrix,AbstractMatrix}}}
(m ≥ r && (n - m)*r ≥ m) || throw(ArgumentError(("Conditions for the existence of `M` in `H = [C | M]` are not satisfied.")))
(m ≥ r && (n - m)*r ≥ m) || throw(ArgumentError((THROW_INVALID_PARAMETERS_TILLICH_ZEMOR)))
new{M}(n, m, r, matrices)
end
end
Expand Down Expand Up @@ -202,7 +202,7 @@ function _create_matrix_M_random(rng::AbstractRNG, m::Int, n::Int, r::Int)
end

function _construct_parity_check_matrix(rng::AbstractRNG, n::Int, m::Int, r::Int)
(m ≥ r && (n - m)*r ≥ m) || throw(ArgumentError(("Conditions for the existence of `M` in `H = [C | M]` are not satisfied.")))
(m ≥ r && (n - m)*r ≥ m) || throw(ArgumentError((THROW_INVALID_PARAMETERS_TILLICH_ZEMOR)))
C = _create_circulant_matrix(m)
M = _create_matrix_M_random(rng, m, n, r)
# The parity-check matrix H = [C | M]
Expand Down
17 changes: 8 additions & 9 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ function __init__()
end
end

include("throws.jl")

const NoZeroQubit = ArgumentError("Qubit indices have to be larger than zero, but you are attempting to create a gate acting on a qubit with a non-positive index. Ensure indexing always starts from 1.")

# Predefined constants representing the permitted phases encoded
# in the low bits of UInt8.
Expand Down Expand Up @@ -189,7 +187,7 @@ function Tableau(phases::AbstractVector{<: Unsigned}, xs::AbstractMatrix{Bool},
r_xs = size(xs, 1)
r_zs = size(zs, 1)
if length(phases) != r_xs || r_xs != r_zs
throw(DimensionMismatch(lazy"The length of phases ($(length(phases))), rows of xs ($r_xs), rows of zs ($r_zs) must all be equal."))
throw(DimensionMismatch(THROW_SIZE))
end
Tableau(
phases,size(xs, 2),
Expand Down Expand Up @@ -656,7 +654,7 @@ function MixedDestabilizer(d::Destabilizer, r::Int)
if l==2n
MixedDestabilizer(tab(d), r)
else
throw(DomainError("Only full-rank `Destabilizer` can be converted to `MixedDestabilizer` with specific rank. Try not specifying `r`."))
throw(DomainError(THROW_ONLY_FULL_RANK_DESTABILIZER_SUPPORTED))
end
end
function MixedDestabilizer(d::Destabilizer)
Expand Down Expand Up @@ -833,8 +831,8 @@ comm(l::Tableau, r::PauliOperator) = comm(r, l)
"""An in-place version of [`comm`](@ref), storing its output in the given buffer."""
function comm! end
function comm!(v, l::PauliOperator, r::Tableau)
length(v) == length(r) || throw(DimensionMismatch(lazy"The dimensions of the output buffer and the input tableau have to match in `comm!`"))
nqubits(l) == nqubits(r) || throw(DimensionMismatch(lazy"The number of qubits of the input Pauli operator and the input tableau have to match in `comm!`"))
length(v) == length(r) || throw(DimensionMismatch(THROW_SIZE))
nqubits(l) == nqubits(r) || throw(DimensionMismatch(THROW_NQUBITS))
for i in 1:length(r)
v[i] = comm(l,r,i)
end
Expand Down Expand Up @@ -872,7 +870,7 @@ function Base.:(*)(l::Number, r::PauliOperator)
elseif l==-1im
p.phase[] = (p.phase[] + 3)&0x3
else
throw(DomainError(l,"Only {±1,±i} are permitted as phases."))
throw(DomainError(l,THROW_PHASES))
end
p
end
Expand Down Expand Up @@ -1059,7 +1057,7 @@ function Base.hcat(tabs::Tableau...) # TODO this implementation is slow as it un
for tab in tabs
rows_tab, cols_tab = size(tab)
if rows_tab != rows
throw(ArgumentError("All input Tableaux/Stabilizers must have the same number of rows."))
throw(ArgumentError(THROW_ROW_MISMATCH_TABLEAUX))
end
for i in 1:rows
for j in 1:cols_tab
Expand Down Expand Up @@ -1099,7 +1097,7 @@ end

# TODO no need to track phases outside of stabview
function _apply!(stab::AbstractStabilizer, p::PauliOperator; phases::Val{B}=Val(true)) where B
nqubits(stab)==nqubits(p) || throw(DimensionMismatch("The tableau and the Pauli operator need to act on the same number of qubits. Consider specifying an array of indices as a third argument to the `apply!` function to avoid this error."))
nqubits(stab)==nqubits(p) || throw(DimensionMismatch(THROW_INVALID_ACTION_QUBITS))
s = tab(stab)
B || return stab
for i in eachindex(s)
Expand Down Expand Up @@ -1462,5 +1460,6 @@ include("grouptableaux.jl")
include("plotting_extensions.jl")
#
include("gpu_adapters.jl")
include("throws.jl")

end #module
Loading