From e18115a5f96039925900013d2b5ee495a3b6fe87 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 5 Apr 2025 14:59:06 +0200 Subject: [PATCH 1/5] [no ci] Make `fock` non-mutating --- src/qobj/states.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qobj/states.jl b/src/qobj/states.jl index 886982f7c..e2d762214 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -37,8 +37,7 @@ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else - array = zeros(ComplexF64, N) - array[j+1] = 1 + array = [j == i ? 1.0 + 0im : 0.0 + 0im for j in 1:N] end return QuantumObject(array; type = Ket, dims = dims) end From eccdf1afa83fa58c6dcffa419f9bce8485452d54 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 5 Apr 2025 15:02:02 +0200 Subject: [PATCH 2/5] Make changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d4d56ddc..100b240dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main) - Make CUDA conversion more general using Adapt.jl. ([#437]) +- Make the generation of `fock` states non-mutating to support Zygote.jl. ([#438]) ## [v0.29.1] Release date: 2025-03-07 @@ -190,3 +191,4 @@ Release date: 2024-11-13 [#428]: https://github.com/qutip/QuantumToolbox.jl/issues/428 [#430]: https://github.com/qutip/QuantumToolbox.jl/issues/430 [#437]: https://github.com/qutip/QuantumToolbox.jl/issues/437 +[#438]: https://github.com/qutip/QuantumToolbox.jl/issues/438 From dd81229c2e7dc175130912ff97a7814d4b5d793e Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 5 Apr 2025 15:32:02 +0200 Subject: [PATCH 3/5] Fix typo error --- src/qobj/states.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qobj/states.jl b/src/qobj/states.jl index e2d762214..ce8af73e3 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -37,7 +37,7 @@ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else - array = [j == i ? 1.0 + 0im : 0.0 + 0im for j in 1:N] + array = [i == j ? 1.0 + 0im : 0.0 + 0im for i in 1:N] end return QuantumObject(array; type = Ket, dims = dims) end From e6e12cb195e43738068f57fe64f9c72644692716 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 5 Apr 2025 16:07:02 +0200 Subject: [PATCH 4/5] Fix another typo --- src/qobj/states.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qobj/states.jl b/src/qobj/states.jl index ce8af73e3..040d2a7de 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -37,7 +37,7 @@ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else - array = [i == j ? 1.0 + 0im : 0.0 + 0im for i in 1:N] + array = [i == (j+1) ? 1.0 + 0im : 0.0 + 0im for i in 1:N] end return QuantumObject(array; type = Ket, dims = dims) end From 6da162c9fd9561f45ebc4a704cb4ad1506dfcbc6 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 5 Apr 2025 16:32:34 +0200 Subject: [PATCH 5/5] Update changelog and format --- CHANGELOG.md | 3 ++- src/qobj/states.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 100b240dc..e06ec247b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main) -- Make CUDA conversion more general using Adapt.jl. ([#437]) +- Make CUDA conversion more general using Adapt.jl. ([#436], [#437]) - Make the generation of `fock` states non-mutating to support Zygote.jl. ([#438]) ## [v0.29.1] @@ -190,5 +190,6 @@ Release date: 2024-11-13 [#423]: https://github.com/qutip/QuantumToolbox.jl/issues/423 [#428]: https://github.com/qutip/QuantumToolbox.jl/issues/428 [#430]: https://github.com/qutip/QuantumToolbox.jl/issues/430 +[#436]: https://github.com/qutip/QuantumToolbox.jl/issues/436 [#437]: https://github.com/qutip/QuantumToolbox.jl/issues/437 [#438]: https://github.com/qutip/QuantumToolbox.jl/issues/438 diff --git a/src/qobj/states.jl b/src/qobj/states.jl index 040d2a7de..784c172aa 100644 --- a/src/qobj/states.jl +++ b/src/qobj/states.jl @@ -37,7 +37,7 @@ function fock(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple} = N if getVal(sparse) array = sparsevec([j + 1], [1.0 + 0im], N) else - array = [i == (j+1) ? 1.0 + 0im : 0.0 + 0im for i in 1:N] + array = [i == (j + 1) ? 1.0 + 0im : 0.0 + 0im for i in 1:N] end return QuantumObject(array; type = Ket, dims = dims) end