Commit 5c0dd934 authored by Nguyen, Thien's avatar Nguyen, Thien
Browse files

Fixed IonQ backend implementation:



- Batch mode: override base RemoteAccelerator to run one-by-one.

- Fixed U3 decompose for IonQProgramVisitor: looks like the decomposition is not correct (incorrect results). Also, IonQ supports native sqrt-X gate, hence just use the same U3 -> (sx-rz) as that of IBM.

Tested by: running on IonQ remote simulator.
Signed-off-by: Nguyen, Thien's avatarThien Nguyen <nguyentm@ornl.gov>
parent 3679fe75
......@@ -50,6 +50,20 @@ void IonQAccelerator::initialize(const HeterogeneousMap &params) {
}
}
// Note: IonQ don't support batching.
void IonQAccelerator::execute(
std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<std::shared_ptr<CompositeInstruction>> circuits) {
for (const auto &f : circuits) {
auto tmpBuffer =
std::make_shared<xacc::AcceleratorBuffer>(f->name(), buffer->size());
// Run each circuit
RemoteAccelerator::execute(tmpBuffer, f);
// tmpBuffer->print();
buffer->appendChild(f->name(), tmpBuffer);
}
}
const std::string IonQAccelerator::processInput(
std::shared_ptr<AcceleratorBuffer> buffer,
std::vector<std::shared_ptr<CompositeInstruction>> functions) {
......@@ -80,7 +94,7 @@ const std::string IonQAccelerator::processInput(
using json = nlohmann::json;
json jj;
to_json(jj, prog);
xacc::info("IonQ Job JSON:\n" + jj.dump(4) + "\n");
return jj.dump();
}
......@@ -145,6 +159,8 @@ void IonQAccelerator::processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
buffer->appendMeasurement(getBitStrForInt(std::stoi(kv.first)),
std::ceil(kv.second * shots));
}
xacc::info("IonQ Result JSON:\n" + j.dump(4) + "\n");
return;
}
......
......@@ -24,7 +24,9 @@ namespace quantum {
class IonQAccelerator : public RemoteAccelerator {
public:
void cancel() override;
void execute(std::shared_ptr<AcceleratorBuffer> buffer,
const std::vector<std::shared_ptr<CompositeInstruction>>
circuits) override;
void initialize(const HeterogeneousMap &params = {}) override;
void updateConfiguration(const HeterogeneousMap &config) override {
if (config.keyExists<int>("shots")) {
......
......@@ -151,16 +151,49 @@ public:
}
void visit(U &u) override {
auto t = u.getParameter(0).toString();
auto p = u.getParameter(1).toString();
auto l = u.getParameter(2).toString();
Rz rz(u.bits()[0], t);
Ry ry(u.bits()[0], p);
Rz rz2(u.bits()[0], l);
visit(rz);
visit(ry);
visit(rz2);
auto t = u.getParameter(0).as<double>();
auto p = u.getParameter(1).as<double>();
auto l = u.getParameter(2).as<double>();
auto qubit = u.bits()[0];
{
// u3_qasm_def.rz(lam, 0)
xacc::ionq::CircuitInstruction inst;
inst.set_gate("rz");
inst.set_target(qubit);
inst.set_rotation(l);
instructions.push_back(inst);
}
{
// u3_qasm_def.sx(0)
// v = Square root of not gate
xacc::ionq::CircuitInstruction inst;
inst.set_gate("v");
inst.set_target(qubit);
instructions.push_back(inst);
}
{
// u3_qasm_def.rz(theta+pi, 0)
xacc::ionq::CircuitInstruction inst;
inst.set_gate("rz");
inst.set_target(qubit);
inst.set_rotation(t + M_PI);
instructions.push_back(inst);
}
{
// u3_qasm_def.sx(0)
xacc::ionq::CircuitInstruction inst;
inst.set_gate("v");
inst.set_target(qubit);
instructions.push_back(inst);
}
{
// u3_qasm_def.rz(phi+3*pi, 0)
xacc::ionq::CircuitInstruction inst;
inst.set_gate("rz");
inst.set_target(qubit);
inst.set_rotation(p + 3.0 * M_PI);
instructions.push_back(inst);
}
}
void visit(Rx &rx) override {
......
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