Commit b10fb2ff authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added ability to set qrt from Python



add a quantum::set_qrt function rather than setting the static var directly.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent d110cb18
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -251,6 +251,13 @@ PYBIND11_MODULE(_pyqcor, m) {
      "Initialize",
      [](py::kwargs kwargs) {
        if (kwargs) {
          // QRT (if provided) must be set before quantum::initialize
          if (kwargs.contains("qrt")) {
            const auto value = std::string(py::str(kwargs["qrt"]));
            // QRT (if provided) should be set before quantum::initialize
            ::quantum::set_qrt(value);
          }
          
          for (auto arg : kwargs) {
            const auto key = std::string(py::str(arg.first));
            // Handle "qpu" key
+4 −0
Original line number Diff line number Diff line
@@ -343,6 +343,10 @@ init_kwargs = {'qpu': sys.argv[sys.argv.index(
if '-shots' in sys.argv:
    init_kwargs['shots'] = int(sys.argv[sys.argv.index('-shots')+1])

# get -qrt if provided
if '-qrt' in sys.argv:
    init_kwargs['qrt'] = sys.argv[sys.argv.index('-qrt')+1]

# Implements internal_startup initialization:
# i.e. set up qrt, backends, shots, etc.
Initialize(**init_kwargs)
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ public:
#endif
// IMPORTANT: This needs to be set before quantum::initialize
#ifdef __internal__qcor__compile__qrt__mode
    xacc::internal_compiler::__qrt_env = __internal__qcor__compile__qrt__mode;
    quantum::set_qrt(__internal__qcor__compile__qrt__mode);
#endif
#ifdef __internal__qcor__compile__backend
    quantum::initialize(__internal__qcor__compile__backend, "empty");
+4 −0
Original line number Diff line number Diff line
@@ -108,6 +108,10 @@ void set_shots(int shots) {

int get_shots() { return current_shots; }

void set_qrt(const std::string &qrt_name) {
  xacc::internal_compiler::__qrt_env = qrt_name;
}

void h(const qubit &qidx) { qrt_impl->h(qidx); }
void x(const qubit &qidx) { qrt_impl->x(qidx); }
void y(const qubit &qidx) { qrt_impl->y(qidx); }
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ void set_shots(int shots);
int get_shots();
void set_backend(std::string accelerator_name);
void set_backend(std::string accelerator_name, const int shots);
void set_qrt(const std::string &qrt_name);

// Common single-qubit gates.
void h(const qubit &qidx);