Skip to content

Commit 0b7a2b5

Browse files
Fix type-instabilities error
1 parent 371af73 commit 0b7a2b5

File tree

4 files changed

+12
-78
lines changed

4 files changed

+12
-78
lines changed

src/qobj/quantum_object_evo.jl

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -349,77 +349,11 @@ Parse the `op_func_list` and generate the data for the `QuantumObjectEvolution`
349349
# Arguments
350350
- `op_func_list::Tuple`: A tuple of tuples or operators.
351351
=#
352-
# @generated function _QobjEvo_generate_data(op_func_list::Tuple)
353-
# op_func_list_types = op_func_list.parameters
354-
# N = length(op_func_list_types)
355-
356-
# dims_expr = ()
357-
# func_methods_expr = ()
358-
# first_op = nothing
359-
# data_expr = :(0)
360-
# qobj_expr_const = :(0)
361-
362-
# for i in 1:N
363-
# op_func_type = op_func_list_types[i]
364-
# if op_func_type <: Tuple
365-
# # check the structure of the tuple
366-
# length(op_func_type.parameters) == 2 || throw(ArgumentError("The tuple must have two elements."))
367-
# op_type = op_func_type.parameters[1]
368-
# func_type = op_func_type.parameters[2]
369-
# ((isoper(op_type) || issuper(op_type)) && func_type <: Function) || throw(
370-
# ArgumentError(
371-
# "The first element must be a Operator or SuperOperator, and the second element must be a function.",
372-
# ),
373-
# )
374-
375-
# op = :(op_func_list[$i][1])
376-
# dims_expr = (dims_expr..., :($op.dimensions))
377-
# func_methods_expr = (func_methods_expr..., :(methods(op_func_list[$i][2], [Any, Real]).ms)) # [Any, Real] means each func must accept 2 arguments
378-
# if i == 1
379-
# first_op = :($op)
380-
# end
381-
# data_expr = :($data_expr + _make_SciMLOperator(op_func_list[$i]))
382-
# else
383-
# op_type = op_func_type
384-
# (isoper(op_type) || issuper(op_type)) ||
385-
# throw(ArgumentError("The element must be a Operator or SuperOperator."))
386-
387-
# dims_expr = (dims_expr..., :(op_func_list[$i].dimensions))
388-
# if i == 1
389-
# first_op = :(op_func_list[$i])
390-
# end
391-
# qobj_expr_const = :($qobj_expr_const + op_func_list[$i])
392-
# end
393-
# end
394-
395-
# quote
396-
# # check the dims of the operators
397-
# dims = tuple($(dims_expr...))
398-
# allequal(dims) || throw(ArgumentError("The dimensions of the operators must be the same."))
399-
400-
# # check if each func accepts 2 arguments
401-
# func_methods = tuple($(func_methods_expr...))
402-
# for i in eachindex(func_methods)
403-
# length(func_methods[i]) == 0 && throw(
404-
# ArgumentError(
405-
# "The following function must only accept two arguments: `$(nameof(op_func_list[i][2]))(p, t)` with t<:Real",
406-
# ),
407-
# )
408-
# end
409-
410-
# data_expr_const = $qobj_expr_const isa Integer ? $qobj_expr_const : _make_SciMLOperator($qobj_expr_const)
411-
412-
# data_expr = data_expr_const + $data_expr
413-
414-
# return $first_op, data_expr
415-
# end
416-
# end
417-
418-
Base.@constprop :aggressive function _QobjEvo_generate_data(op_func_list::Tuple)
352+
function _QobjEvo_generate_data(op_func_list::Tuple)
419353
first_op = _QobjEvo_get_first_op(op_func_list[1])
420354

