qpu_handler.hpp 1.39 KB
Newer Older
Mccaskey, Alex's avatar
Mccaskey, Alex committed
1
2
3
4
#ifndef RUNTIME_QPU_HANDLER_HPP_
#define RUNTIME_QPU_HANDLER_HPP_

#include "XACC.hpp"
5
6
7
8
9
#include "qcor.hpp"
#include "Function.hpp"
#include "AcceleratorBuffer.hpp"
#include "InstructionIterator.hpp"
#include <string>
Mccaskey, Alex's avatar
Mccaskey, Alex committed
10
11
12
13
14

namespace qcor {

class qpu_handler {

15
16
17
18
protected:

  std::shared_ptr<xacc::AcceleratorBuffer> buffer;

Mccaskey, Alex's avatar
Mccaskey, Alex committed
19
public:
20
21
22
23
24

  std::shared_ptr<xacc::AcceleratorBuffer> getResults() {
      return buffer;
  }

Mccaskey, Alex's avatar
Mccaskey, Alex committed
25
26
  template <typename QuantumKernel>
  void vqe(QuantumKernel &&kernel, double observable, double optimizer) {
27
    xacc::info("[qcor] Executing vqe! :)");
Mccaskey, Alex's avatar
Mccaskey, Alex committed
28
29
  }

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  template <typename QuantumKernel> void execute(QuantumKernel &&kernel) {
    // xacc::info("[qcor] Executing circuit! :)");
    auto function = qcor::loadCompiledCircuit(kernel());

    int maxBitIdx = 0;
    xacc::InstructionIterator it(function);
      while (it.hasNext()) {
        auto nextInst = it.next();
        if (nextInst->isEnabled()) {
          for (auto& i : nextInst->bits()) {
              if (maxBitIdx < i) {
                  maxBitIdx = i;
              }
          }
        }
      }

    maxBitIdx++;

    // auto function = kernel();
    auto accelerator = xacc::getAccelerator();
    buffer = accelerator->createBuffer("q", maxBitIdx);
    accelerator->execute(buffer, function);
  }
Mccaskey, Alex's avatar
Mccaskey, Alex committed
54
55
56
57
58
59
60
61

  template <typename QuantumKernel>
  void execute(const std::string &algorithm, QuantumKernel &&kernel) {}
};

} // namespace qcor

#endif