QuantumIRProvider.cpp 2.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "QuantumIRProvider.hpp"

// #include "GateFunction.hpp"
#include "GateIR.hpp"
#include "Circuit.hpp"

// #include "GateInstruction.hpp"

// #include "DWFunction.hpp"
// #include "DWQMI.hpp"

#include "CompositeInstruction.hpp"
#include "xacc_service.hpp"
14
#include "XACC.hpp"
15
16
17

namespace xacc {
namespace quantum {
Mccaskey, Alex's avatar
Mccaskey, Alex committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const int QuantumIRProvider::getNRequiredBits(const std::string name) {
  std::shared_ptr<Instruction> inst;
  if (xacc::hasService<Instruction>(name)) {
    inst = xacc::getService<Instruction>(name);
  } else if (xacc::hasContributedService<Instruction>(name)) {
    inst = xacc::getContributedService<Instruction>(name);
  } else if (xacc::hasCompiled(name)) {
    inst = xacc::getCompiled(name);
  } else {
      xacc::error("Invalid instruction name - " + name);
  }
  return inst->nRequiredBits();
}

32
33
34
35
36
37
38
39
std::shared_ptr<Instruction> QuantumIRProvider::createInstruction(const std::string name,
                                                         std::size_t bit) {
  return createInstruction(name, std::vector<std::size_t>{bit});
}

std::shared_ptr<Instruction> QuantumIRProvider::createInstruction(
    const std::string name, std::vector<std::size_t> bits,
    std::vector<InstructionParameter> parameters) {
40

41
  std::shared_ptr<Instruction> inst;
42
  if (xacc::hasService<Instruction>(name)) {
43
    inst = xacc::getService<Instruction>(name);
44
45
46
47
48
49
50
  } else if (xacc::hasContributedService<Instruction>(name)) {
    inst = xacc::getContributedService<Instruction>(name);
  } else if (xacc::hasCompiled(name)) {
    inst = xacc::getCompiled(name);
  } else {
      xacc::error("Invalid instruction name - " + name);
  }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

  if (!inst->isComposite()) {
    inst->setBits(bits);
    int idx = 0;
    for (auto &a : parameters) {
      inst->setParameter(idx, a);
      idx++;
    }
  }

  return inst;
}

 std::shared_ptr<CompositeInstruction>
 QuantumIRProvider::createComposite(const std::string name,
                  std::vector<std::string> variables) {
  // FIXME, update to handle D-Wave...
  auto f = std::make_shared<xacc::quantum::Circuit>(name,variables);
  return f;
}

std::shared_ptr<IR> QuantumIRProvider::createIR() {
  return std::make_shared<GateIR>();
}

std::vector<std::string> QuantumIRProvider::getInstructions() {
  std::vector<std::string> ret;
  for (auto i : xacc::getRegisteredIds<Instruction>()) {
    ret.push_back(i);
  }
//   ret.push_back("qmi");
//   ret.push_back("anneal");
  return ret;
}

} // namespace quantum
} // namespace xacc