Commit 2f9128d2 authored by Mccaskey, Alex's avatar Mccaskey, Alex

adding embed() to python api

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 52ae384d
Pipeline #32963 passed with stages
in 9 minutes and 19 seconds
......@@ -13,6 +13,9 @@ include_directories(${CMAKE_SOURCE_DIR}/tpls/exprtk)
include_directories(${CMAKE_SOURCE_DIR}/tpls/spdlog)
include_directories(${CMAKE_SOURCE_DIR}/tpls/eigen)
include_directories(${CMAKE_SOURCE_DIR}/quantum/aqc/ir)
include_directories(${CMAKE_SOURCE_DIR}/quantum/aqc/compiler)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/ir)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/ir/instructions)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/utils)
......
......@@ -17,6 +17,8 @@
#include "AcceleratorBuffer.hpp"
#include "AcceleratorDecorator.hpp"
#include "InstructionParameter.hpp"
#include "DWGraph.hpp"
#include "EmbeddingAlgorithm.hpp"
#include <pybind11/complex.h>
#include <pybind11/numpy.h>
......@@ -372,7 +374,7 @@ PYBIND11_MODULE(_pyxacc, m) {
(ExtraInfo(xacc::AcceleratorBuffer::*)(const std::string)) &
xacc::AcceleratorBuffer::getInformation,
"")
.def("appendChild", &xacc::AcceleratorBuffer::appendChild,"")
.def("appendChild", &xacc::AcceleratorBuffer::appendChild, "")
.def("hasExtraInfoKey", &xacc::AcceleratorBuffer::hasExtraInfoKey, "")
.def("name", &xacc::AcceleratorBuffer::name, "")
.def("getAllUnique", &xacc::AcceleratorBuffer::getAllUnique,
......@@ -530,7 +532,11 @@ PYBIND11_MODULE(_pyxacc, m) {
(void (*)(std::shared_ptr<AcceleratorBuffer>)) & xacc::analyzeBuffer,
"Analyze the AcceleratorBuffer to produce problem-specific results.");
m.def("getCache", &xacc::getCache, "");
m.def("appendCache", (void (*)(const std::string, const std::string, InstructionParameter&)) &xacc::appendCache, "");
m.def(
"appendCache",
(void (*)(const std::string, const std::string, InstructionParameter &)) &
xacc::appendCache,
"");
m.def("Finalize", &xacc::Finalize, "Finalize the framework");
m.def(
"loadBuffer",
......@@ -615,16 +621,16 @@ PYBIND11_MODULE(_pyxacc, m) {
return xacc::getService<IRProvider>("dwave")->createInstruction(
name, qbits, params);
},
"Convenience function for creating a new DWInstruction.",
py::arg("name"), py::arg("qbits"),
"Convenience function for creating a new DWInstruction.", py::arg("name"),
py::arg("qbits"),
py::arg("params") = std::vector<InstructionParameter>{});
aqcsub.def(
"createFunction",
[](const std::string &name, std::vector<int> qbits,
std::vector<InstructionParameter> params =
std::vector<InstructionParameter>{}) -> std::shared_ptr<Function> {
return xacc::getService<IRProvider>("dwave")->createFunction(name, qbits,
params);
return xacc::getService<IRProvider>("dwave")->createFunction(
name, qbits, params);
},
"Convenience function for creating a new DWFunction.", py::arg("name"),
py::arg("qbits"),
......@@ -635,4 +641,43 @@ PYBIND11_MODULE(_pyxacc, m) {
return xacc::getService<IRProvider>("dwave")->createIR();
},
"Convenience function for creating a new DWIR.");
aqcsub.def(
"embed",
[](std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc,
const std::string algo) -> std::map<int, std::vector<int>> {
auto a = xacc::getService<xacc::quantum::EmbeddingAlgorithm>(algo);
auto hardware = acc->getAcceleratorConnectivity();
int maxBitIdx = 0;
for (auto inst : f->getInstructions()) {
if (inst->name() == "dw-qmi") {
auto qbit1 = inst->bits()[0];
auto qbit2 = inst->bits()[1];
if (qbit1 > maxBitIdx) {
maxBitIdx = qbit1;
}
if (qbit2 > maxBitIdx) {
maxBitIdx = qbit2;
}
}
}
auto problemGraph = std::make_shared<xacc::quantum::DWGraph>(maxBitIdx+1);
for (auto inst : f->getInstructions()) {
if (inst->name() == "dw-qmi") {
auto qbit1 = inst->bits()[0];
auto qbit2 = inst->bits()[1];
if (qbit1 == qbit2) {
problemGraph->setVertexProperties(qbit1, 1.0);
} else {
problemGraph->addEdge(qbit1, qbit2, 1.0);
}
}
}
return a->embed(problemGraph, hardware);
},
"");
}
......@@ -32,8 +32,7 @@ namespace quantum {
* for minor graph embedding algorithms.
*
*/
class __attribute__((visibility("default"))) EmbeddingAlgorithm
: public Identifiable {
class EmbeddingAlgorithm : public Identifiable {
public:
/**
......
......@@ -2,13 +2,13 @@
# Copyright (c) 2018 UT-Battelle, LLC.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v.10 which accompany this distribution.
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# and Eclipse Distribution License v.10 which accompany this distribution.
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# https://eclipse.org/org/documents/edl-v10.php
#
# Contributors:
# Alexander J. McCaskey - initial API and implementation
# Alexander J. McCaskey - initial API and implementation
# *******************************************************************************/
set(BUILD_SHARED_LIBS TRUE)
add_subdirectory(cppmicroservices)
......
Markdown is supported
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