Skip to content

Commit

Permalink
Merge pull request #515 from 1tnguyen/tnguyen/maxcut-qaoa-gradient
Browse files Browse the repository at this point in the history
Maxcut QAOA to allow setting gradient strategy
  • Loading branch information
1tnguyen authored Feb 14, 2022
2 parents 73a4f68 + ed726db commit 577cef4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions quantum/plugins/algorithms/qaoa/qaoa_maxcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ namespace algorithm {
if (parameters.keyExists<bool>("shuffle-terms")) {
m_shuffleTerms = parameters.get<bool>("shuffle-terms");
}

if (parameters.stringExists("gradient_strategy")) {
gradientStrategy = xacc::getService<AlgorithmGradientStrategy>(
parameters.getString("gradient_strategy"));
gradientStrategy->initialize({{"observable", m_costHamObs}});
}

if (m_optimizer && m_optimizer->isGradientBased() &&
gradientStrategy == nullptr) {
// No gradient strategy was provided, just use autodiff.
Expand All @@ -294,7 +301,9 @@ namespace algorithm {
m.insert("steps", m_nbSteps);
m.insert("parameter-scheme", "Standard");
m.insert("shuffle-terms", m_shuffleTerms);

if (gradientStrategy) {
m.insert("gradient_strategy", gradientStrategy);
}
if (m_initializationMode == "warm-start") {
m.insert("initial-state", warm_start(m_graph));
} else if (m_initial_state){
Expand All @@ -318,7 +327,9 @@ namespace algorithm {
m.insert("steps", m_nbSteps);
m.insert("parameter-scheme", "Standard");
m.insert("shuffle-terms", m_shuffleTerms);

if (gradientStrategy) {
m.insert("gradient_strategy", gradientStrategy);
}
// If: warm-start selected, call the warm start function
// and use as initial-state.
// Else if: custom initial-state given, pass that to the
Expand Down

0 comments on commit 577cef4

Please sign in to comment.