Commit 52c6d7db authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

add 2 qubit broadcast functions

parent 291b4e3c
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -303,4 +303,38 @@ void reset(qreg q) {
    reset(q[i]);
  }
}

void cnot(qreg src, qreg tgt) {
  assert(src.size() == tgt.size() &&
         "2-qubit broadcast must be across registers of same size.");

  for (int i = 0; i < src.size(); i++) {
    cnot(src[i], tgt[i]);
  }
}

void cy(qreg src, qreg tgt) {
  assert(src.size() == tgt.size() &&
         "2-qubit broadcast must be across registers of same size.");

  for (int i = 0; i < src.size(); i++) {
    cy(src[i], tgt[i]);
  }
}
void cz(qreg src, qreg tgt) {
  assert(src.size() == tgt.size() &&
         "2-qubit broadcast must be across registers of same size.");

  for (int i = 0; i < src.size(); i++) {
    cz(src[i], tgt[i]);
  }
}
void ch(qreg src, qreg tgt) {
  assert(src.size() == tgt.size() &&
         "2-qubit broadcast must be across registers of same size.");

  for (int i = 0; i < src.size(); i++) {
    ch(src[i], tgt[i]);
  }
}
}  // namespace quantum
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -168,6 +168,12 @@ void swap(const qubit &src_idx, const qubit &tgt_idx);
void cphase(const qubit &src_idx, const qubit &tgt_idx, const double theta);
void crz(const qubit &src_idx, const qubit &tgt_idx, const double theta);

// Broadcast two registers
void cnot(qreg src, qreg tgt);
void cy(qreg src, qreg tgt);
void cz(qreg src, qreg tgt);
void ch(qreg src, qreg tgt);

// exponential of i * theta * H, where H is an Observable pointer
void exp(qreg q, const double theta, xacc::Observable &H);
void exp(qreg q, const double theta, xacc::Observable *H);