Unverified Commit 87016df3 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub

Merge pull request #272 from tnguyen-ornl/tnguyen/test-qfast

Fixes for Qfast convergence instability if using mlpack
parents 7b141d9c b619d900
......@@ -368,6 +368,11 @@ std::vector<QFAST::Block> QFAST::refine(const std::vector<QFAST::PauliReps>& in_
// Set the tolerance so that it will terminate when the
// trace distance is sufficiently converged.
optimizer->appendOption("mlpack-tolerance", m_distanceLimit/20.0);
if (optimizer->get_algorithm() == "adam")
{
optimizer->appendOption("adam-exact-objective", true);
}
}
if (needGrads)
......@@ -617,6 +622,10 @@ bool QFAST::optimizeAtDepth(std::vector<PauliReps>& io_repsToOpt, double in_targ
optimizer->appendOption("mlpack-max-iter", maxEval);
optimizer->appendOption("mlpack-step-size", 0.01);
optimizer->appendOption("mlpack-tolerance", in_targetDistance/100.0);
if (optimizer->get_algorithm() == "adam")
{
optimizer->appendOption("adam-exact-objective", true);
}
}
if (needGrads)
......
......@@ -26,6 +26,7 @@ TEST(QFastTester, checkSimple)
// Pick 0 or 1
const int randPick = rand() % 2;
const std::string optimizerName = (randPick == 0) ? "nlopt" : "mlpack";
// Randomly pick an optimizer:
// To save test time, we don't want to run many long tests.
auto optimizer = xacc::getOptimizer(optimizerName);
......
......@@ -102,7 +102,14 @@ OptResult MLPACKOptimizer::optimize(OptFunction &function) {
beta2 = options.get<double>("mlpack-beta2");
}
Adam optimizer(stepSize, 1, beta1, beta2, eps, maxiter, tol, false, false);
// Adam's exactObjective property (default = false)
bool exactObjective = false;
if (options.keyExists<bool>("adam-exact-objective")) {
exactObjective = options.get<bool>("adam-exact-objective");
}
Adam optimizer(stepSize, 1, beta1, beta2, eps, maxiter, tol, false, false,
exactObjective);
results = optimizer.Optimize(f, coordinates);
} else if (mlpack_opt_name == "spsa") {
SPSA optimizer(0.1, 0.102, 0.16, 0.3, 100000, 1e-5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment