Timo suggested:
# Assume obj and obj_grad are passed
obj = args[0] if args else kwargs.get("obj")
obj_grad args[1] if len(args)>1 else kwargs.get("obj_grad")
It "obj_expr" in kwargs:
if isinstance(args[0], Callable) or isinstance(args[1], Callable):
raise ValueError("The objective function should be provided either as expression ('obj_expr')or as two evaluation functions ('obj', 'obj_grad').")
obj, obj_grad = create_objective_function(...)
else:
args = args[2:] # Something like this
in #122 (comment)