diff --git a/quantum/plugins/optimizers/nlopt-optimizers/nlopt_optimizer.cpp b/quantum/plugins/optimizers/nlopt-optimizers/nlopt_optimizer.cpp index 3f99ae033..c1ed058c2 100644 --- a/quantum/plugins/optimizers/nlopt-optimizers/nlopt_optimizer.cpp +++ b/quantum/plugins/optimizers/nlopt-optimizers/nlopt_optimizer.cpp @@ -59,7 +59,7 @@ OptResult NLOptimizer::optimize(OptFunction &function) { auto dim = function.dimensions(); nlopt::algorithm algo = nlopt::algorithm::LN_COBYLA; - double tol = 1e-6; + double tol = 1e-6, absFTol = 1e-6, relFTol = 1e-6, absXTol = 1e-6, relXTol = 1e-6; int maxeval = 1000; bool maximize = false; @@ -98,6 +98,34 @@ OptResult NLOptimizer::optimize(OptFunction &function) { xacc::info("[NLOpt] function tolerance set to " + std::to_string(tol)); } + if (options.keyExists("absolute-ftol")) { + absFTol = options.get("absolute-ftol"); + xacc::info("[NLOpt] absolute function tolerance set to " + std::to_string(absFTol)); + } else { + absFTol = tol; + } + + if (options.keyExists("relative-ftol")) { + relFTol = options.get("relative-ftol"); + xacc::info("[NLOpt] relative function tolerance set to " + std::to_string(relFTol)); + } else { + relFTol = tol; + } + + if (options.keyExists("absolute-xtol")) { + absXTol = options.get("absolute-xtol"); + xacc::info("[NLOpt] absolute parameter tolerance set to " + std::to_string(absXTol)); + } else { + absXTol = tol; + } + + if (options.keyExists("relative-xtol")) { + relXTol = options.get("relative-xtol"); + xacc::info("[NLOpt] relative parameter tolerance set to " + std::to_string(relXTol)); + } else { + relXTol = tol; + } + if (options.keyExists("maxeval")) { maxeval = options.get("maxeval"); xacc::info("[NLOpt] max function evaluations set to " + @@ -154,7 +182,10 @@ OptResult NLOptimizer::optimize(OptFunction &function) { _opt.set_lower_bounds(lowerBounds); _opt.set_upper_bounds(upperBounds); _opt.set_maxeval(maxeval); - _opt.set_ftol_rel(tol); + _opt.set_ftol_rel(relFTol); + _opt.set_ftol_abs(absFTol); + _opt.set_xtol_rel(relXTol); + _opt.set_xtol_abs(absXTol); if (options.keyExists("stopval")) { const double stopVal = options.get("stopval");