From cd74b92b7cde5e462f868103f76844305b1a0da5 Mon Sep 17 00:00:00 2001 From: Feroz Ahmad Date: Tue, 5 Nov 2024 20:28:39 +0500 Subject: [PATCH] =?UTF-8?q?noncliff:=20introducing=20inverse=20sparsity=20?= =?UTF-8?q?`=CE=9B(=CF=87)`=20and=20`=CE=9B(=CF=95=E1=B5=A2=E2=B1=BC)`=20(?= =?UTF-8?q?#376)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Stefan Krastanov --- src/nonclifford.jl | 36 ++++++++++++++++++++++++++++++++++++ test/test_nonclifford.jl | 17 ++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/nonclifford.jl b/src/nonclifford.jl index 7ab5c3dd0..524085025 100644 --- a/src/nonclifford.jl +++ b/src/nonclifford.jl @@ -418,6 +418,42 @@ nqubits(pc::UnitaryPauliChannel) = nqubits(pc.paulis[1]) apply!(state::GeneralizedStabilizer, gate::UnitaryPauliChannel; prune_threshold=1e-10) = apply!(state, gate.paulichannel; prune_threshold) +""" +Calculates the number of non-zero elements in the density matrix `χ` +of a [`GeneralizedStabilizer`](@ref), representing the inverse sparsity +of `χ`. It provides a measure of the state's complexity, with bounds +`Λ(χ) ≤ 4ⁿ`. + +```jldoctest +julia> sm = GeneralizedStabilizer(S"X") +A mixture ∑ ϕᵢⱼ Pᵢ ρ Pⱼ† where ρ is +𝒟ℯ𝓈𝓉𝒶𝒷 ++ Z +𝒮𝓉𝒶𝒷 ++ X +with ϕᵢⱼ | Pᵢ | Pⱼ: + 1.0+0.0im | + _ | + _ + +julia> apply!(sm, pcT) |> invsparsity +4 +``` + +Similarly, it calculates the number of non-zero elements in the density +matrix `ϕᵢⱼ`​ of a PauliChannel, providing a measure of the channel +complexity. + +```jldoctest +julia> invsparsity(pcT) +4 +``` + +See also: [`GeneralizedStabilizer`](@ref) +""" +function invsparsity end + +invsparsity(sm::GeneralizedStabilizer) = count(!iszero, values(sm.destabweights::DefaultDict{Tuple{BitVector, BitVector}, ComplexF64, ComplexF64})) +invsparsity(gate::AbstractPauliChannel) = count(!iszero, values(gate.paulichannel.weights::Vector{ComplexF64})) + ## # Predefined Pauli Channels ## diff --git a/test/test_nonclifford.jl b/test/test_nonclifford.jl index c4ff7c658..b26239de8 100644 --- a/test/test_nonclifford.jl +++ b/test/test_nonclifford.jl @@ -1,5 +1,5 @@ using QuantumClifford -using QuantumClifford: GeneralizedStabilizer, rowdecompose, PauliChannel, mul_left!, mul_right! +using QuantumClifford: GeneralizedStabilizer, rowdecompose, PauliChannel, invsparsity, mul_left!, mul_right! using Test using InteractiveUtils using Random @@ -39,6 +39,21 @@ end ## +@testset "Inverse sparsity" begin + for n in 1:5 + s = random_stabilizer(n) + gs = GeneralizedStabilizer(s) + for i in 1:rand(1:4) + apply!(gs, embed(n, i, pcT)) + end + # Λ(χ) ≤ 4ⁿ + @test invsparsity(gs) <= 4^n + channels = [embed(n, i, pcT) for i in 1:rand(1:4)] + # Λ(ϕᵢⱼ) ≤ 4ⁿ + @test all(invsparsity(channel) <= 4^n for channel in channels) + end +end + @test_throws ArgumentError GeneralizedStabilizer(S"XX") @test_throws ArgumentError PauliChannel(((P"X", P"Z"), (P"X", P"ZZ")), (1,2)) @test_throws ArgumentError PauliChannel(((P"X", P"Z"), (P"X", P"Z")), (1,))