Commit c2f8e73c authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Updating the README



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 9f85a8a7
......@@ -28,17 +28,22 @@ import xacc
# Initialize the framework
xacc.Initialize()
# Select the QPU you want to use and
# allocate some qubits
qpu = xacc.getAccelerator('rigetti') # or ibm, tnqvm, etc..
qubits = qpu.createBuffer('q',2)
# Annotate functions that are to be
# run on the QPU
@xacc.qpu(accelerator='rigetti') # or ibm, tnqvm, etc..
def entangle():
@xacc.qpu(accelerator=qpu)
def entangle(buffer):
H(0)
CNOT(0, 1)
Measure(0, 0)
Measure(1, 1)
# Execute, gather results
results = entangle()
entangle(qubits)
print(result.getMeasurementCounts())
# Cleanup
......
......@@ -131,7 +131,7 @@ void PyXACCListener::enterUop(PyXACCIRParser::UopContext *ctx) {
auto acc = xacc::getAccelerator("dwave");
auto buff = acc->getBuffer(bufferName);
buff->addExtraInfo("ir-generator", ExtraInfo(generator->name()));
auto xaccKernelSrcStr = dwcompiler->translate("", genF);
auto embeddedCode = dwcompiler->compile(xaccKernelSrcStr, acc);
genF = embeddedCode->getKernels()[0];
......
......@@ -451,7 +451,9 @@ PYBIND11_MODULE(_pyxacc, m) {
"Indicate that this is using XACC via the Python API.");
m.def("optimizeFunction", &xacc::optimizeFunction,
"Run an optimizer on the given function.");
m.def("analyzeBuffer", (void(*)(std::shared_ptr<AcceleratorBuffer>)) &xacc::analyzeBuffer, "Analyze the AcceleratorBuffer to produce problem-specific results.");
m.def("analyzeBuffer",
(void (*)(std::shared_ptr<AcceleratorBuffer>)) & xacc::analyzeBuffer,
"Analyze the AcceleratorBuffer to produce problem-specific results.");
m.def("Finalize", &xacc::Finalize, "Finalize the framework");
m.def("compileKernel",
......
......@@ -324,12 +324,14 @@ const std::string translateWithVisitor(const std::string &originalSource,
}
void analyzeBuffer(std::shared_ptr<AcceleratorBuffer> buffer) {
if (!buffer->hasExtraInfoKey("ir-generator")) {
error("xacc::analyzeBuffer is for use with codes generated with an IRGenerator.");
}
auto gen = getService<IRGenerator>(boost::get<std::string>(buffer->getInformation("ir-generator")));
gen->analyzeResults(buffer);
if (!buffer->hasExtraInfoKey("ir-generator")) {
error("xacc::analyzeBuffer is for use with codes generated with an "
"IRGenerator.");
}
auto gen = getService<IRGenerator>(
boost::get<std::string>(buffer->getInformation("ir-generator")));
gen->analyzeResults(buffer);
}
void clearOptions() { RuntimeOptions::instance()->clear(); }
......
......@@ -41,9 +41,11 @@ bool CheckEqualVisitor::operator()(const std::vector<std::string> &i) const {
boost::get<std::vector<std::string>>(extraInfo).begin());
}
bool CheckEqualVisitor::operator()(const std::map<int, std::vector<int>> &i) const {
return std::equal(i.begin(), i.end(),
boost::get<std::map<int, std::vector<int>>>(extraInfo).begin());
bool CheckEqualVisitor::
operator()(const std::map<int, std::vector<int>> &i) const {
return std::equal(
i.begin(), i.end(),
boost::get<std::map<int, std::vector<int>>>(extraInfo).begin());
}
void ToJsonVisitor::operator()(const int &i) { writer.Int(i); }
void ToJsonVisitor::operator()(const double &i) { writer.Double(i); }
......@@ -68,16 +70,16 @@ void ToJsonVisitor::operator()(const std::vector<std::string> &i) {
}
void ToJsonVisitor::operator()(const std::map<int, std::vector<int>> &i) {
writer.StartArray();
for (auto &kv : i) {
writer.Key(std::to_string(kv.first));
writer.StartArray();
for (auto& kv : i) {
writer.Key(std::to_string(kv.first));
writer.StartArray();
for (auto& v : kv.second) {
writer.Int(v);
}
writer.EndArray();
for (auto &v : kv.second) {
writer.Int(v);
}
writer.EndArray();
}
writer.EndArray();
}
AcceleratorBuffer::AcceleratorBuffer(const std::string &str, const int N)
......@@ -380,8 +382,8 @@ void AcceleratorBuffer::print(std::ostream &stream) {
writer.Key("Children");
writer.StartObject();
for (auto &pair : children) {
writer.Key("child");
writer.StartObject();
writer.Key("child");
writer.StartObject();
writer.Key("name");
writer.String(pair.first);
writer.Key("Information");
......
......@@ -33,7 +33,8 @@ class AcceleratorBuffer;
using AcceleratorBufferChildPair =
std::pair<std::string, std::shared_ptr<AcceleratorBuffer>>;
using ExtraInfo = boost::variant<int, double, std::string, std::vector<int>,
std::vector<double>, std::vector<std::string>, std::map<int, std::vector<int>>>;
std::vector<double>, std::vector<std::string>,
std::map<int, std::vector<int>>>;
using AddPredicate = std::function<bool(ExtraInfo &)>;
class CheckEqualVisitor : public boost::static_visitor<bool> {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment