Commit 27a79414 authored by Nguyen, Thien's avatar Nguyen, Thien
Browse files

Support qasm construction from QObj


Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent c6d64045
......@@ -1260,7 +1260,30 @@ IBMAccelerator::getNativeCode(std::shared_ptr<CompositeInstruction> program,
return jsonStr;
} else if (format == "qasm" || format == "Qasm" || format == "QASM" ||
format == "OpenQASM" || format == "OPENQASM") {
return "";
chosenBackend = availableBackends[backend];
const auto basis_gates =
chosenBackend["basis_gates"].get<std::vector<std::string>>();
// If the gate set has "u3" -> old gateset.
const auto gateSet = (xacc::container::contains(basis_gates, "u3"))
? QObjectExperimentVisitor::GateSet::U_CX
: QObjectExperimentVisitor::GateSet::RZ_SX_CX;
auto visitor = std::make_shared<QObjectExperimentVisitor>(
program->name(), program->nLogicalBits(), gateSet);
InstructionIterator it(program);
int memSlots = 0;
while (it.hasNext()) {
auto nextInst = it.next();
if (nextInst->isEnabled()) {
nextInst->accept(visitor);
}
}
auto experiment = visitor->getExperiment();
std::stringstream ss;
for (auto &inst : experiment.get_instructions()) {
// std::cout << "HOWDY: " << inst.toString() << "\n";
ss << inst.toString() << "\n";
}
return ss.str();
}
xacc::error("Unknown native code format '" + format + "'");
return "";
......
......@@ -399,6 +399,26 @@ public:
std::optional<int64_t> get_condition_reg_id() const { return conditional; }
void set_condition_reg_id(int64_t value) { this->conditional = value; }
std::string toString() const {
std::stringstream ss;
ss << name;
if (!params.empty()) {
ss << "(";
for (int i = 0; i < params.size(); ++i) {
ss << params[i];
if (i != params.size() - 1) {
ss << ", ";
}
}
ss << ")";
}
for (const auto &qb : qubits) {
ss << " q[" << qb << "]";
}
ss << ";";
return ss.str();
}
};
class Experiment {
......
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