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

Work on mirror circuit construction



- helper to compute the pseudo inverse and tracking the net-pauli as the pauli gate commuting through

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 77c50bc7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
add_subdirectory(quasimo)
add_subdirectory(mirror_rb)

# Install QCOR standard library header
file(GLOB LIB_HEADERS qcor_*)
+13 −0
Original line number Diff line number Diff line
set(LIBRARY_NAME qcor-mirror-rb)

file(GLOB SRC *.cpp)
file(GLOB HEADERS *.hpp)

add_library(${LIBRARY_NAME} SHARED ${SRC})

target_link_libraries(${LIBRARY_NAME} PUBLIC qcor)

xacc_configure_library_rpath(${LIBRARY_NAME})

install(FILES ${HEADERS} DESTINATION include/qcor)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
+50 −0
Original line number Diff line number Diff line
#include "clifford_gate_utils.hpp"
#include <cassert>
#include <cmath>
namespace {
double mod_2pi(double theta) {
  while (theta > M_PI or theta <= -M_PI) {
    if (theta > M_PI) {
      theta = theta - 2 * M_PI;
    } else if (theta <= -M_PI) {
      theta = theta + 2 * M_PI;
    }
  }
  assert(theta >= -M_PI && theta <= M_PI);
  return theta;
}
} // namespace
namespace qcor {
namespace utils {
GenRot_t computeRotationInPauliFrame(const GenRot_t &in_rot,
                                     PauliLabel in_newPauli,
                                     PauliLabel &io_netPauli) {
  auto [theta1, theta2, theta3] = in_rot;

  if (io_netPauli == PauliLabel::X || io_netPauli == PauliLabel::Z) {
    theta2 *= -1.0;
  }
  if (io_netPauli == PauliLabel::X || io_netPauli == PauliLabel::Y) {
    theta3 *= -1.0;
    theta1 *= -1.0;
  }

  // if x or y
  if (in_newPauli == PauliLabel::X || io_netPauli == PauliLabel::Y) {
    theta1 = -theta1 + M_PI;
    theta2 = theta2 + M_PI;
  }
  // if y or z
  if (in_newPauli == PauliLabel::Y || io_netPauli == PauliLabel::Z) {
    theta1 = theta1 + M_PI;
  }

  // make everything between - pi and pi
  theta1 = mod_2pi(theta1);
  theta2 = mod_2pi(theta2);
  theta3 = mod_2pi(theta3);

  return std::make_tuple(theta1, theta2, theta3);
}
} // namespace utils
} // namespace qcor
 No newline at end of file
+15 −0
Original line number Diff line number Diff line
#pragma once
#include <tuple>
namespace qcor {
namespace utils {
// Generalized rotation (3 angles)
// rz - sx - rz - sx - rz
using GenRot_t = std::tuple<double, double, double>;
enum class PauliLabel { I, X, Y, Z };
// Computes z rotation angles in a randomized Pauli frame.
// - in_pauli: the randomined Pauli op
GenRot_t computeRotationInPauliFrame(const GenRot_t &in_rot,
                                     PauliLabel in_newPauli,
                                     PauliLabel &io_netPauli);
} // namespace utils
} // namespace qcor
 No newline at end of file