Skip to content

Commit cef3b95

Browse files
authored
introduce permutesystems (#490)
1 parent 5341f9d commit cef3b95

7 files changed

+42
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Planned changes for v1.0.0:
22

3-
- `permute` will be a wrapper around to `QuantumInterface.permutesubsystems`. Documentation for `permute!` would be similarly updated
3+
- `permute` will be a wrapper around to `QuantumInterface.permutesystems`. Documentation for `permute!` would be similarly updated
44
- reworking the rest of `NoisyCircuits` and moving it out of `Experimental`
55

66
# News
77

8+
## v0.9.19 - 2025-04-08
9+
10+
- `permutesystems` and `permutesystems!` are no implemented, deprecating `permute` and `permute!`
11+
812
## v0.9.18 - 2025-02-19
913

1014
- Fixes for rare crashes in the python BP decoders.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuantumClifford"
22
uuid = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
33
authors = ["Stefan Krastanov <[email protected]> and QuantumSavory community members"]
4-
version = "0.9.18"
4+
version = "0.9.19"
55

66
[deps]
77
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"

docs/src/stab-algebra-manual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ julia> tHadamard * tPhase
513513
X₁ ⟼ - Y
514514
Z₁ ⟼ + X
515515
516-
julia> permute(tCNOT, [2,1])
516+
julia> permutesubsystem(tCNOT, [2,1])
517517
X₁ ⟼ + X_
518518
X₂ ⟼ + XX
519519
Z₁ ⟼ + ZZ

src/QuantumClifford.jl

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ using Combinatorics: combinations
1515
using Base.Cartesian
1616
using DocStringExtensions
1717

18-
import QuantumInterface: tensor, , tensor_pow, apply!, nqubits, expect, project!, reset_qubits!, traceout!, ptrace, apply!, projectX!, projectY!, projectZ!, entanglement_entropy, embed
18+
import QuantumInterface: tensor, , tensor_pow,
19+
nqubits, expect, project!, reset_qubits!, traceout!, ptrace,
20+
apply!, projectX!, projectY!, projectZ!,
21+
embed, permutesystems,
22+
entanglement_entropy
1923

2024
export
2125
@P_str, PauliOperator, , I, X, Y, Z,
@@ -37,13 +41,14 @@ export
3741
tensor, tensor_pow,
3842
logdot, expect,
3943
apply!,
44+
permutesystems, permutesystems!,
4045
# Low Level Function Interface
4146
generate!, project!, reset_qubits!, traceout!,
4247
projectX!, projectY!, projectZ!,
4348
projectrand!, projectXrand!, projectYrand!, projectZrand!,
4449
puttableau!, embed,
4550
# Clifford Ops
46-
CliffordOperator, @C_str, permute,
51+
CliffordOperator, @C_str,
4752
tCNOT, tCPHASE, tSWAP, tHadamard, tPhase, tId1,
4853
# Symbolic Clifford Ops
4954
AbstractSymbolicOperator, AbstractSingleQubitOperator, AbstractTwoQubitOperator,
@@ -936,20 +941,6 @@ the following values based on the index `i`:
936941
return lowbit, ibig, ismall, ismallm
937942
end
938943

939-
"""Permute the qubits (i.e., columns) of the tableau in place."""
940-
function Base.permute!(s::Tableau, perm::AbstractVector)
941-
for r in 1:size(s,1)
942-
s[r] = s[r][perm] # TODO make a local temporary buffer row instead of constantly allocating new rows
943-
end
944-
s
945-
end
946-
947-
"""Permute the qubits (i.e., columns) of the state in place."""
948-
function Base.permute!(s::AbstractStabilizer, perm::AbstractVector)
949-
permute!(tab(s), perm)
950-
s
951-
end
952-
953944
function check_allrowscommute(stabilizer::Tableau)
954945
for i in eachindex(stabilizer)
955946
for j in eachindex(stabilizer)
@@ -1349,6 +1340,7 @@ include("fastmemlayout.jl")
13491340
include("dense_cliffords.jl")
13501341
# special one- and two- qubit operators
13511342
include("symbolic_cliffords.jl")
1343+
# linear algebra and array-like operations
13521344
include("linalg.jl")
13531345
# circuits
13541346
include("operator_traits.jl")

src/canonicalization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function _canonicalize_gott!(stabilizer::Stabilizer; phases::Val{B}=Val(true)) w
240240
end
241241
end
242242
xperm, r = gott_standard_form_indices((@view xzs[1:end÷2,:]),rows,columns)
243-
permute!(stabilizer,xperm)
243+
permutesystems!(stabilizer,xperm)
244244
i = r+1
245245
for j in r+1:columns
246246
# find first row with Z in col `j`
@@ -257,7 +257,7 @@ function _canonicalize_gott!(stabilizer::Stabilizer; phases::Val{B}=Val(true)) w
257257
end
258258
end
259259
zperm, s = gott_standard_form_indices((@view xzs[end÷2+1:end,:]),rows,columns,skip=r)
260-
permute!(stabilizer,zperm)
260+
permutesystems!(stabilizer,zperm)
261261
# we have r+s==rows (or we have trailing rows that are zeroed)
262262
stabilizer, r, s, xperm, zperm
263263
end

src/dense_cliffords.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ function apply!(r::CliffordOperator, l::AbstractCliffordOperator; phases=false)
106106
r
107107
end
108108

109-
# TODO create Base.permute! and getindex(..., permutation_array)
110-
function permute(c::CliffordOperator,p) # TODO this is a slow stupid implementation
111-
CliffordOperator(Tableau([tab(c)[i][p] for i in 1:2*nqubits(c)][vcat(p,p.+nqubits(c))]))
112-
end
113-
114109
"""Nonvectorized version of `apply!` used for unit tests."""
115110
function _apply_nonthread!(stab::AbstractStabilizer, c::CliffordOperator; phases::Bool=true)
116111
nqubits(stab)==nqubits(c) || throw(DimensionMismatch("The tableau and the Clifford 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."))

src/linalg.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
function permutesystems(c::CliffordOperator,p) # TODO this is a slow stupid implementation
2+
CliffordOperator(Tableau([tab(c)[i][p] for i in 1:2*nqubits(c)][vcat(p,p.+nqubits(c))]))
3+
end
4+
5+
@deprecate permute(c::CliffordOperator,p) permutesystems(c,p)
6+
7+
function permutesystems!(s::Tableau, perm::AbstractVector)
8+
for r in 1:size(s,1)
9+
s[r] = s[r][perm] # TODO make a local temporary buffer row instead of constantly allocating new rows
10+
end
11+
s
12+
end
13+
14+
function permutesystems!(s::AbstractStabilizer, perm::AbstractVector)
15+
permutesystems!(tab(s), perm)
16+
s
17+
end
18+
19+
import Base: permute!
20+
@deprecate permute!(s::Tableau, perm::AbstractVector) permutesystems!(s, perm)
21+
@deprecate permute!(s::AbstractStabilizer, perm::AbstractVector) permutesystems!(s, perm)
22+
23+
# TODO upstream to QuantumInterface for (state::Any, perm)
24+
permutesystems(s::AbstractStabilizer, perm) = permutesystems!(s, perm)
25+
126
"""
227
$TYPEDSIGNATURES
328

0 commit comments

Comments
 (0)