421355
ops_constant = filter(op_func_list) do x
422-
if x isa AbstractQuantumObject
356+
if x isa QuantumObject
423357
x.type == first_op.type || throw(ArgumentError("The types of the operators must be the same."))
424358
x.dimensions == first_op.dimensions ||
425359
throw(ArgumentError("The dimensions of the operators must be the same."))
@@ -440,18 +374,18 @@ Base.@constprop :aggressive function _QobjEvo_generate_data(op_func_list::Tuple)
440374
op.dimensions == first_op.dimensions ||
441375
throw(ArgumentError("The dimensions of the operators must be the same."))
442376
return true
443-
elseif x isa AbstractQuantumObject
377+
elseif x isa QuantumObject
444378
return false
445379
else
446380
throw(ArgumentError("Each element of the tuple must be either a QuantumObject or a Tuple."))
447381
end
448382
end
449383

450-
data_const = sum(_make_SciMLOperator, ops_constant; init = zero(eltype(first_op))*I)
384+
data_const = isempty(ops_constant) ? zero(eltype(first_op)) : _make_SciMLOperator(sum(ops_constant))
451385
data_td =
452386
length(ops_time_dep) == 1 ? _make_SciMLOperator(ops_time_dep[1]) :
453387
AddedOperator(map(_make_SciMLOperator, ops_time_dep))
454-
data = isempty(ops_constant) ? data_td : data_const + data_td
388+
data = data_const + data_td
455389

456390
return first_op, data
457391
end

src/time_evolution/mcsolve.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ function _normalize_state!(u, dims, normalize_states)
2626
end
2727

2828
function _mcsolve_make_Heff_QobjEvo(H::QuantumObject, c_ops)
29-
c_ops isa Nothing && return QobjEvo(H)
30-
return QobjEvo(H - 1im * mapreduce(op -> op' * op, +, c_ops) / 2)
29+
c_ops isa Nothing && return QuantumObjectEvolution(H)
30+
return QuantumObjectEvolution(H - 1im * mapreduce(op -> op' * op, +, c_ops) / 2)
3131
end
3232
function _mcsolve_make_Heff_QobjEvo(H::Tuple, c_ops)
33-
c_ops isa Nothing && return QobjEvo(H)
34-
return QobjEvo((H..., -1im * sum(op -> op' * op, c_ops) / 2))
33+
c_ops isa Nothing && return QuantumObjectEvolution(H)
34+
return QuantumObjectEvolution((H..., -1im * sum(op -> op' * op, c_ops) / 2))
3535
end
3636
function _mcsolve_make_Heff_QobjEvo(H::QuantumObjectEvolution, c_ops)
3737
c_ops isa Nothing && return H
38-
return H + QobjEvo(sum(op -> -1im * op' * op / 2, c_ops))
38+
return H + QuantumObjectEvolution(sum(op -> -1im * op' * op / 2, c_ops))
3939
end
4040

4141
@doc raw"""

src/time_evolution/smesolve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function smesolveProblem(
119119
# TODO: # Currently, we are assuming a time-independent MatrixOperator
120120
# Also, the u state may become non-hermitian, so Tr[Sn * ρ + ρ * Sn'] != real(Tr[Sn * ρ]) / 2
121121
op_vec = mat2vec(adjoint(op.A))
122-
return _spre(op, Id) + _spost(op', Id) + _smesolve_ScalarOperator(op_vec) * Id_op
122+
return AddedOperator(_spre(op, Id), _spost(op', Id), _smesolve_ScalarOperator(op_vec) * Id_op)
123123
end
124124
D = DiffusionOperator(D_l)
125125

src/time_evolution/ssesolve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function ssesolveProblem(
113113
sc_ops_evo_data,
114114
)
115115

116-
K = get_data(-1im * QobjEvo(H_eff_evo)) + K_l
116+
K = get_data(-1im * QuantumObjectEvolution(H_eff_evo)) + K_l
117117

118118
D_l = map(op -> op + _ScalarOperator_e(op, -) * IdentityOperator(prod(dims)), sc_ops_evo_data)
119119
D = DiffusionOperator(D_l)

0 commit comments

Comments
 (0)