@@ -180,8 +180,19 @@ function QuantumObjectEvolution(
180180 return QuantumObjectEvolution (data, type, dims)
181181end
182182
183- QuantumObjectEvolution (op:: QuantumObject , f:: Function ; type:: Union{Nothing,QuantumObjectType} = nothing ) =
184- QuantumObjectEvolution (((op, f),); type = type)
183+ # this is a extra method if user accidentally specify `QuantumObjectEvolution( (op, func) )` or `QuantumObjectEvolution( ((op, func)) )`
184+ QuantumObjectEvolution (
185+ op_func:: Tuple{QuantumObject,Function} ,
186+ α:: Union{Nothing,Number} = nothing ;
187+ type:: Union{Nothing,QuantumObjectType} = nothing ,
188+ ) = QuantumObjectEvolution ((op_func,), α; type = type)
189+
190+ QuantumObjectEvolution (
191+ op:: QuantumObject ,
192+ f:: Function ,
193+ α:: Union{Nothing,Number} = nothing ;
194+ type:: Union{Nothing,QuantumObjectType} = nothing ,
195+ ) = QuantumObjectEvolution (((op, f),), α; type = type)
185196
186197function QuantumObjectEvolution (
187198 op:: QuantumObject ,
@@ -229,13 +240,15 @@ Parse the `op_func_list` and generate the data for the `QuantumObjectEvolution`
229240 N = length (op_func_list_types)
230241
231242 dims_expr = ()
243+ func_methods_expr = ()
232244 first_op = nothing
233245 data_expr = :(0 )
234246 qobj_expr_const = :(0 )
235247
236248 for i in 1 : N
237249 op_func_type = op_func_list_types[i]
238250 if op_func_type <: Tuple
251+ # check the structure of the tuple
239252 length (op_func_type. parameters) == 2 || throw (ArgumentError (" The tuple must have two elements." ))
240253 op_type = op_func_type. parameters[1 ]
241254 func_type = op_func_type. parameters[2 ]
@@ -248,6 +261,7 @@ Parse the `op_func_list` and generate the data for the `QuantumObjectEvolution`
248261 op = :(op_func_list[$ i][1 ])
249262 data_type = op_type. parameters[1 ]
250263 dims_expr = (dims_expr... , :($ op. dims))
264+ func_methods_expr = (func_methods_expr... , :(methods (op_func_list[$ i][2 ], [Any, Real]))) # [Any, Real] means each func must accept 2 arguments
251265 if i == 1
252266 first_op = :($ op)
253267 end
@@ -267,10 +281,20 @@ Parse the `op_func_list` and generate the data for the `QuantumObjectEvolution`
267281 end
268282
269283 quote
284+ # check the dims of the operators
270285 dims = tuple ($ (dims_expr... ))
271-
272286 allequal (dims) || throw (ArgumentError (" The dimensions of the operators must be the same." ))
273287
288+ # check if each func accepts 2 arguments
289+ func_methods = tuple ($ (func_methods_expr... ))
290+ for f_method in func_methods
291+ length (f_method. ms) == 0 && throw (
292+ ArgumentError (
293+ " The following function must accept two arguments: `$(f_method. mt. name) (p, t)` with t<:Real" ,
294+ ),
295+ )
296+ end
297+
274298 data_expr_const = $ qobj_expr_const isa Integer ? $ qobj_expr_const : _make_SciMLOperator ($ qobj_expr_const, α)
275299
276300 data_expr = data_expr_const + $ data_expr
0 commit comments