@@ -360,7 +360,7 @@ function QuantumObjectEvolution(
360360 if α isa Nothing
361361 return QuantumObjectEvolution (op. data, type, op. dimensions)
362362 end
363- return QuantumObjectEvolution (α * op. data, type, op. dimensions)
363+ return QuantumObjectEvolution (_promote_to_scimloperator (α, op. data) , type, op. dimensions)
364364end
365365
366366#=
@@ -397,7 +397,6 @@ Parse the `op_func_list` and generate the data for the `QuantumObjectEvolution`
397397 )
398398
399399 op = :(op_func_list[$ i][1 ])
400- data_type = op_type. parameters[1 ]
401400 dims_expr = (dims_expr... , :($ op. dimensions))
402401 func_methods_expr = (func_methods_expr... , :(methods (op_func_list[$ i][2 ], [Any, Real]))) # [Any, Real] means each func must accept 2 arguments
403402 if i == 1
@@ -409,7 +408,6 @@ Parse the `op_func_list` and generate the data for the `QuantumObjectEvolution`
409408 (isoper (op_type) || issuper (op_type)) ||
410409 throw (ArgumentError (" The element must be a Operator or SuperOperator." ))
411410
412- data_type = op_type. parameters[1 ]
413411 dims_expr = (dims_expr... , :(op_func_list[$ i]. dimensions))
414412 if i == 1
415413 first_op = :(op_func_list[$ i])
@@ -445,16 +443,33 @@ function _make_SciMLOperator(op_func::Tuple, α)
445443 T = eltype (op_func[1 ])
446444 update_func = (a, u, p, t) -> op_func[2 ](p, t)
447445 if α isa Nothing
448- return ScalarOperator (zero (T), update_func) * MatrixOperator (op_func[1 ]. data)
446+ return ScalarOperator (zero (T), update_func) * _promote_to_scimloperator (op_func[1 ]. data)
449447 end
450- return ScalarOperator (zero (T), update_func) * MatrixOperator (α * op_func[1 ]. data)
448+ return ScalarOperator (zero (T), update_func) * _promote_to_scimloperator (α, op_func[1 ]. data)
451449end
452450
453- function _make_SciMLOperator (op:: QuantumObject , α)
451+ function _make_SciMLOperator (op:: AbstractQuantumObject , α)
454452 if α isa Nothing
455- return MatrixOperator (op. data)
453+ return _promote_to_scimloperator (op. data)
456454 end
457- return MatrixOperator (α * op. data)
455+ return _promote_to_scimloperator (α, op. data)
456+ end
457+
458+ _promote_to_scimloperator (data:: AbstractMatrix ) = MatrixOperator (data)
459+ _promote_to_scimloperator (data:: AbstractSciMLOperator ) = data
460+ # TODO : The following special cases can be simplified after
461+ # https://github.com/SciML/SciMLOperators.jl/pull/264 is merged
462+ _promote_to_scimloperator (α:: Number , data:: AbstractMatrix ) = MatrixOperator (α * data)
463+ function _promote_to_scimloperator (α:: Number , data:: MatrixOperator )
464+ isconstant (data) && return MatrixOperator (α * data. A)
465+ return ScaledOperator (α, data) # Going back to the generic case
466+ end
467+ function _promote_to_scimloperator (α:: Number , data:: ScaledOperator )
468+ isconstant (data. λ) && return ScaledOperator (α * data. λ, data. L)
469+ return ScaledOperator (data. λ, _promote_to_scimloperator (α, data. L)) # Try to propagate the rule
470+ end
471+ function _promote_to_scimloperator (α:: Number , data:: AbstractSciMLOperator )
472+ return α * data # Going back to the generic case
458473end
459474
460475@doc raw """
0 commit comments