13 #ifndef XACC_QALLOC_HPP_
14 #define XACC_QALLOC_HPP_
22 class AcceleratorBuffer;
24 namespace internal_compiler {
28 struct AllocEventListener {
29 virtual void onAllocate(qubit* qubit) = 0;
30 virtual void onDealloc(qubit* qubit) = 0;
33 extern AllocEventListener *getGlobalQubitManager();
34 extern void setGlobalQubitManager(AllocEventListener *);
45 listener->onAllocate(m_qubit);
53 virtual qubit allocate() = 0;
59 xacc::AcceleratorBuffer *buffer;
60 xacc::AcceleratorBuffer *results() {
return buffer; }
63 qubit(
const std::string ®_name,
size_t idx,
64 xacc::AcceleratorBuffer *in_buffer =
nullptr)
65 : first(reg_name), second(idx), buffer(in_buffer) {
66 tracker = std::make_shared<AllocTracker>(
this);
72 std::shared_ptr<AllocTracker> tracker;
82 cReg(std::shared_ptr<AcceleratorBuffer> in_buffer);
83 bool operator[](std::size_t i);
86 std::shared_ptr<AcceleratorBuffer> buffer;
92 std::vector<qubit> internal_qubits;
93 std::string random_string(std::size_t length);
96 std::shared_ptr<AcceleratorBuffer> buffer;
97 bool been_named_and_stored =
false;
103 std::size_t step = 1;
104 Range(std::vector<std::size_t> &s);
105 Range(std::initializer_list<std::size_t> &&s);
111 qreg(std::vector<qubit> &qubits);
112 qubit operator[](
const std::size_t i);
113 qreg extract_range(
const std::size_t& start,
const std::size_t& end);
115 qreg extract_qubits(
const std::initializer_list<std::size_t> &&qbits);
116 qreg head(
const std::size_t n_qubits);
119 qreg tail(
const std::size_t n_qubits);
120 AcceleratorBuffer *results();
121 std::shared_ptr<AcceleratorBuffer> results_shared();
122 std::map<std::string, int> counts();
126 void addChild(
qreg &q);
127 void setName(
const char *name);
128 void setNameAndStore(
const char *name);
132 double weighted_sum(Observable *obs);
133 void write_file(
const std::string &file_name);
155 #define __qpu__ [[clang::syntax(qcor)]] __attribute__((annotate("quantum")))