From cab5f2867938c1fc8da0d8a9f2c0ba5f82bbfbbb Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Mon, 22 Sep 2025 19:36:40 -0400 Subject: [PATCH 1/7] made it such that petrajectories throws an error when it receives an operation that has out of bounds indices for qubits) --- src/petrajectory.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/petrajectory.jl b/src/petrajectory.jl index 125ecc30e..64724ee51 100644 --- a/src/petrajectory.jl +++ b/src/petrajectory.jl @@ -70,6 +70,11 @@ end See also: [`pftrajectories`](@ref), [`mctrajectories`](@ref)""" function petrajectories(initialstate, circuit; branch_weight=1.0, max_order=1, keepstates::Bool=false) + for circuit_op in circuit + if(maximum(affectedqubits(circuit_op)) > nqubits(initialstate)) + throw(ArgumentError(lazy"""Qubit out of bounds for $circuit_op. Attempting to access a $(nqubits(initialstate)) qubit state at index $(maximum(affectedqubits(circuit_op)))""")) + end + end if keepstates return petrajectory_keep(initialstate, circuit; branch_weight=branch_weight, current_order=0, max_order=max_order) else From 46114a77881486bef574d93ea2abf37402b7150d Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Sat, 4 Oct 2025 16:13:28 -0400 Subject: [PATCH 2/7] fixed the guard for petrajectories --- src/noise.jl | 8 ++++++++ src/petrajectory.jl | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/noise.jl b/src/noise.jl index 226a77780..7283afa90 100644 --- a/src/noise.jl +++ b/src/noise.jl @@ -208,3 +208,11 @@ function applybranches(s::AbstractQCState, g::NoisyGate; max_order=1) news, _,_,_ = applybranches(s,g.gate,max_order=max_order)[1] # TODO this assumes only one always successful branch for the gate return [(state, continue_stat, prob, order) for (state, prob, order) in applynoise_branches(news, g.noise, affectedqubits(g), max_order=max_order)] end + +function _sentinel_affectedqubits end +QuantumClifford._sentinel_affectedqubits(x::Any) = QuantumClifford.affectedqubits(x) +QuantumClifford._sentinel_affectedqubits(::QuantumClifford.NoiseOpAll) = missing + +function _sentinel_maximum end +QuantumClifford._sentinel_maximum(x::Any) = maximum(x) +QuantumClifford._sentinel_maximum(::Missing) = 0 \ No newline at end of file diff --git a/src/petrajectory.jl b/src/petrajectory.jl index 64724ee51..fb58b949d 100644 --- a/src/petrajectory.jl +++ b/src/petrajectory.jl @@ -71,8 +71,8 @@ end See also: [`pftrajectories`](@ref), [`mctrajectories`](@ref)""" function petrajectories(initialstate, circuit; branch_weight=1.0, max_order=1, keepstates::Bool=false) for circuit_op in circuit - if(maximum(affectedqubits(circuit_op)) > nqubits(initialstate)) - throw(ArgumentError(lazy"""Qubit out of bounds for $circuit_op. Attempting to access a $(nqubits(initialstate)) qubit state at index $(maximum(affectedqubits(circuit_op)))""")) + if(_sentinel_maximum(_sentinel_affectedqubits(circuit_op)) > nqubits(initialstate)) + throw(ArgumentError(lazy"""Qubit out of bounds for $circuit_op. Attempting to access a $(nqubits(initialstate)) qubit state at index $(_sentinel_maximum(_sentinel_affectedqubits(circuit_op)))""")) end end if keepstates From 970c680e16bfa97abe088533aa9abb816096b70e Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Sat, 4 Oct 2025 16:17:01 -0400 Subject: [PATCH 3/7] empty From 7cf39d67f7881e49e7f224f7435292dc097b3868 Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Sat, 4 Oct 2025 16:24:37 -0400 Subject: [PATCH 4/7] fixed some typos around the repo --- ext/QuantumCliffordGPUExt/fastmemlayout.jl | 2 +- src/ecc/codes/concat.jl | 2 +- src/randoms.jl | 2 +- src/sumtypes.jl | 2 +- test/test_noisycircuits.jl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/QuantumCliffordGPUExt/fastmemlayout.jl b/ext/QuantumCliffordGPUExt/fastmemlayout.jl index f5706b641..490903ef9 100644 --- a/ext/QuantumCliffordGPUExt/fastmemlayout.jl +++ b/ext/QuantumCliffordGPUExt/fastmemlayout.jl @@ -8,7 +8,7 @@ TableauAdj is the type of Tableau with its data stored in an adjoint of a CUDA a rest of the fastrow, fastcolumn functions are implemented in QuantumClifford.jl """ -# todo when we use to_gpu, to_cpu the efffect of fastrow, fastcolumn disappears +# todo when we use to_gpu, to_cpu the effect of fastrow, fastcolumn disappears fastrow(t::TableauCUDA) = t fastrow(t::TableauAdj) = Tableau(t.phases, t.nqubits, CuArray(t.xzs)) fastcolumn(t::TableauCUDA) = Tableau(t.phases, t.nqubits, CuArray(t.xzs')') diff --git a/src/ecc/codes/concat.jl b/src/ecc/codes/concat.jl index 0bd8f627b..1304f36ea 100644 --- a/src/ecc/codes/concat.jl +++ b/src/ecc/codes/concat.jl @@ -25,7 +25,7 @@ function parity_checks(c::Concat) phases_logx₁ = phases(logx_ops(c₁)) h_logz₁ = stab_to_gf2(logz_ops(c₁)) phases_logz₁ = phases(logz_ops(c₁)) - # parity checks of c₂ with qubits repalced with logical qubits of c₁ + # parity checks of c₂ with qubits replaced with logical qubits of c₁ outer_check_h = transpose(hcat([vcat( kron(h₂[i, 1:end÷2], h_logx₁[j, 1:end÷2]) .⊻ kron(h₂[i, end÷2+1:end], h_logz₁[j, 1:end÷2]), # X part kron(h₂[i, 1:end÷2], h_logx₁[j, end÷2+1:end]) .⊻ kron(h₂[i, end÷2+1:end], h_logz₁[j, end÷2+1:end]) # Z part diff --git a/src/randoms.jl b/src/randoms.jl index b1150a0a4..b45c28018 100644 --- a/src/randoms.jl +++ b/src/randoms.jl @@ -287,7 +287,7 @@ function _reset!(memory::RandDestabMemory) end end -# Allocation free inverse of upper trinagular int matrix with 1 on diagonal. +# Allocation free inverse of upper triangular int matrix with 1 on diagonal. function _inv!(inverse, A) for i in 2:size(A, 2) for j in 1:i-1 diff --git a/src/sumtypes.jl b/src/sumtypes.jl index f496532b0..d06ac4a3f 100644 --- a/src/sumtypes.jl +++ b/src/sumtypes.jl @@ -209,7 +209,7 @@ end ## -# `concrete_typeparams` annotations for the parameteric types we care about +# `concrete_typeparams` annotations for the parametric types we care about ## function concrete_typeparams(t::Type{ClassicalXOR}) diff --git a/test/test_noisycircuits.jl b/test/test_noisycircuits.jl index b1eb33c3f..83e31dc8f 100644 --- a/test/test_noisycircuits.jl +++ b/test/test_noisycircuits.jl @@ -272,7 +272,7 @@ @test pet_y[true_success_stat] == 1 @test pet_y[failure_stat] == 0 - #checks probabilstic case to see if the phase of measurement anticommuting stabilizer is the same in both branches + #checks probabilistic case to see if the phase of measurement anticommuting stabilizer is the same in both branches ghz_state = S"XXX ZZI IZZ" reg = Register(ghz_state, [0]) branches = applybranches(reg, sMRZ(1,1)) From 4d5b56798e9075f87ee80a92ae8e3d13df168c5c Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Fri, 10 Oct 2025 18:01:00 -0400 Subject: [PATCH 5/7] shifted the code from noise.jl to affected_qubits.jl --- src/noise.jl | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/noise.jl b/src/noise.jl index 7283afa90..3c133ab75 100644 --- a/src/noise.jl +++ b/src/noise.jl @@ -207,12 +207,4 @@ end function applybranches(s::AbstractQCState, g::NoisyGate; max_order=1) news, _,_,_ = applybranches(s,g.gate,max_order=max_order)[1] # TODO this assumes only one always successful branch for the gate return [(state, continue_stat, prob, order) for (state, prob, order) in applynoise_branches(news, g.noise, affectedqubits(g), max_order=max_order)] -end - -function _sentinel_affectedqubits end -QuantumClifford._sentinel_affectedqubits(x::Any) = QuantumClifford.affectedqubits(x) -QuantumClifford._sentinel_affectedqubits(::QuantumClifford.NoiseOpAll) = missing - -function _sentinel_maximum end -QuantumClifford._sentinel_maximum(x::Any) = maximum(x) -QuantumClifford._sentinel_maximum(::Missing) = 0 \ No newline at end of file +end \ No newline at end of file From 303fc4bf545ed6097b94978087e9e53fc165c636 Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Fri, 10 Oct 2025 18:02:50 -0400 Subject: [PATCH 6/7] fix --- src/affectedqubits.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/affectedqubits.jl b/src/affectedqubits.jl index 3609710e3..d377fada8 100644 --- a/src/affectedqubits.jl +++ b/src/affectedqubits.jl @@ -17,3 +17,11 @@ affectedqubits(c::ClassicalXOR) = () affectedbits(o) = () affectedbits(m::Union{sMRZ,sMZ,sMRX,sMX,sMRY,sMY}) = m.bit==0 ? () : (m.bit,) affectedbits(c::ClassicalXOR) = (c.bits..., c.store) + +function _sentinel_affectedqubits end +QuantumClifford._sentinel_affectedqubits(x::Any) = QuantumClifford.affectedqubits(x) +QuantumClifford._sentinel_affectedqubits(::QuantumClifford.NoiseOpAll) = missing + +function _sentinel_maximum end +QuantumClifford._sentinel_maximum(x::Any) = maximum(x) +QuantumClifford._sentinel_maximum(::Missing) = 0 \ No newline at end of file From f48bf58c4fab0112fccc2e5a2dda9ab83601269b Mon Sep 17 00:00:00 2001 From: Sai Rohan Reddy Kondlapudi Date: Fri, 10 Oct 2025 20:53:34 -0400 Subject: [PATCH 7/7] added a testthrows --- test/test_noisycircuits.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_noisycircuits.jl b/test/test_noisycircuits.jl index 83e31dc8f..5db39ea1e 100644 --- a/test/test_noisycircuits.jl +++ b/test/test_noisycircuits.jl @@ -414,4 +414,10 @@ end + @testset "Petrajectories" begin + reg = Register(one(MixedDestabilizer,3),2) + op = sCNOT(1,4) + circuit = [op] + @test_throws ArgumentError petrajectories(reg, circuit) # throws an error because sCNOT attemps to access a qubit that doesn't exist + end end