Skip to content

Commit b91b46f

Browse files
author
cailixun
committed
back to ArgumentError
1 parent 8334e81 commit b91b46f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/qobj/operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ end
494494
Generates the projection operator ``\hat{O} = |i \rangle\langle j|`` with Hilbert space dimension `N`.
495495
"""
496496
function projection(N::Int, i::Int, j::Int)
497-
(0 <= i < N) || throw(DomainError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1"))
498-
(0 <= j < N) || throw(DomainError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1"))
497+
(0 <= i < N) || throw(ArgumentError("Invalid argument i, must satisfy: 0 ≤ i ≤ N-1"))
498+
(0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1"))
499499

500500
return QuantumObject(sparse([i + 1], [j + 1], [1.0 + 0.0im], N, N), type = Operator(), dims = N)
501501
end

src/qobj/states.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ It is also possible to specify the list of dimensions `dims` if different subsys
3838
`basis(N, j; dims = dims, sparse = sparse)` is a synonym of `fock(N, j; dims = dims, sparse = sparse)`.
3939
"""
4040
function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N, sparse::Union{Bool,Val} = Val(false))
41-
(0 <= j < N) || throw(DomainError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1"))
41+
(0 <= j < N) || throw(ArgumentError("Invalid argument j, must satisfy: 0 ≤ j ≤ N-1"))
4242
if getVal(sparse)
4343
array = sparsevec([j + 1], [1.0 + 0im], N)
4444
else
@@ -311,7 +311,7 @@ Returns the `n`-qubit [W-state](https://en.wikipedia.org/wiki/W_state):
311311
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.
312312
"""
313313
function w_state(::Val{n}) where {n}
314-
(n >= 2) || throw(DomainError("Invalid argument n, must satisfy: n ≥ 2"))
314+
(n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2"))
315315

316316
nzind = 2 .^ (0:(n-1)) .+ 1
317317
nzval = fill(ComplexF64(1 / sqrt(n)), n)
@@ -336,8 +336,8 @@ Here, `d` specifies the dimension of each qudit. Default to `d=2` (qubit).
336336
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.
337337
"""
338338
function ghz_state(::Val{n}; d::Int = 2) where {n}
339-
(n >= 2) || throw(DomainError("Invalid argument n, must satisfy: n ≥ 2"))
340-
(d >= 2) || throw(DomainError("Invalid argument d, must satisfy: d ≥ 2"))
339+
(n >= 2) || throw(ArgumentError("Invalid argument n, must satisfy: n ≥ 2"))
340+
(d >= 2) || throw(ArgumentError("Invalid argument d, must satisfy: d ≥ 2"))
341341

342342
nzind = collect((0:(d-1)) .* Int((d^n - 1) / (d - 1)) .+ 1)
343343
nzval = fill(ComplexF64(1 / sqrt(d)), d)

test/core-test/states_and_operators.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# fock, basis, and fock_dm
2121
@test fock_dm(4; dims = (2, 2), sparse = true) ket2dm(basis(4; dims = (2, 2)))
2222
@test_throws DimensionMismatch fock(4; dims = 2)
23-
@test_throws DomainError fock(4, 4)
23+
@test_throws ArgumentError fock(4, 4)
2424
end
2525

2626
@testset "coherent state" begin
@@ -122,9 +122,9 @@
122122
@test_throws ArgumentError bell_state(0, 2)
123123
@test_throws ArgumentError bell_state(3, 1)
124124
@test_throws ArgumentError bell_state(2, 3)
125-
@test_throws DomainError w_state(1)
126-
@test_throws DomainError ghz_state(1)
127-
@test_throws DomainError ghz_state(2; d = 1)
125+
@test_throws ArgumentError w_state(1)
126+
@test_throws ArgumentError ghz_state(1)
127+
@test_throws ArgumentError ghz_state(2; d = 1)
128128
end
129129

130130
@testset "bosonic operators" begin
@@ -145,8 +145,8 @@
145145
@test commutator(N, ad) ad
146146
@test all(diag(commutator(x, p))[1:(n-1)] .≈ 1.0im)
147147
@test fock(n, i) == Pij * fock(n, j)
148-
@test_throws DomainError projection(n, n, 0)
149-
@test_throws DomainError projection(n, 0, n)
148+
@test_throws ArgumentError projection(n, n, 0)
149+
@test_throws ArgumentError projection(n, 0, n)
150150
end
151151

152152
@testset "displacement and squeezing operators" begin

0 commit comments

Comments
 (0)