Skip to content

Commit 0998f71

Browse files
committed
Deprecate PauliBasis and equal_bases
1 parent 0609a9d commit 0998f71

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# News
22

3+
## v0.3.7 - 2024-12-05
4+
5+
- Rename `PauliBasis` to `NQubitBasis` with warning, and add deprecation to `equal_bases`.
6+
37
## v0.3.6 - 2024-09-08
48

59
- Add `coherentstate`, `thermalstate`, `displace`, `squeeze`, `wigner`, previously from QuantumOptics.

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuantumInterface"
22
uuid = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
33
authors = ["QuantumInterface.jl contributors"]
4-
version = "0.3.6"
4+
version = "0.3.7"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/QuantumInterface.jl

+1
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,6 @@ include("julia_linalg.jl")
126126
include("sparse.jl")
127127

128128
include("sortedindices.jl")
129+
include("deprecated.jl")
129130

130131
end # module

src/bases.jl

+6-23
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,6 @@ function equal_shape(a, b)
6565
return true
6666
end
6767

68-
"""
69-
equal_bases(a, b)
70-
71-
Check if two subbases vectors are identical.
72-
"""
73-
function equal_bases(a, b)
74-
if a===b
75-
return true
76-
end
77-
for i=1:length(a)
78-
if a[i]!=b[i]
79-
return false
80-
end
81-
end
82-
return true
83-
end
84-
8568
##
8669
# Common bases
8770
##
@@ -126,25 +109,25 @@ end
126109

127110
Base.:(==)(b1::NLevelBasis, b2::NLevelBasis) = b1.N == b2.N
128111

129-
130112
"""
131-
PauliBasis(num_qubits::Int)
113+
NQubitBasis(num_qubits::Int)
132114
133115
Basis for an N-qubit space where `num_qubits` specifies the number of qubits.
134-
The dimension of the basis is 2²ᴺ.
116+
The dimension of the basis is 2ᴺ.
135117
"""
136-
struct PauliBasis{S,B} <: Basis
118+
struct NQubitBasis{S,B} <: Basis
137119
shape::S
138120
bases::B
139-
function PauliBasis(num_qubits::T) where {T<:Integer}
121+
function NQubitBasis(num_qubits::T) where {T<:Integer}
140122
shape = [2 for _ in 1:num_qubits]
141123
bases = Tuple(SpinBasis(1//2) for _ in 1:num_qubits)
142124
return new{typeof(shape),typeof(bases)}(shape, bases)
143125
end
144126
end
145127

146-
Base.:(==)(pb1::PauliBasis, pb2::PauliBasis) = length(pb1.bases) == length(pb2.bases)
128+
Base.:(==)(pb1::NQubitBasis, pb2::NQubitBasis) = length(pb1.bases) == length(pb2.bases)
147129

130+
Base.@deprecate PauliBasis(num_qubits) NQubitBasis(num_qubits) false
148131

149132
"""
150133
SpinBasis(n)

src/deprecated.jl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function equal_bases(a, b)
2+
Base.depwarn("`==` should be preferred over `equal_bases`!", :equal_bases)
3+
if a===b
4+
return true
5+
end
6+
for i=1:length(a)
7+
if a[i]!=b[i]
8+
return false
9+
end
10+
end
11+
return true
12+
end

test/test_bases.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Test
2-
using QuantumInterface: tensor, , ptrace, reduced, permutesystems, equal_bases, multiplicable
2+
using QuantumInterface: tensor, , ptrace, reduced, permutesystems, multiplicable
33
using QuantumInterface: GenericBasis, CompositeBasis, NLevelBasis, FockBasis
44

55
@testset "basis" begin
@@ -49,7 +49,7 @@ comp1 = tensor(b1, b2, b3)
4949
comp2 = tensor(b2, b1, b3)
5050
@test permutesystems(comp1, [2,1,3]) == comp2
5151

52-
@test !equal_bases([b1, b2], [b1, b3])
52+
@test [b1, b2] !== [b1, b3]
5353
@test !multiplicable(comp1, b1 b2 NLevelBasis(prod(b3.shape)))
5454

5555
end # testset

0 commit comments

Comments
 (0)