From 84b5fd0d3d59c681b06c9c883790823213bca1c7 Mon Sep 17 00:00:00 2001 From: ChristophHotter Date: Wed, 13 May 2026 12:00:00 -0400 Subject: [PATCH 1/3] adjoint_ops kwarg for translate_qo --- src/translate.jl | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/translate.jl b/src/translate.jl index b9f0334..dd792bf 100644 --- a/src/translate.jl +++ b/src/translate.jl @@ -13,6 +13,21 @@ _translate_numeric_raw(op, b; level_map = nothing, operators = Dict(), op_type = _translate_one(b, operators, op_type) = isempty(operators) ? op_type(one(b)) : op_type(one(basis(first(values(operators))))) +function _translate_operator_dict(operators::Dict, adjoint_ops::Bool) + if isempty(operators) || !adjoint_ops + return operators + end + + operators_ = copy(operators) + for (k, v) in operators + k_adj = Base.adjoint(k) + if !haskey(operators_, k_adj) + operators_[k_adj] = Base.adjoint(v) + end + end + return operators_ +end + # simplified, no applicable(), values are Number → wrap, anything else → pass through function _normalize_time_parameter(time_parameter) if isempty(time_parameter) @@ -40,7 +55,7 @@ end """ translate_qo(op, b::QuantumOpticsBase.Basis; parameter=Dict(), time_parameter=Dict(), - level_map=nothing, operators=Dict(), op_type=sparse) + level_map=nothing, operators=Dict(), adjoint_ops=true, op_type=sparse) Translate a symbolic operator `op` into a numeric QuantumOptics.jl operator with the corresponding basis `b`. The dictionary `parameter` substitutes symbolic parameters with numbers. Time-dependent functions can be provide @@ -50,6 +65,8 @@ The kwarg `level_map=nothing` is used to provide the names of levels for `transi The operator type which should be returned can be set with the kwarg `op_type=sparse` and a list of user-defined operators (e.g. on a different basis than `b`) can be provided with the dictionary `operators=Dict()`. These operators will then be used to replace the symbolic expressions. +If `adjoint_ops=true`, adjoint entries are added automatically for operators missing from the +dictionary, e.g. `a => A` also provides `a' => A'`. """ function translate_qo( op, @@ -58,16 +75,18 @@ function translate_qo( time_parameter = Dict(), level_map = nothing, operators = Dict(), + adjoint_ops = true, op_type = sparse, ) tp = _normalize_time_parameter(time_parameter) + operators_ = _translate_operator_dict(operators, adjoint_ops) return _translate_qo( op, b; parameter, time_parameter = tp, level_map, - operators, + operators = operators_, op_type, ) end From bcf285e5b62875c9ce61b06267dae9f03c92414b Mon Sep 17 00:00:00 2001 From: ChristophHotter Date: Wed, 13 May 2026 12:00:16 -0400 Subject: [PATCH 2/3] test --- test/test_translate.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_translate.jl b/test/test_translate.jl index c2dc5f4..5b7a70c 100644 --- a/test/test_translate.jl +++ b/test/test_translate.jl @@ -80,6 +80,7 @@ using Test a_QO2 = destroy(bc1) ⊗ one(ba) σ_QO(i, j) = to_numeric(σ(i, j), b) + @test isequal(a_QO2'σ_QO(1,2), dense(translate_qo(a'σ(1,2), b; operators=Dict([a,σ(1,2)].=>[a_QO2, σ_QO(1,2)]), adjoint_ops=true))) @test isequal(a_QO2, dense(to_numeric(a, b))) @test isequal(translate_qo(Δ, b; parameter = dict_p1), one(b)*Δn) F3 = translate_qo(Δ, b; parameter = dict_p1, time_parameter = dict_p_t2) From 46a9bc4f6dfa330ef394d91b895116efa7eb4660 Mon Sep 17 00:00:00 2001 From: ChristophHotter Date: Wed, 13 May 2026 12:08:48 -0400 Subject: [PATCH 3/3] format --- test/test_translate.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/test_translate.jl b/test/test_translate.jl index 5b7a70c..fdd88c6 100644 --- a/test/test_translate.jl +++ b/test/test_translate.jl @@ -80,7 +80,17 @@ using Test a_QO2 = destroy(bc1) ⊗ one(ba) σ_QO(i, j) = to_numeric(σ(i, j), b) - @test isequal(a_QO2'σ_QO(1,2), dense(translate_qo(a'σ(1,2), b; operators=Dict([a,σ(1,2)].=>[a_QO2, σ_QO(1,2)]), adjoint_ops=true))) + @test isequal( + a_QO2'σ_QO(1, 2), + dense( + translate_qo( + a'σ(1, 2), + b; + operators = Dict([a, σ(1, 2)] .=> [a_QO2, σ_QO(1, 2)]), + adjoint_ops = true, + ), + ), + ) @test isequal(a_QO2, dense(to_numeric(a, b))) @test isequal(translate_qo(Δ, b; parameter = dict_p1), one(b)*Δn) F3 = translate_qo(Δ, b; parameter = dict_p1, time_parameter = dict_p_t2)