Skip to content

Commit 371af73

Browse files
Make QobjEvo generation working
1 parent f7695e9 commit 371af73

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/qobj/quantum_object_evo.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,11 @@ Base.@constprop :aggressive function _QobjEvo_generate_data(op_func_list::Tuple)
447447
end
448448
end
449449

450-
data = _make_SciMLOperator(sum(ops_constant; init = zero(eltype(first_op)))) + sum(_make_SciMLOperator, ops_time_dep; init = zero(eltype(first_op)))
450+
data_const = sum(_make_SciMLOperator, ops_constant; init = zero(eltype(first_op))*I)
451+
data_td =
452+
length(ops_time_dep) == 1 ? _make_SciMLOperator(ops_time_dep[1]) :
453+
AddedOperator(map(_make_SciMLOperator, ops_time_dep))
454+
data = isempty(ops_constant) ? data_td : data_const + data_td
451455

452456
return first_op, data
453457
end
@@ -461,8 +465,11 @@ function _QobjEvo_check_op_func(op_func::Tuple)
461465
length(op_func) == 2 || throw(ArgumentError("The tuple must have two elements."))
462466
_QobjEvo_check_op(op_func[1])
463467
(op_func[2] isa Function) || throw(ArgumentError("The second element must be a function."))
464-
methods(op_func[2], (Any, Real)) |> length == 0 &&
465-
throw(ArgumentError("The following function must only accept two arguments: `$(nameof(op_func[2]))(p, t)` with t<:Real"))
468+
methods(op_func[2], (Any, Real)) |> length == 0 && throw(
469+
ArgumentError(
470+
"The following function must only accept two arguments: `$(nameof(op_func[2]))(p, t)` with t<:Real",
471+
),
472+
)
466473
return nothing
467474
end
468475

@@ -479,13 +486,12 @@ _QobjEvo_get_first_op(op_func_list_1::Union{Tuple,AbstractQuantumObject}) =
479486
end
480487

481488
function _make_SciMLOperator(op_func::Tuple)
482-
T = eltype(op_func[1])
483-
update_func = (a, u, p, t) -> op_func[2](p, t)
484-
return ScalarOperator(zero(T), update_func) * _promote_to_scimloperator(op_func[1].data)
489+
op, coef = op_func
490+
T = eltype(op)
491+
update_func = (a, u, p, t) -> coef(p, t)
492+
return ScalarOperator(zero(T), update_func) * _promote_to_scimloperator(op.data)
485493
end
486-
487494
_make_SciMLOperator(op::AbstractQuantumObject) = _promote_to_scimloperator(op.data)
488-
_make_SciMLOperator(op::Number) = op
489495

490496
_promote_to_scimloperator(data::AbstractMatrix) = MatrixOperator(data)
491497
_promote_to_scimloperator(data::AbstractSciMLOperator) = data

0 commit comments

Comments
 (0)