Skip to content

improvements to the non-clifford functionality #259

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

Merged
merged 21 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0680562
`Destabilizer` now preserves input Stabilizer tableaux
Krastanov Apr 11, 2024
e395e26
`StabMixture` renamed to `GeneralizedStabilizer`
Krastanov Apr 11, 2024
feb7363
rowdecompose was not accounting for input phase
Krastanov Apr 12, 2024
1ad4b36
`expect` for `GeneralizedStabilizer`
Krastanov Apr 12, 2024
21d7983
scaffolding for `project!` for `GeneralizedStabilizer`
Krastanov Apr 12, 2024
bcf816c
bump project version and test fixups
Krastanov Apr 12, 2024
9ecb7bf
add smaller tests for `expect` on nonstabilizer states
Krastanov Apr 18, 2024
bf649a6
fixes expect (#348)
Fe-r-oz Sep 14, 2024
19626ba
noncliff: fix JET errors (#362)
Fe-r-oz Sep 27, 2024
624eedd
noncliff: improvements to `apply!` and `dictvaltype` (#346)
Fe-r-oz Sep 27, 2024
6863bd0
noncliff: improve performance of `_allthreesumtozero` (#377)
Fe-r-oz Oct 25, 2024
78d4430
noncliff: improve error handling in `apply!(sm, pcT)` (#374)
Fe-r-oz Oct 25, 2024
99f2f0b
noncliff: add copy, == for GeneralizedStabilizer, UnitaryPauliChannel…
Fe-r-oz Nov 5, 2024
9c1ea49
noncliff: add tests for conjugate destabs (#413)
Fe-r-oz Nov 5, 2024
e4a6479
noncliff: scaffolding for projectrand! for GeneralizedStabilizer (#420)
Fe-r-oz Nov 5, 2024
cd74b92
noncliff: introducing inverse sparsity `Λ(χ)` and `Λ(ϕᵢⱼ)` (#376)
Fe-r-oz Nov 5, 2024
f90a4ed
noncliff: enhanced error message for inapplicable Project! of General…
Fe-r-oz Nov 8, 2024
2d8fce2
noncliff: in-place Pauli measurements (`projectrand!`) for `Generaliz…
Fe-r-oz Apr 29, 2025
cf16f31
Merge branch 'master' into nonclif
Fe-r-oz Apr 29, 2025
6a8290d
use testitem for test_nonclifford_quantumoptics so tests actually run…
Fe-r-oz Apr 29, 2025
3b7bb0e
improve doctest for projectrand, since it gives random output, we us…
Fe-r-oz Apr 29, 2025
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

# News

## v0.10.0 - dev

- **(breaking)** `StabMixture` was renamed to `GeneralizedStabilizer`.
- **(fix)** `rowdecompose` was not accounting for the phase of the input Pauli string, leading to potential errors in nonclifford functionality.
- `expect` is now implemented for `GeneralizedStabilizer`.
- Constructing a `Destabilizer` out of a full-rank `Stabilizer` does not require a canonicalization anymore, i.e. `stabilizerview(Destabilizer(s))==s` is guaranteed.
- The `maximally_mixed` function is now available for creating maximally mixed multi-qubit states.
- `projectrand!` is now implemented for `GeneralizedStabilizer`.

## unreleased

- Much faster indexing and slicing of `PauliOperator`.
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 <[email protected]> and QuantumSavory community members"]
version = "0.9.19"
version = "0.10.0"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
9 changes: 9 additions & 0 deletions docs/src/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ @article{nahum2017quantum
year = {2017}
}

% non-Clifford formalism

@inproceedings{Yoder2012AGO,
title={A generalization of the stabilizer formalism for simulating arbitrary quantum circuits},
author={Theodore J. Yoder},
year={2012},
url={https://api.semanticscholar.org/CorpusID:18406560}
}

% codes

@article{mackay2004sparse,
Expand Down
12 changes: 6 additions & 6 deletions docs/src/stab-algebra-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,12 @@ julia> s=S"-XXX
julia> d = Destabilizer(s)
𝒟ℯ𝓈𝓉𝒶𝒷
+ Z__
+ _X_
+ _XX
+ __X
𝒮𝓉𝒶𝒷━
- XXX
- ZZ_
- Z_Z
+ _ZZ
```

They have convenience methods to extract only the stabilizer and destabilizer
Expand All @@ -642,11 +642,11 @@ pieces:
julia> stabilizerview(d)
- XXX
- ZZ_
- Z_Z
+ _ZZ

julia> destabilizerview(d)
+ Z__
+ _X_
+ _XX
+ __X
```

Expand All @@ -672,12 +672,12 @@ Clifford operations can be applied the same way they are applied to stabilizers.
julia> apply!(d,tCNOT⊗tHadamard)
𝒟ℯ𝓈𝓉𝒶𝒷
- X_Z
+ XXZ
+ _XZ
+ X__
𝒮𝓉𝒶𝒷━
+ _ZX
- _Z_
- Z_X
+ ZZX
```

# Mixed States
Expand Down
11 changes: 9 additions & 2 deletions ext/QuantumCliffordQOpticsExt/QuantumCliffordQOpticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ Ket(dim=4)
```"""
Ket(s::QuantumClifford.AbstractStabilizer) = stab_to_ket(s)

function stabmix_to_densityop(s::StabMixture)
"""
$TYPEDSIGNATURES

Convert a stabilizer tableau to a density matrix corresponding to the given state.
"""
Operator(s::QuantumClifford.AbstractStabilizer) = dm(Ket(s)) # TODO support mixed stabilizer states

function genstab_to_densityop(s::GeneralizedStabilizer)
ρ₀ = zero(dm(Ket(s.stab)))
for ((Pₗᵇⁱᵗˢ,Pᵣᵇⁱᵗˢ), χ) in s.destabweights
ρ̃ = dm(Ket(s.stab))
Expand All @@ -96,7 +103,7 @@ end
$TYPEDSIGNATURES

"""
Operator(s::StabMixture) = stabmix_to_densityop(s)
Operator(s::GeneralizedStabilizer) = genstab_to_densityop(s)


"""
Expand Down
67 changes: 58 additions & 9 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# Pauli frames
PauliFrame, pftrajectories, pfmeasurements,
# Useful States
bell, ghz,
bell, ghz, maximally_mixed,
single_z, single_x, single_y,
# Graphs
graphstate, graphstate!, graph_gatesequence, graph_gate,
Expand All @@ -92,7 +92,7 @@
# petrajectories
petrajectories, applybranches,
# nonclifford
StabMixture, UnitaryPauliChannel, PauliChannel, pcT,
GeneralizedStabilizer, UnitaryPauliChannel, PauliChannel, pcT,
# makie plotting -- defined only when extension is loaded
stabilizerplot, stabilizerplot_axis,
# sum types
Expand All @@ -109,6 +109,22 @@
BIG_INT_MINUS_ONE[] = BigInt(-1)
BIG_INT_TWO[] = BigInt(2)
BIG_INT_FOUR[] = BigInt(4)

# Register error hint for the `project!` method for GeneralizedStabilizer
if isdefined(Base.Experimental, :register_error_hint)
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
if exc.f === project! && argtypes[1] <: GeneralizedStabilizer
print(io, """
\nThe method `project!` is not appropriate for use with`GeneralizedStabilizer`.
You probably are looking for `projectrand!`.
`project!` in this library is a low-level "linear algebra" method to verify
whether a measurement operator commutes with a set of stabilizers, and to
potentially simplify the tableau and provide the index of the anticommuting
term in that tableau. This linear algebra operation is not defined for
`GeneralStabilizer` as there is no single tableau to provide an index into.""")
end
end
end
end

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.")
Expand Down Expand Up @@ -462,21 +478,54 @@

"""
A tableau representation of a pure stabilizer state. The tableau tracks the
destabilizers as well, for efficient projections. On initialization there are
destabilizers as well, for efficient projections.

For full-rank tableaux, the stabilizer part of the tableau is guaranteed to be kept the same as the input stabilizer tableau given to the constructor (a guarantee not kept by [`MixedDestabilizer`](@ref)).

On initialization there are
no checks that the provided state is indeed pure. This enables the use of this
data structure for mixed stabilizer state, but a better choice would be to use
data structure for mixed stabilizer state, but usually a better choice would be
[`MixedDestabilizer`](@ref).
""" # TODO clean up and document constructor

```
julia> Destabilizer(S"ZZI XXX")
𝒟ℯ𝓈𝓉𝒶𝒷
+ Z__
+ _X_
𝒮𝓉𝒶𝒷━
+ XXX
+ ZZ_

julia> Destabilizer(S"ZZI XXX IZZ")
𝒟ℯ𝓈𝓉𝒶𝒷
+ X__
+ _Z_
+ __X
𝒮𝓉𝒶𝒷━
+ ZZ_
+ XXX
+ _ZZ
```
"""
struct Destabilizer{T<:Tableau} <: AbstractStabilizer
tab::T
end

function Destabilizer(s::Stabilizer)
row, col = size(s)
row>col && error(DomainError("The input stabilizer has more rows than columns, making it inconsistent or overdetermined."))
mixed_destab = MixedDestabilizer(s)
t = vcat(tab(destabilizerview(mixed_destab)),tab(stabilizerview(mixed_destab)))
Destabilizer(t)
if row<col
mixed_destab = MixedDestabilizer(s)
t = vcat(tab(destabilizerview(mixed_destab)),tab(stabilizerview(mixed_destab)))
return Destabilizer(t)
elseif row==col
maxmix = maximally_mixed(col)
for row in s
project!(maxmix, row)
end
return Destabilizer(maxmix.tab)
else
error(DomainError("The input stabilizer has more rows than columns, making it inconsistent or overdetermined."))

Check warning on line 527 in src/QuantumClifford.jl

View check run for this annotation

Codecov / codecov/patch

src/QuantumClifford.jl#L527

Added line #L527 was not covered by tests
end
end

Base.length(d::Destabilizer) = length(tab(d))÷2
Expand Down
4 changes: 2 additions & 2 deletions src/dense_cliffords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ ERROR: DimensionMismatch: Input tableau should be of size 2n×n (top half is the
```jldoctest
julia> d = Destabilizer(S"Y")
𝒟ℯ𝓈𝓉𝒶𝒷
+ Z
+ X
𝒮𝓉𝒶𝒷
+ Y

julia> CliffordOperator(d)
X₁ ⟼ + Z
X₁ ⟼ + X
Z₁ ⟼ + Y
```
"""
Expand Down
Loading
Loading