Introduce function similar to `build_optim_fn`
Introduce function similar to
build_optim_fn