QVMAccelerator.hpp 3.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*******************************************************************************
 * Copyright (c) 2019 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 v1.0 which accompanies 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
 *******************************************************************************/
Mccaskey, Alex's avatar
Mccaskey, Alex committed
13
14
15
16
17
18
#ifndef QUANTUM_GATE_ACCELERATORS_QVMACCELERATOR_HPP_
#define QUANTUM_GATE_ACCELERATORS_QVMACCELERATOR_HPP_

#include "RemoteAccelerator.hpp"
#include "InstructionIterator.hpp"
#include "QuilVisitor.hpp"
19
#include "xacc.hpp"
Mccaskey, Alex's avatar
Mccaskey, Alex committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

using namespace xacc;

namespace xacc {
namespace quantum {

/**
 * The QVMAccelerator is a QPUGate Accelerator that
 * provides an execute implementation that maps XACC IR
 * to an equivalent Quil string, and executes it on the
 * Rigetti QVM at 127.0.0.1:5000/qvm
 *
 *
 */
class QVMAccelerator : virtual public RemoteAccelerator {
public:
  QVMAccelerator() : RemoteAccelerator() {}

  QVMAccelerator(std::shared_ptr<Client> client)
      : RemoteAccelerator(client) {}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
40
  const std::string getSignature() override {return name()+":";}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

  void
  execute(std::shared_ptr<AcceleratorBuffer> buffer,
          const std::vector<std::shared_ptr<CompositeInstruction>> functions) override {
    int counter = 0;
    std::vector<std::shared_ptr<AcceleratorBuffer>> tmpBuffers;
    for (auto f : functions) {
      xacc::info("QVM Executing kernel = " + f->name());
      auto tmpBuffer = std::make_shared<AcceleratorBuffer>(buffer->name() + std::to_string(counter),
                                    buffer->size());
      RemoteAccelerator::execute(tmpBuffer, f);
      tmpBuffers.push_back(tmpBuffer);
      buffer->appendChild(tmpBuffer->name(), tmpBuffer);
      counter++;
    }

    return;
  }

  void initialize(const HeterogeneousMap& params = {}) override {}
  const std::vector<std::string> configurationKeys() override {
      return {};
  }
  void updateConfiguration(const HeterogeneousMap &config) override {
  }


  const std::string
  processInput(std::shared_ptr<AcceleratorBuffer> buffer,
               std::vector<std::shared_ptr<CompositeInstruction>> functions) override;

  void
  processResponse(std::shared_ptr<AcceleratorBuffer> buffer,
                  const std::string &response) override;

  std::vector<std::shared_ptr<IRTransformation>>
  getIRTransformations() override {
    std::vector<std::shared_ptr<IRTransformation>> v;
    return v;
  }

  /**
   * Return all relevant QVMAccelerator runtime options.
   * Users can set the api-key, execution type, and number of triels
   * from the command line with these options.
   */
  OptionPairs getOptions() override {
    OptionPairs desc {{"rigetti-shots",
        "Provide the number of shots to execute on the QVM."}};
    return desc;
  }

  const std::string name() const override { return "rigetti-qvm"; }

  const std::string description() const override {
    return "The Rigetti QVM Accelerator interacts with "
           "the Forest QVM to execute XACC quantum IR.";
  }

  virtual ~QVMAccelerator() {}

private:
  std::vector<int> currentMeasurementSupports;

};

} // namespace quantum
} // namespace xacc

#endif