From 4b053115cb7a0e7f85c057717d19af8126729252 Mon Sep 17 00:00:00 2001 From: Akira Kyle Date: Thu, 5 Dec 2024 18:14:56 -0700 Subject: [PATCH] Deprecate `PauliBasis` and `equal_bases` --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- src/QuantumInterface.jl | 1 + src/bases.jl | 29 +++++------------------------ src/deprecated.jl | 14 ++++++++++++++ test/test_bases.jl | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 src/deprecated.jl diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c30de4..f086a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Project.toml b/Project.toml index d8b70c0..a02a99b 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/QuantumInterface.jl b/src/QuantumInterface.jl index 89d3c9a..c1bc651 100644 --- a/src/QuantumInterface.jl +++ b/src/QuantumInterface.jl @@ -126,5 +126,6 @@ include("julia_linalg.jl") include("sparse.jl") include("sortedindices.jl") +include("deprecated.jl") end # module diff --git a/src/bases.jl b/src/bases.jl index 2c059e0..532ad65 100644 --- a/src/bases.jl +++ b/src/bases.jl @@ -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 ## @@ -126,25 +109,23 @@ 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} 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) """ SpinBasis(n) diff --git a/src/deprecated.jl b/src/deprecated.jl new file mode 100644 index 0000000..d4aadd5 --- /dev/null +++ b/src/deprecated.jl @@ -0,0 +1,14 @@ +function equal_bases(a, b) + Base.depwarn("`==` should be preferred over `equal_bases`!", :equal_bases) + if a===b + return true + end + for i=1:length(a) + if a[i]!=b[i] + return false + end + end + return true +end + +Base.@deprecate PauliBasis(num_qubits) NQubitBasis(num_qubits) false diff --git a/test/test_bases.jl b/test/test_bases.jl index 1d91673..f6a98c9 100644 --- a/test/test_bases.jl +++ b/test/test_bases.jl @@ -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 @@ -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