Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/translate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/test_translate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +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, 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)
Expand Down
Loading