XACC
adapt.hpp
1 /*******************************************************************************
2  * Copyright (c) 2020 UT-Battelle, LLC.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and Eclipse Distribution License v1.0 which accompanies this
6  * distribution. The Eclipse Public License is available at
7  * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution
8  *License is available at https://eclipse.org/org/documents/edl-v10.php
9  *
10  * Contributors:
11  * Daniel Claudino - initial API and implementation
12  *******************************************************************************/
13 #ifndef XACC_ALGORITHM_ADAPT_HPP_
14 #define XACC_ALGORITHM_ADAPT_HPP_
15 
16 #include "Algorithm.hpp"
17 #include "Observable.hpp"
18 #include "PauliOperator.hpp"
19 
20 using namespace xacc::quantum;
21 
22 namespace xacc{
23 namespace algorithm{
24 
25 class OperatorPool : public Identifiable {
26 
27 public:
28 
29  virtual bool optionalParameters(const HeterogeneousMap parameters) = 0;
30 
31  virtual std::vector<std::shared_ptr<Observable>>
32  generate(const int &nQubits) = 0;
33 
34  virtual std::string operatorString(const int index) = 0;
35 
36  virtual std::shared_ptr<CompositeInstruction>
37  getOperatorInstructions(const int opIdx, const int varIdx) const = 0;
38 };
39 
40 class ADAPT : public Algorithm {
41 
42 protected:
43  std::shared_ptr<Observable> observable;
44  std::shared_ptr<Optimizer> optimizer;
45  std::shared_ptr<Accelerator> accelerator;
46  std::shared_ptr<OperatorPool> pool;
47  std::shared_ptr<CompositeInstruction> initialState;
48  std::string subAlgo; // sub-algorithm, either VQE or QAOA
49  HeterogeneousMap _parameters;
50 
51  //ADAPT parameters
52  int _maxIter = 50; // max # of ADAPT cycles // # of QAOA layers
53  double _adaptThreshold = 1.0e-2; // gradient norm threshold
54  double _printThreshold = 1.0e-10; // threshold to print commutator
55  bool _printOps = false; // set to true to print operators at every iteration
56  int _nElectrons; // # of electrons, used for VQE
57 
58  std::vector<int> checkpointOps; // indices of operators to construct initial ansatz
59  std::vector<double> checkpointParams; // initial parameters for initial ansatz
60  // name of class to compute gradient for optimization
61  // defaults to parameter shift
62  std::string gradStrategyName = "parameter-shift-gradient";
63 
64 public:
65 
66  bool initialize(const HeterogeneousMap &parameters) override;
67  const std::vector<std::string> requiredParameters() const override;
68  void execute(const std::shared_ptr<AcceleratorBuffer> buffer) const override;
69  const std::string name() const override { return "adapt"; }
70  const std::string description() const override { return ""; }
71 
72  DEFINE_ALGORITHM_CLONE(ADAPT)
73 
74 };
75 
76 
77 } // namespace algorithm
78 } // namespace xacc
79 
80 #endif
Definition: Algorithm.hpp:34
Definition: Accelerator.hpp:25
const std::string description() const override
Definition: adapt.hpp:70
const std::string name() const override
Definition: adapt.hpp:69
Definition: heterogeneous.hpp:45
Definition: adapt.hpp:25
Definition: adapt.hpp:40
Definition: Identifiable.hpp:25
Definition: DefaultParameterSetter.cpp:17