def merge_arg_and_const_arg(arg, const_arg):
    """
    prepares data from arg and const_arg such that they can be passed
    to the general integration routine
    
    arg and const_arg are both assumed to be dictionaries
    
    the merge process must not alter arg nor const_arg
    in order to be used in the jobmanager context
    
    returns the arguments passed to the function
    defining the derivative such that
    args_dgl = arg['args'] + const_arg['args']
    where as arg['args'] and const_arg['args'] have been assumed to be tuples
    
    e.g. 
        arg['args'] = (2, 'low')
        const_arg['args'] = (15, np.pi)
    f will be called with
    f(t, x, 2, 'low', 15, np.pi)
    
    returns further the combined dictionary
    arg + const_arg with the keyword 'args' removed
    
    For any duplicate keys the value will be the value
    from the 'arg' dictionary. 
    """
    
    # allows arg to be a namedtuple (or any other object that
    # can be converted to a dict)
    # the purpose is that dicts are not allowed as keys for
    # the persistent data structure, where as namedtupled are
    # and therefore arg as a neamedtuple may be used to identify
    # the result of this calculation in the database
    if hasattr(arg, '_asdict'):
        arg = arg._asdict()
        
    # same for const_arg, as a reason of consistency
    if hasattr(const_arg, '_asdict'):
        const_arg = const_arg._asdict() 
    
    # extract the args keyword from arg and const_arg
    args_dgl = tuple()
    if 'args' in arg:
        args_dgl += arg['args']
    if 'args' in const_arg:
        args_dgl += const_arg['args']

    kwargs = {}
    kwargs.update(const_arg)
    kwargs.update(arg)
    # remove args as they have been constructed explicitly
    if 'args' in kwargs:
        del kwargs['args']
        
    # remove id, when it comes from the persistentDataServer 
    if 'id' in kwargs:
        del kwargs['id']
    
    return args_dgl, kwargs
dataset/ETHPy150Open cimatosa/jobmanager/jobmanager/clients.py/merge_arg_and_const_arg/original