@@ -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
457391end
0 commit comments