From b774c62bd6d8063c479122a98c3a40a2ebb6ba9f Mon Sep 17 00:00:00 2001 From: Orjan Ameye Date: Fri, 3 Apr 2026 09:44:24 +0200 Subject: [PATCH] refactor: consolidate interaction picture functions into a single interaction_picture_A function --- docs/src/api.md | 10 +- ...action-picture__PRA2023_107-013706_fig2.md | 2 +- docs/src/examples/08-1_pulse-delay__simple.md | 2 +- docs/src/implementation.md | 2 +- ...action-picture__PRA2023_107-013706_fig2.jl | 2 +- examples/08-1_pulse-delay__simple.jl | 2 +- src/QuantumInputOutput.jl | 7 +- src/interaction_picture.jl | 98 ++++++------------- test/test_interaction_picture.jl | 2 +- 9 files changed, 40 insertions(+), 87 deletions(-) diff --git a/docs/src/api.md b/docs/src/api.md index ca17600..78274a6 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -93,15 +93,7 @@ interaction_picture_M_2modes_equal ``` ```@docs -interaction_picture_A_2modes -``` - -```@docs -interaction_picture_A_3modes -``` - -```@docs -interaction_picture_A_4modes +interaction_picture_A ``` ## [Correlations](@id API: Correlations) diff --git a/docs/src/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.md b/docs/src/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.md index f25ae6c..b827ded 100644 --- a/docs/src/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.md +++ b/docs/src/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.md @@ -98,7 +98,7 @@ gu_t = u_to_gu(u, T) gv_t = v_to_gv(u, T) # identical output mode v(t) = u(t) # interaction-picture coefficient matrix M(t) for u ↔ v -A_uv = interaction_picture_A_2modes(gu_t, gv_t) +A_uv = interaction_picture_A(gu_t, gv_t) M_t = interaction_picture_M(A_uv, T) # constant and time-dependent parameters diff --git a/docs/src/examples/08-1_pulse-delay__simple.md b/docs/src/examples/08-1_pulse-delay__simple.md index 4545576..921cd89 100644 --- a/docs/src/examples/08-1_pulse-delay__simple.md +++ b/docs/src/examples/08-1_pulse-delay__simple.md @@ -179,7 +179,7 @@ nothing # hide ````@example 08-1_pulse-delay__simple # interaction-picture coefficient matrix M(t) for u ↔ d -A_ud = interaction_picture_A_2modes(gu_, gin_) +A_ud = interaction_picture_A(gu_, gin_) M_t = interaction_picture_M(A_ud, T) M_ls = [M(i, j) for i = 1:la for j = 1:la] diff --git a/docs/src/implementation.md b/docs/src/implementation.md index 91f1582..9fc4cf3 100644 --- a/docs/src/implementation.md +++ b/docs/src/implementation.md @@ -121,7 +121,7 @@ A(t) = \frac{1}{2}\begin{bmatrix} \end{bmatrix} ``` -The functions [`interaction_picture_A_2modes`](@ref), [`interaction_picture_A_3modes`](@ref), and [`interaction_picture_A_4modes`](@ref) build the coupling matrices for two, three and four modes. For two equal modes ($u(t) = v(t)$) the analytic solution of $M(t)$ is provided by [`interaction_picture_M_2modes_equal`](@ref). +The function [`interaction_picture_A`](@ref) builds the coupling matrix for any number of modes. For two equal modes ($u(t) = v(t)$) the analytic solution of $M(t)$ is provided by [`interaction_picture_M_2modes_equal`](@ref). Using the interaction picture for scattering with a Fock state $| n=20 \rangle$ on a two-level system, is demonstrated in the example [Interaction Picture Scattering with a Quantum Pulse](examples/06-1_interaction-picture__PRA2023_107-013706_fig2.md). diff --git a/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.jl b/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.jl index 77bf436..6da9213 100644 --- a/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.jl +++ b/examples/06-1_interaction-picture__PRA2023_107-013706_fig2.jl @@ -87,7 +87,7 @@ gu_t = u_to_gu(u, T) gv_t = v_to_gv(u, T) # identical output mode v(t) = u(t) ## interaction-picture coefficient matrix M(t) for u ↔ v -A_uv = interaction_picture_A_2modes(gu_t, gv_t) +A_uv = interaction_picture_A(gu_t, gv_t) M_t = interaction_picture_M(A_uv, T) ## constant and time-dependent parameters diff --git a/examples/08-1_pulse-delay__simple.jl b/examples/08-1_pulse-delay__simple.jl index 7b81ae5..2301cca 100644 --- a/examples/08-1_pulse-delay__simple.jl +++ b/examples/08-1_pulse-delay__simple.jl @@ -177,7 +177,7 @@ nothing # hide # ## interaction-picture coefficient matrix M(t) for u ↔ d -A_ud = interaction_picture_A_2modes(gu_, gin_) +A_ud = interaction_picture_A(gu_, gin_) M_t = interaction_picture_M(A_ud, T) M_ls = [M(i, j) for i = 1:la for j = 1:la] diff --git a/src/QuantumInputOutput.jl b/src/QuantumInputOutput.jl index 2542e73..c6b3970 100644 --- a/src/QuantumInputOutput.jl +++ b/src/QuantumInputOutput.jl @@ -38,12 +38,7 @@ export SLH, # SLH.jl two_time_corr_matrix, interaction_picture_M, # interaction picture interaction_picture_M_2modes_equal, - interaction_picture_A_2modes, - interaction_picture_A_3modes, - interaction_picture_A_4modes, - interaction_picture_A_uv, - interaction_picture_A_ucv, - interaction_picture_A_uuvv, + interaction_picture_A, substitute_operators include("SLH.jl") diff --git a/src/interaction_picture.jl b/src/interaction_picture.jl index e22d806..62f1707 100644 --- a/src/interaction_picture.jl +++ b/src/interaction_picture.jl @@ -61,88 +61,54 @@ end _as_time_function(x) = x isa Function ? x : (_ -> x) """ - interaction_picture_A_2modes(g1, g2) + interaction_picture_A(gs) + interaction_picture_A(g1, g2, gs...) -Coefficient matrix `A(t)` for two virtual modes `(1, 2)`, +Coefficient matrix `A(t)` for `N` interacting modes with couplings `gs = [g_1, …, g_N]`. +All couplings may be time-dependent functions or constants. + +The anti-Hermitian matrix has entries ```math -A(t) = \\frac{1}{2} -\\begin{bmatrix} -0 & g_1(t) g_2^*(t) \\\\ --g_1^*(t) g_2(t) & 0 -\\end{bmatrix} +A_{ij}(t) = \\tfrac{1}{2}\\,g_i(t)\\,g_j^*(t), \\quad i < j, +\\qquad A_{ji} = -A_{ij}^*, +\\qquad A_{ii} = 0. ``` -All couplings may be time-dependent or constant. -""" -function interaction_picture_A_2modes(g1, g2) - g1f = _as_time_function(g1) - g2f = _as_time_function(g2) - A(t) = 0.5 * [ - 0 g1f(t) * conj(g2f(t)); - -conj(g1f(t)) * g2f(t) 0 - ] - return A -end -interaction_picture_A_2modes(g_ls) = interaction_picture_A_2modes(g_ls...) - -""" - interaction_picture_A_3modes(g1, g2, g3) - -Coefficient matrix `A(t)` for three interacting modes ordered as `(1, 2, 3)` +For two modes this gives ```math A(t) = \\frac{1}{2} \\begin{bmatrix} -0 & g_1(t) g_2^*(t) & g_1(t) g_3^*(t) \\\\ --g_1^*(t) g_2(t) & 0 & g_2(t) g_3^*(t) \\\\ --g_1^*(t) g_3(t) & -g_2^*(t) g_3(t) & 0 -\\end{bmatrix} +0 & g_1(t)\\, g_2^*(t) \\\\ +-g_1^*(t)\\, g_2(t) & 0 +\\end{bmatrix}, ``` -All couplings may be time-dependent or constant. -""" -function interaction_picture_A_3modes(g1, g2, g3) - g1f = _as_time_function(g1) - g2f = _as_time_function(g2) - g3f = _as_time_function(g3) - A(t) = - 0.5 * [ - 0 conj(g2f(t)) * g1f(t) g1f(t) * conj(g3f(t)); - -g2f(t) * conj(g1f(t)) 0 g2f(t) * conj(g3f(t)); - -conj(g1f(t)) * g3f(t) -conj(g2f(t)) * g3f(t) 0 - ] - return A -end - -""" - interaction_picture_A_4modes(g1, g2, g3, g4) - -Coefficient matrix `A(t)` for four interacting modes ordered as `(1, 2, 3, 4)` +and for three modes ```math A(t) = \\frac{1}{2} \\begin{bmatrix} -0 & g_1(t) g_2^*(t) & g_1(t) g_3^*(t) & g_1(t) g_4^*(t) \\\\ --g_1^*(t) g_2(t) & 0 & g_2(t) g_3^*(t) & g_2(t) g_4^*(t) \\\\ --g_1^*(t) g_3(t) & -g_2^*(t) g_3(t) & 0 & g_3(t) g_4^*(t) \\\\ --g_1^*(t) g_4(t) & -g_2^*(t) g_4(t) & -g_3^*(t) g_4(t) & 0 -\\end{bmatrix} +0 & g_1(t)\\, g_2^*(t) & g_1(t)\\, g_3^*(t) \\\\ +-g_1^*(t)\\, g_2(t) & 0 & g_2(t)\\, g_3^*(t) \\\\ +-g_1^*(t)\\, g_3(t) & -g_2^*(t)\\, g_3(t) & 0 +\\end{bmatrix}. ``` - -All couplings may be time-dependent or constant. """ -function interaction_picture_A_4modes(g1, g2, g3, g4) - g1f = _as_time_function(g1) - g2f = _as_time_function(g2) - g3f = _as_time_function(g3) - g4f = _as_time_function(g4) - A(t) = - 0.5 * [ - 0 g1f(t) * conj(g2f(t)) g1f(t) * conj(g3f(t)) g1f(t) * conj(g4f(t)); - -conj(g1f(t)) * g2f(t) 0 g2f(t) * conj(g3f(t)) g2f(t) * conj(g4f(t)); - -conj(g1f(t)) * g3f(t) -conj(g2f(t)) * g3f(t) 0 g3f(t) * conj(g4f(t)); - -conj(g1f(t)) * g4f(t) -conj(g2f(t)) * g4f(t) -conj(g3f(t)) * g4f(t) 0 - ] +function interaction_picture_A(gs) + gfs = _as_time_function.(gs) + n = length(gfs) + function A(t) + g = [gf(t) for gf in gfs] + M = zeros(ComplexF64, n, n) + for i in 1:n, j in (i+1):n + M[i, j] = g[i] * conj(g[j]) + M[j, i] = -conj(M[i, j]) + end + return 0.5 * M + end return A end + +interaction_picture_A(g1, g2, gs...) = interaction_picture_A([g1, g2, gs...]) diff --git a/test/test_interaction_picture.jl b/test/test_interaction_picture.jl index aa634de..eb224dc 100644 --- a/test/test_interaction_picture.jl +++ b/test/test_interaction_picture.jl @@ -56,7 +56,7 @@ using Test gv_t = v_to_gv(u, T) # Interaction-picture coefficient matrices - A_uv = interaction_picture_A_2modes(gu_t, gv_t) + A_uv = interaction_picture_A(gu_t, gv_t) M_num = interaction_picture_M(A_uv, T) M_ana = interaction_picture_M_2modes_equal(u, T)