Commit 7b7222a2 authored by Nguyen, Thien's avatar Nguyen, Thien
Browse files

Work on Accelerator::getNativeCode


Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent f820332d
......@@ -1237,6 +1237,35 @@ void IBMAccelerator::put(const std::string &_url, const std::string &postStr,
return;
}
std::string
IBMAccelerator::getNativeCode(std::shared_ptr<CompositeInstruction> program,
const HeterogeneousMap &config) {
std::string format = "QObj"; // QObj/QASM
if (config.stringExists("format")) {
format = config.getString("format");
}
// Handle different ways to specify the format:
if (format == "QObj" || format == "QOBJ" || format == "JSON") {
chosenBackend = availableBackends[backend];
auto connectivity = getConnectivity();
// Get the correct QObject Generator
auto qobjGen = xacc::getService<QObjGenerator>(mode);
// Generate the QObject JSON
auto jsonStr = qobjGen->getQObjJsonStr(
{program}, shots, chosenBackend, getBackendPropsResponse, connectivity,
json::parse(defaults_response));
return jsonStr;
} else if (format == "qasm" || format == "Qasm" || format == "QASM" ||
format == "OpenQASM" || format == "OPENQASM") {
return "";
}
xacc::error("Unknown native code format '" + format + "'");
return "";
}
std::string
IBMAccelerator::get(const std::string &_url, const std::string &path,
std::map<std::string, std::string> headers,
......
......@@ -131,6 +131,8 @@ public:
std::vector<std::pair<int, int>> getConnectivity() override;
std::string getNativeCode(std::shared_ptr<CompositeInstruction> program,
const HeterogeneousMap &config) override;
// Return the name of an IRTransformation of type Placement that is
// preferred for this Accelerator
const std::string defaultPlacementTransformation() override {
......
......@@ -106,6 +106,14 @@ public:
return std::vector<std::pair<int, int>>{};
}
// Get circuit representation that the backend would be submitting to the
// physical QPU
virtual std::string
getNativeCode(std::shared_ptr<CompositeInstruction> program,
const HeterogeneousMap &config = {}) {
return program->toString();
}
virtual const std::vector<std::complex<double>>
getAcceleratorState(std::shared_ptr<CompositeInstruction> program) {
return std::vector<std::complex<double>>{};
......
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