From 1a7a199e09a7b1a4ff14ea1d5e97de4fbbf4801d Mon Sep 17 00:00:00 2001 From: cailixun Date: Wed, 26 Nov 2025 14:31:04 +0800 Subject: [PATCH 1/7] add error throwing for projection --- src/qobj/operators.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/qobj/operators.jl b/src/qobj/operators.jl index fb0c2041f..4233edb61 100644 --- a/src/qobj/operators.jl +++ b/src/qobj/operators.jl @@ -493,8 +493,12 @@ end Generates the projection operator ``\hat{O} = |i \rangle\langle j|`` with Hilbert space dimension `N`. """ -projection(N::Int, i::Int, j::Int) = - QuantumObject(sparse([i + 1], [j + 1], [1.0 + 0.0im], N, N), type = Operator(), dims = N) +function projection(N::Int, i::Int, j::Int) + (0 <= i < N) || throw(ArgumentError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) + (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) + + return QuantumObject(sparse([i + 1], [j + 1], [1.0 + 0.0im], N, N), type = Operator(), dims = N) +end @doc raw""" tunneling(N::Int, m::Int=1; sparse::Union{Bool,Val{<:Bool}}=Val(false)) From 1a1ea65b2ffa87f5a31c36e1522cf4e17eb61b39 Mon Sep 17 00:00:00 2001 From: cailixun Date: Wed, 26 Nov 2025 14:49:08 +0800 Subject: [PATCH 2/7] add to several others --- src/qobj/operators.jl | 2 +- src/qobj/states.jl | 27 +++++++++++++-------------- src/qobj/synonyms.jl | 3 +++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/qobj/operators.jl b/src/qobj/operators.jl index 4233edb61..b921e349a 100644 --- a/src/qobj/operators.jl +++ b/src/qobj/operators.jl @@ -477,7 +477,7 @@ _Jordan_Wigner(N::Int, j::Int, op::QuantumObject{Operator}) = _Jordan_Wigner(Val function _Jordan_Wigner(::Val{N}, j::Int, op::QuantumObject{Operator}) where {N} (N < 1) && throw(ArgumentError("The total number of sites (N) cannot be less than 1")) - ((j > N) || (j < 1)) && throw(ArgumentError("The site index (j) should satisfy: 1 ≤ j ≤ N")) + (1 <= j <= N) || throw(ArgumentError("The site index (j) should satisfy: 1 ≤ j ≤ N")) σz = sigmaz().data Z_tensor = kron(1, 1, fill(σz, j - 1)...) diff --git a/src/qobj/states.jl b/src/qobj/states.jl index dd79bee8d..ad2b93a9a 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -2,7 +2,7 @@ Functions for generating (common) quantum states. =# -export zero_ket, fock, basis, coherent, rand_ket +export zero_ket, fock, coherent, rand_ket export fock_dm, coherent_dm, thermal_dm, maximally_mixed_dm, rand_dm export spin_state, spin_coherent export bell_state, singlet_state, triplet_states, w_state, ghz_state @@ -25,6 +25,7 @@ zero_ket(dimensions::Union{Dimensions,AbstractVector{Int},Tuple}) = @doc raw""" fock(N::Int, j::Int=0; dims::Union{Int,AbstractVector{Int},Tuple}=N, sparse::Union{Bool,Val}=Val(false)) + basis(N::Int, j::Int=0; dims::Union{Int,AbstractVector{Int},Tuple}=N, sparse::Union{Bool,Val}=Val(false)) Generates a fock state ``\ket{\psi}`` of dimension `N`. @@ -32,8 +33,13 @@ It is also possible to specify the list of dimensions `dims` if different subsys !!! warning "Beware of type-stability!" If you want to keep type stability, it is recommended to use `fock(N, j, dims=dims, sparse=Val(sparse))` instead of `fock(N, j, dims=dims, sparse=sparse)`. Consider also to use `dims` as a `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) instead of `Vector`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details. + +!!! note + `basis(N, j; dims = dims, sparse = sparse)` is a synonym of `fock(N, j; dims = dims, sparse = sparse)`. """ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N, sparse::Union{Bool,Val} = Val(false)) + (0 <= i < N) || throw(ArgumentError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) + (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else @@ -42,18 +48,6 @@ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N return QuantumObject(array; type = Ket(), dims = dims) end -@doc raw""" - basis(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple}=N) - -Generates a fock state like [`fock`](@ref). - -It is also possible to specify the list of dimensions `dims` if different subsystems are present. - -!!! warning "Beware of type-stability!" - If you want to keep type stability, it is recommended to use `basis(N, j, dims=dims)` with `dims` as a `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) instead of `Vector`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details. -""" -basis(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N) = fock(N, j, dims = dims) - @doc raw""" coherent(N::Int, α::Number) @@ -203,7 +197,7 @@ function spin_state(j::Real, m::Real) throw(ArgumentError("Invalid eigenvalue m: (j - m) must be a non-negative integer.")) (m < (-j)) && throw(ArgumentError("Invalid eigenvalue m, must satisfy: -j ≤ m ≤ j")) - return basis(Int(J), Int(Δ)) + return fock(Int(J), Int(Δ)) end @doc raw""" @@ -318,6 +312,8 @@ Returns the `n`-qubit [W-state](https://en.wikipedia.org/wiki/W_state): If you want to keep type stability, it is recommended to use `w_state(Val(n))` instead of `w_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function w_state(::Val{n}) where {n} + (n >= 3) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 3")) + nzind = 2 .^ (0:(n-1)) .+ 1 nzval = fill(ComplexF64(1 / sqrt(n)), n) data = zeros(ComplexF64, 2^n) @@ -341,6 +337,9 @@ Here, `d` specifies the dimension of each qudit. Default to `d=2` (qubit). If you want to keep type stability, it is recommended to use `ghz_state(Val(n))` instead of `ghz_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function ghz_state(::Val{n}; d::Int = 2) where {n} + (n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2")) + (d >= 2) || throw(ArgumentError("Invalid argument d, must satisfy: d ≥ 2")) + nzind = collect((0:(d-1)) .* Int((d^n - 1) / (d - 1)) .+ 1) nzval = fill(ComplexF64(1 / sqrt(d)), d) data = zeros(ComplexF64, d^n) diff --git a/src/qobj/synonyms.jl b/src/qobj/synonyms.jl index 224c73b59..fa73ad396 100644 --- a/src/qobj/synonyms.jl +++ b/src/qobj/synonyms.jl @@ -4,6 +4,7 @@ Synonyms of the functions for QuantumObject export Qobj, QobjEvo, shape, isherm export trans, dag, matrix_element, unit +export basis export tensor, ⊗ export qeye, qeye_like, qzero_like export vector_to_operator, operator_to_vector @@ -33,6 +34,8 @@ const trans = transpose const dag = adjoint +const basis = fock + @doc raw""" matrix_element(i::QuantumObject, A::QuantumObject, j::QuantumObject) From fd030312063066f715f16ba5a30c9f2399e02a74 Mon Sep 17 00:00:00 2001 From: cailixun Date: Wed, 26 Nov 2025 15:11:48 +0800 Subject: [PATCH 3/7] add test --- src/qobj/states.jl | 3 +-- test/core-test/states_and_operators.jl | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/qobj/states.jl b/src/qobj/states.jl index ad2b93a9a..38cddd6c9 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -38,7 +38,6 @@ It is also possible to specify the list of dimensions `dims` if different subsys `basis(N, j; dims = dims, sparse = sparse)` is a synonym of `fock(N, j; dims = dims, sparse = sparse)`. """ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N, sparse::Union{Bool,Val} = Val(false)) - (0 <= i < N) || throw(ArgumentError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) @@ -312,7 +311,7 @@ Returns the `n`-qubit [W-state](https://en.wikipedia.org/wiki/W_state): If you want to keep type stability, it is recommended to use `w_state(Val(n))` instead of `w_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function w_state(::Val{n}) where {n} - (n >= 3) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 3")) + (n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2")) nzind = 2 .^ (0:(n-1)) .+ 1 nzval = fill(ComplexF64(1 / sqrt(n)), n) diff --git a/test/core-test/states_and_operators.jl b/test/core-test/states_and_operators.jl index 6d0aef108..ad2814233 100644 --- a/test/core-test/states_and_operators.jl +++ b/test/core-test/states_and_operators.jl @@ -20,6 +20,7 @@ # fock, basis, and fock_dm @test fock_dm(4; dims = (2, 2), sparse = true) ≈ ket2dm(basis(4; dims = (2, 2))) @test_throws DimensionMismatch fock(4; dims = 2) + @test_throws ArgumentError fock(4, 4) end @testset "coherent state" begin @@ -121,16 +122,21 @@ @test_throws ArgumentError bell_state(0, 2) @test_throws ArgumentError bell_state(3, 1) @test_throws ArgumentError bell_state(2, 3) + @test_throws ArgumentError w_state(1) + @test_throws ArgumentError ghz_state(1) + @test_throws ArgumentError ghz_state(2; d = 1) end @testset "bosonic operators" begin # destroy, create, num, position, momentum n = 10 + i, j = rand(0:(n-1), 2) a = destroy(n) ad = create(n) N = num(n) x = position(n) p = momentum(n) + Pij = projection(n, i, j) @test isoper(x) @test isoper(p) @test a.dims == ad.dims == N.dims == x.dims == p.dims == [n] @@ -138,6 +144,9 @@ @test commutator(N, a) ≈ -a @test commutator(N, ad) ≈ ad @test all(diag(commutator(x, p))[1:(n-1)] .≈ 1.0im) + @test fock(n, i) == Pij * fock(n, j) + @test_throws ArgumentError projection(n, n, 0) + @test_throws ArgumentError projection(n, 0, n) end @testset "displacement and squeezing operators" begin From e4d671a12527973aa4a888cfb64aafa42101f463 Mon Sep 17 00:00:00 2001 From: cailixun Date: Wed, 26 Nov 2025 15:17:40 +0800 Subject: [PATCH 4/7] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fbea819e..b8f5151f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Release date: 2025-11-19 - Add `spre` and `spost` methods for `ComposedOperator` and cache propagator in every time evolution solver. ([#596]) +- Add error message for bad input in state/operator generating functions ([#603]) ## [v0.39.0] Release date: 2025-11-17 @@ -381,3 +382,4 @@ Release date: 2024-11-13 [#589]: https://github.com/qutip/QuantumToolbox.jl/issues/589 [#591]: https://github.com/qutip/QuantumToolbox.jl/issues/591 [#596]: https://github.com/qutip/QuantumToolbox.jl/issues/596 +[#603]: https://github.com/qutip/QuantumToolbox.jl/issues/603 From 9670da18ff0b9ed6c0fd325b000f7a6c8c97f831 Mon Sep 17 00:00:00 2001 From: Li-Xun Cai <157601901+TendonFFF@users.noreply.github.com> Date: Wed, 26 Nov 2025 21:19:42 +0800 Subject: [PATCH 5/7] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8f5151f1..84bc5139e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main) +- Add error message for bad input in state/operator generating functions ([#603]) ## [v0.39.1] Release date: 2025-11-19 - Add `spre` and `spost` methods for `ComposedOperator` and cache propagator in every time evolution solver. ([#596]) -- Add error message for bad input in state/operator generating functions ([#603]) ## [v0.39.0] Release date: 2025-11-17 From 8334e8125011c741c76dfcf9b4bd523e30264168 Mon Sep 17 00:00:00 2001 From: cailixun Date: Thu, 27 Nov 2025 14:57:43 +0800 Subject: [PATCH 6/7] change to `DomainError` --- src/qobj/operators.jl | 4 ++-- src/qobj/states.jl | 8 ++++---- test/core-test/states_and_operators.jl | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/qobj/operators.jl b/src/qobj/operators.jl index b921e349a..b921f1926 100644 --- a/src/qobj/operators.jl +++ b/src/qobj/operators.jl @@ -494,8 +494,8 @@ end Generates the projection operator ``\hat{O} = |i \rangle\langle j|`` with Hilbert space dimension `N`. """ function projection(N::Int, i::Int, j::Int) - (0 <= i < N) || throw(ArgumentError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) - (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) + (0 <= i < N) || throw(DomainError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) + (0 <= j < N) || throw(DomainError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) return QuantumObject(sparse([i + 1], [j + 1], [1.0 + 0.0im], N, N), type = Operator(), dims = N) end diff --git a/src/qobj/states.jl b/src/qobj/states.jl index 38cddd6c9..749788708 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -38,7 +38,7 @@ It is also possible to specify the list of dimensions `dims` if different subsys `basis(N, j; dims = dims, sparse = sparse)` is a synonym of `fock(N, j; dims = dims, sparse = sparse)`. """ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N, sparse::Union{Bool,Val} = Val(false)) - (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) + (0 <= j < N) || throw(DomainError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else @@ -311,7 +311,7 @@ Returns the `n`-qubit [W-state](https://en.wikipedia.org/wiki/W_state): If you want to keep type stability, it is recommended to use `w_state(Val(n))` instead of `w_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function w_state(::Val{n}) where {n} - (n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2")) + (n >= 2) || throw(DomainError("Invalid argument n, must satisfy: n ≥ 2")) nzind = 2 .^ (0:(n-1)) .+ 1 nzval = fill(ComplexF64(1 / sqrt(n)), n) @@ -336,8 +336,8 @@ Here, `d` specifies the dimension of each qudit. Default to `d=2` (qubit). If you want to keep type stability, it is recommended to use `ghz_state(Val(n))` instead of `ghz_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function ghz_state(::Val{n}; d::Int = 2) where {n} - (n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2")) - (d >= 2) || throw(ArgumentError("Invalid argument d, must satisfy: d ≥ 2")) + (n >= 2) || throw(DomainError("Invalid argument n, must satisfy: n ≥ 2")) + (d >= 2) || throw(DomainError("Invalid argument d, must satisfy: d ≥ 2")) nzind = collect((0:(d-1)) .* Int((d^n - 1) / (d - 1)) .+ 1) nzval = fill(ComplexF64(1 / sqrt(d)), d) diff --git a/test/core-test/states_and_operators.jl b/test/core-test/states_and_operators.jl index ad2814233..59d4c78cf 100644 --- a/test/core-test/states_and_operators.jl +++ b/test/core-test/states_and_operators.jl @@ -20,7 +20,7 @@ # fock, basis, and fock_dm @test fock_dm(4; dims = (2, 2), sparse = true) ≈ ket2dm(basis(4; dims = (2, 2))) @test_throws DimensionMismatch fock(4; dims = 2) - @test_throws ArgumentError fock(4, 4) + @test_throws DomainError fock(4, 4) end @testset "coherent state" begin @@ -122,9 +122,9 @@ @test_throws ArgumentError bell_state(0, 2) @test_throws ArgumentError bell_state(3, 1) @test_throws ArgumentError bell_state(2, 3) - @test_throws ArgumentError w_state(1) - @test_throws ArgumentError ghz_state(1) - @test_throws ArgumentError ghz_state(2; d = 1) + @test_throws DomainError w_state(1) + @test_throws DomainError ghz_state(1) + @test_throws DomainError ghz_state(2; d = 1) end @testset "bosonic operators" begin @@ -145,8 +145,8 @@ @test commutator(N, ad) ≈ ad @test all(diag(commutator(x, p))[1:(n-1)] .≈ 1.0im) @test fock(n, i) == Pij * fock(n, j) - @test_throws ArgumentError projection(n, n, 0) - @test_throws ArgumentError projection(n, 0, n) + @test_throws DomainError projection(n, n, 0) + @test_throws DomainError projection(n, 0, n) end @testset "displacement and squeezing operators" begin From b91b46fd9da16683a54f50aca624a11125c774ac Mon Sep 17 00:00:00 2001 From: cailixun Date: Thu, 27 Nov 2025 15:44:29 +0800 Subject: [PATCH 7/7] back to `ArgumentError` --- src/qobj/operators.jl | 4 ++-- src/qobj/states.jl | 8 ++++---- test/core-test/states_and_operators.jl | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/qobj/operators.jl b/src/qobj/operators.jl index b921f1926..b921e349a 100644 --- a/src/qobj/operators.jl +++ b/src/qobj/operators.jl @@ -494,8 +494,8 @@ end Generates the projection operator ``\hat{O} = |i \rangle\langle j|`` with Hilbert space dimension `N`. """ function projection(N::Int, i::Int, j::Int) - (0 <= i < N) || throw(DomainError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) - (0 <= j < N) || throw(DomainError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) + (0 <= i < N) || throw(ArgumentError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1")) + (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) return QuantumObject(sparse([i + 1], [j + 1], [1.0 + 0.0im], N, N), type = Operator(), dims = N) end diff --git a/src/qobj/states.jl b/src/qobj/states.jl index 749788708..38cddd6c9 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -38,7 +38,7 @@ It is also possible to specify the list of dimensions `dims` if different subsys `basis(N, j; dims = dims, sparse = sparse)` is a synonym of `fock(N, j; dims = dims, sparse = sparse)`. """ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N, sparse::Union{Bool,Val} = Val(false)) - (0 <= j < N) || throw(DomainError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) + (0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1")) if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else @@ -311,7 +311,7 @@ Returns the `n`-qubit [W-state](https://en.wikipedia.org/wiki/W_state): If you want to keep type stability, it is recommended to use `w_state(Val(n))` instead of `w_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function w_state(::Val{n}) where {n} - (n >= 2) || throw(DomainError("Invalid argument n, must satisfy: n ≥ 2")) + (n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2")) nzind = 2 .^ (0:(n-1)) .+ 1 nzval = fill(ComplexF64(1 / sqrt(n)), n) @@ -336,8 +336,8 @@ Here, `d` specifies the dimension of each qudit. Default to `d=2` (qubit). If you want to keep type stability, it is recommended to use `ghz_state(Val(n))` instead of `ghz_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details. """ function ghz_state(::Val{n}; d::Int = 2) where {n} - (n >= 2) || throw(DomainError("Invalid argument n, must satisfy: n ≥ 2")) - (d >= 2) || throw(DomainError("Invalid argument d, must satisfy: d ≥ 2")) + (n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2")) + (d >= 2) || throw(ArgumentError("Invalid argument d, must satisfy: d ≥ 2")) nzind = collect((0:(d-1)) .* Int((d^n - 1) / (d - 1)) .+ 1) nzval = fill(ComplexF64(1 / sqrt(d)), d) diff --git a/test/core-test/states_and_operators.jl b/test/core-test/states_and_operators.jl index 59d4c78cf..ad2814233 100644 --- a/test/core-test/states_and_operators.jl +++ b/test/core-test/states_and_operators.jl @@ -20,7 +20,7 @@ # fock, basis, and fock_dm @test fock_dm(4; dims = (2, 2), sparse = true) ≈ ket2dm(basis(4; dims = (2, 2))) @test_throws DimensionMismatch fock(4; dims = 2) - @test_throws DomainError fock(4, 4) + @test_throws ArgumentError fock(4, 4) end @testset "coherent state" begin @@ -122,9 +122,9 @@ @test_throws ArgumentError bell_state(0, 2) @test_throws ArgumentError bell_state(3, 1) @test_throws ArgumentError bell_state(2, 3) - @test_throws DomainError w_state(1) - @test_throws DomainError ghz_state(1) - @test_throws DomainError ghz_state(2; d = 1) + @test_throws ArgumentError w_state(1) + @test_throws ArgumentError ghz_state(1) + @test_throws ArgumentError ghz_state(2; d = 1) end @testset "bosonic operators" begin @@ -145,8 +145,8 @@ @test commutator(N, ad) ≈ ad @test all(diag(commutator(x, p))[1:(n-1)] .≈ 1.0im) @test fock(n, i) == Pij * fock(n, j) - @test_throws DomainError projection(n, n, 0) - @test_throws DomainError projection(n, 0, n) + @test_throws ArgumentError projection(n, n, 0) + @test_throws ArgumentError projection(n, 0, n) end @testset "displacement and squeezing operators" begin