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

Merge branch 'master' into tnguyen/qsim-qaoa-qite

parents e46f59e1 d623103a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -58,11 +58,11 @@ docker run_macosx_bottles:
  - docker start catalina-ci-container
  # give it time to boot up
  - sleep 120
  - ssh catalina-ci "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin bash homebrew-deploy/scripts/catalina/build.sh $AIDEQC_ACCESS_TOKEN $JFROG_API_KEY"
  - ssh catalina-ci "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin bash run_bottle_build.sh $AIDEQC_ACCESS_TOKEN $JFROG_API_KEY"
  - docker stop catalina-ci-container
  # now run mojave
  - docker start mojave-ci-container
  - sleep 120
  - ssh mojave-ci "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin bash homebrew-deploy/scripts/mojave/build.sh $AIDEQC_ACCESS_TOKEN $JFROG_API_KEY"
  - ssh mojave-ci "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin bash run_bottle_build.sh $AIDEQC_ACCESS_TOKEN $JFROG_API_KEY"
  - docker stop mojave-ci-container
  
+2 −2
Original line number Diff line number Diff line
@@ -475,10 +475,10 @@ PYBIND11_MODULE(_pyqcor, m) {
          "internal_python_jit_compile",
          [](qcor::QJIT &qjit, const std::string src,
             const std::vector<std::string> &dependency = {},
             const std::string &extra_cpp_code = "") {
             const std::string &extra_cpp_code = "", std::vector<std::string> extra_headers = {}) {
            bool turn_on_hetmap_kernel_ctor = true;
            qjit.jit_compile(src, turn_on_hetmap_kernel_ctor, dependency,
                             extra_cpp_code);
                             extra_cpp_code, extra_headers);
          },
          "")
      .def(
+10 −1
Original line number Diff line number Diff line
@@ -22,6 +22,15 @@ FermionOperator = xacc.quantum.FermionOperator
FLOAT_REF = typing.NewType('value', float)
INT_REF = typing.NewType('value', int)

# Need to add a few extra header paths 
# for the clang code-gen mechanism. Mac OS X will 
# need QCOR_EXTRA_HEADERS, all will need the 
# Python include path.
extra_headers = ['-I'+'@Python_INCLUDE_DIRS@']
tmp_extra_headers = '@QCOR_EXTRA_HEADERS@'.replace('"','')
for path in tmp_extra_headers.split(';'):
    if path:
        extra_headers.append('-I'+path)

def X(idx):
    return xacc.quantum.PauliOperator({idx: 'X'}, 1.0)
@@ -391,7 +400,7 @@ class qjit(object):

        # Run the QJIT compile step to store function pointers internally
        self._qjit.internal_python_jit_compile(
            self.src, self.sorted_kernel_dep, self.extra_cpp_code)
            self.src, self.sorted_kernel_dep, self.extra_cpp_code, extra_headers)
        self._qjit.write_cache()
        self.__compiled__kernels.append(self.function.__name__)
        return
+2 −1
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ class QJIT {
  void jit_compile(const std::string &quantum_kernel_src,
                   const bool add_het_map_kernel_ctor = false,
                   const std::vector<std::string> &kernel_dependency = {},
                   const std::string &extra_functions_src = "");
                   const std::string &extra_functions_src = "",
                   std::vector<std::string> extra_headers = {});

  void write_cache();

+16 −13
Original line number Diff line number Diff line
@@ -55,9 +55,10 @@
using namespace llvm;
using namespace llvm::orc;

#include <sys/stat.h>

#include <iostream>
#include <regex>
#include <sys/stat.h>

namespace qcor {

@@ -295,13 +296,13 @@ class LLVMJIT {
  Error addModule(std::unique_ptr<llvm::Module> M) {
    // FIXME hook up to cmake
    MainJD.addGenerator(cantFail(DynamicLibrarySearchGenerator::Load(
        "@XACC_ROOT@/lib/libxacc.so", DL.getGlobalPrefix())));
        "@XACC_ROOT@/lib/libxacc@CMAKE_SHARED_LIBRARY_SUFFIX@", DL.getGlobalPrefix())));
    MainJD.addGenerator(cantFail(DynamicLibrarySearchGenerator::Load(
        "@CMAKE_INSTALL_PREFIX@/lib/libqrt.so", DL.getGlobalPrefix())));
        "@CMAKE_INSTALL_PREFIX@/lib/libqrt@CMAKE_SHARED_LIBRARY_SUFFIX@", DL.getGlobalPrefix())));
    MainJD.addGenerator(cantFail(DynamicLibrarySearchGenerator::Load(
        "@CMAKE_INSTALL_PREFIX@/lib/libqcor.so", DL.getGlobalPrefix())));
        "@CMAKE_INSTALL_PREFIX@/lib/libqcor@CMAKE_SHARED_LIBRARY_SUFFIX@", DL.getGlobalPrefix())));
    MainJD.addGenerator(cantFail(DynamicLibrarySearchGenerator::Load(
        "@XACC_ROOT@/lib/libCppMicroServices.so", DL.getGlobalPrefix())));
        "@XACC_ROOT@/lib/libCppMicroServices@CMAKE_SHARED_LIBRARY_SUFFIX@", DL.getGlobalPrefix())));

    return CompileLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx));
  }
@@ -315,7 +316,8 @@ QJIT::QJIT() {
  // if tmp directory doesnt exist create it
  qjit_cache_path = std::string(std::getenv("HOME")) + "/.qjit";
  if (!xacc::directoryExists(qjit_cache_path)) {
    auto status = mkdir(qjit_cache_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    auto status =
        mkdir(qjit_cache_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  }

  std::string cache_file_loc = qjit_cache_path + "/qjit_cache.json";
@@ -351,7 +353,9 @@ QJIT::~QJIT() { write_cache(); }

void QJIT::jit_compile(const std::string &code,
                       const bool add_het_map_kernel_ctor,
                       const std::vector<std::string> &kernel_dependency, const std::string& extra_functions_src) {
                       const std::vector<std::string> &kernel_dependency,
                       const std::string &extra_functions_src,
                       std::vector<std::string> extra_headers) {
  // Run the Syntax Handler to get the kernel name and
  // the kernel code (the QuantumKernel subtype def + utility functions)
  auto [kernel_name, new_code] =
@@ -388,8 +392,7 @@ void QJIT::jit_compile(const std::string &code,
    // If we have this hash in the cache, we will grab its
    // correspoding Module bc file name and load it
    auto module_bitcode_file_name = cached_kernel_codes[hash];
    std::string full_path =
        qjit_cache_path+"/" + module_bitcode_file_name;
    std::string full_path = qjit_cache_path + "/" + module_bitcode_file_name;

    // Load the bitcode file as Module
    SMDiagnostic error;
@@ -405,15 +408,15 @@ void QJIT::jit_compile(const std::string &code,
  } else {
    // We have not seen this code before, so we
    // need to map it to an LLVM Module
    act = qcor::emit_llvm_ir(new_code);
    act = qcor::emit_llvm_ir(new_code, extra_headers);
    module = act->takeModule();

    // Persist the Module to a bitcode file
    std::stringstream file_name_ss;
    file_name_ss << "__qjit_m_" << module.get() << ".bc";
    std::error_code ec;
    ToolOutputFile result(qjit_cache_path+"/" + file_name_ss.str(),
                          ec, sys::fs::F_None);
    ToolOutputFile result(qjit_cache_path + "/" + file_name_ss.str(), ec,
                          sys::fs::F_None);
    WriteBitcodeToFile(*module, result.os());
    result.keep();

Loading