code: def jacobian_from_model(model, as_functions=False):
      
      # Inverse dict so we can turn functions back into vars in the end
      functions_as_vars = dict((v, k) for k, v in model.vars_as_functions.items())
      # Create the jacobian components. The `vars` here in the model_dict are
      # always of the type D(y, a), but the righthand-side might still contain
      # functions instead of vars depending on the value of `as_functions`.
      jac = {}
      for func, expr in model.function_dict.items():
          for param in model.params:
              target = D(func, param)
              dfdp = expr.diff(param)
              if as_functions:
                  jac[_partial_subs(target, functions_as_vars)] = dfdp
              else:
                  # Turn Function objects back into Variables.
                  dfdp = dfdp.subs(functions_as_vars, evaluate=False)
                  jac[_partial_subs(target, functions_as_vars)] = dfdp
      # Next lines are needed for the Hessian, where the components of model still
      # contain functions instead of vars.
      if as_functions:
          jac.update(model)
      else:
          jac.update({y: expr.subs(functions_as_vars, evaluate=False)
                      for y, expr in model.items()})
      jacobian_model = CallableModel(jac)
      return jacobian_model
docs: Build a :class:`~symfit.core.fit.CallableModel` representing the Jacobian of
      ``model``.
  
      This function make sure the chain rule is correctly applied for
      interdependent variables.
  
      :param model: Any symbolical model-type.
      :param as_functions: If `True`, the result is returned using
          :class:`sympy.core.function.Function` where needed, e.g.
          ``{y(x, a): a * x}`` instead of ``{y: a * x}``.
      :return: :class:`~symfit.core.fit.CallableModel` representing the Jacobian
          of ``model``.