XACC
old_DWAccelerator.hpp
1 /*******************************************************************************
2  * Copyright (c) 2019 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  * Alexander J. McCaskey - initial API and implementation
12  *******************************************************************************/
13 #ifndef QUANTUM_PLUGINS_DWACCELERATOR_HPP_
14 #define QUANTUM_PLUGINS_DWACCELERATOR_HPP_
15 
16 #include "AcceleratorBuffer.hpp"
17 #include "AnnealingProgram.hpp"
18 #include "DWQMI.hpp"
19 #include "RemoteAccelerator.hpp"
20 
21 #include "dwave_sapi.h"
22 
23 using namespace xacc;
24 
25 namespace xacc {
26 namespace quantum {
27 
32 struct DWSolver {
33  std::string name;
34  std::string description;
35  double jRangeMin;
36  double jRangeMax;
37  double hRangeMin;
38  double hRangeMax;
39  int nQubits;
40  std::vector<std::pair<int, int>> edges;
41 };
42 
44 public:
46  DWAccelerator(std::shared_ptr<Client> client) : RemoteAccelerator(client) {}
47 
48  std::vector<std::pair<int, int>> getConnectivity() override;
49 
50  const std::string getSignature() override { return "dwave-internal" + backend; }
51 
52  const std::string processInput(
53  std::shared_ptr<AcceleratorBuffer> buffer,
54  std::vector<std::shared_ptr<CompositeInstruction>> functions) override;
55 
56  void processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
57  const std::string &response) override;
58 
59  void execute(std::shared_ptr<AcceleratorBuffer> buffer,
60  const std::vector<std::shared_ptr<CompositeInstruction>>
61  functions) override {
62  int counter = 0;
63  std::vector<std::shared_ptr<AcceleratorBuffer>> tmpBuffers;
64  for (auto f : functions) {
65  auto tmpBuffer = std::make_shared<AcceleratorBuffer>(
66  buffer->name() + std::to_string(counter), buffer->size());
67  RemoteAccelerator::execute(tmpBuffer, f);
68  buffer->appendChild(buffer->name() + std::to_string(counter), tmpBuffer);
69  counter++;
70  }
71 
72  return;
73  }
74 
75  void initialize(const HeterogeneousMap &params = {}) override;
76  void updateConfiguration(const HeterogeneousMap &config) override {
77  if (config.keyExists<int>("shots")) {
78  shots = config.get<int>("shots");
79  }
80  if (config.stringExists("backend")) {
81  backend = config.getString("backend");
82  }
83  }
84 
85  const std::vector<std::string> configurationKeys() override {
86  return {"shots", "backend"};
87  }
88 
89  const std::string name() const override { return "dwave-internal"; }
90 
91  const std::string description() const override {
92  return "The D-Wave Accelerator executes Ising Hamiltonian parameters "
93  "on a remote D-Wave QPU.";
94  }
95 
96  virtual ~DWAccelerator() {}
97 
98 protected:
99  int shots = 1000;
100  std::string backend = "DW_2000Q_5";
101 
102  std::string apiKey;
103  std::string url;
104  std::map<std::string, DWSolver> availableSolvers;
105 
106  sapi_Connection *connection = nullptr;
107  sapi_Solver *solver = nullptr;
108  const sapi_SolverProperties *solver_properties = nullptr;
109 
110  void searchAPIKey(std::string &key, std::string &url);
111  void findApiKeyInFile(std::string &key, std::string &url,
112  const std::string &p);
113 };
114 
115 } // namespace quantum
116 } // namespace xacc
117 
118 #endif
Definition: old_DWAccelerator.hpp:43
Definition: Accelerator.hpp:25
const std::string name() const override
Definition: old_DWAccelerator.hpp:89
const std::string description() const override
Definition: old_DWAccelerator.hpp:91
Definition: old_DWAccelerator.hpp:32
Definition: heterogeneous.hpp:45
Definition: RemoteAccelerator.hpp:38