Skip to content

Commit

Permalink
Deprecate PauliBasis and equal_bases
Browse files Browse the repository at this point in the history
  • Loading branch information
akirakyle committed Dec 6, 2024
1 parent 0609a9d commit 0998f71
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# News

## v0.3.7 - 2024-12-05

- Rename `PauliBasis` to `NQubitBasis` with warning, and add deprecation to `equal_bases`.

## v0.3.6 - 2024-09-08

- Add `coherentstate`, `thermalstate`, `displace`, `squeeze`, `wigner`, previously from QuantumOptics.
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 = "QuantumInterface"
uuid = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
authors = ["QuantumInterface.jl contributors"]
version = "0.3.6"
version = "0.3.7"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
1 change: 1 addition & 0 deletions src/QuantumInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ include("julia_linalg.jl")
include("sparse.jl")

include("sortedindices.jl")
include("deprecated.jl")

end # module
29 changes: 6 additions & 23 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ function equal_shape(a, b)
return true
end

"""
equal_bases(a, b)
Check if two subbases vectors are identical.
"""
function equal_bases(a, b)
if a===b
return true
end
for i=1:length(a)
if a[i]!=b[i]
return false
end
end
return true
end

##
# Common bases
##
Expand Down Expand Up @@ -126,25 +109,25 @@ end

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


"""
PauliBasis(num_qubits::Int)
NQubitBasis(num_qubits::Int)
Basis for an N-qubit space where `num_qubits` specifies the number of qubits.
The dimension of the basis is 2²ᴺ.
The dimension of the basis is 2ᴺ.
"""
struct PauliBasis{S,B} <: Basis
struct NQubitBasis{S,B} <: Basis
shape::S
bases::B
function PauliBasis(num_qubits::T) where {T<:Integer}
function NQubitBasis(num_qubits::T) where {T<:Integer}

Check warning on line 121 in src/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases.jl#L121

Added line #L121 was not covered by tests
shape = [2 for _ in 1:num_qubits]
bases = Tuple(SpinBasis(1//2) for _ in 1:num_qubits)
return new{typeof(shape),typeof(bases)}(shape, bases)
end
end

Base.:(==)(pb1::PauliBasis, pb2::PauliBasis) = length(pb1.bases) == length(pb2.bases)
Base.:(==)(pb1::NQubitBasis, pb2::NQubitBasis) = length(pb1.bases) == length(pb2.bases)

Check warning on line 128 in src/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases.jl#L128

Added line #L128 was not covered by tests

Base.@deprecate PauliBasis(num_qubits) NQubitBasis(num_qubits) false

"""
SpinBasis(n)
Expand Down
12 changes: 12 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function equal_bases(a, b)
Base.depwarn("`==` should be preferred over `equal_bases`!", :equal_bases)
if a===b
return true

Check warning on line 4 in src/deprecated.jl

View check run for this annotation

Codecov / codecov/patch

src/deprecated.jl#L1-L4

Added lines #L1 - L4 were not covered by tests
end
for i=1:length(a)
if a[i]!=b[i]
return false

Check warning on line 8 in src/deprecated.jl

View check run for this annotation

Codecov / codecov/patch

src/deprecated.jl#L6-L8

Added lines #L6 - L8 were not covered by tests
end
end
return true

Check warning on line 11 in src/deprecated.jl

View check run for this annotation

Codecov / codecov/patch

src/deprecated.jl#L10-L11

Added lines #L10 - L11 were not covered by tests
end
4 changes: 2 additions & 2 deletions test/test_bases.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test
using QuantumInterface: tensor, , ptrace, reduced, permutesystems, equal_bases, multiplicable
using QuantumInterface: tensor, , ptrace, reduced, permutesystems, multiplicable
using QuantumInterface: GenericBasis, CompositeBasis, NLevelBasis, FockBasis

@testset "basis" begin
Expand Down Expand Up @@ -49,7 +49,7 @@ comp1 = tensor(b1, b2, b3)
comp2 = tensor(b2, b1, b3)
@test permutesystems(comp1, [2,1,3]) == comp2

@test !equal_bases([b1, b2], [b1, b3])
@test [b1, b2] !== [b1, b3]
@test !multiplicable(comp1, b1 b2 NLevelBasis(prod(b3.shape)))

end # testset

0 comments on commit 0998f71

Please sign in to comment.