Loading handlers/qcor_syntax_handler.cpp +25 −18 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ void QCORSyntaxHandler::GetReplacement( std::vector<std::string> program_arg_types, std::vector<std::string> program_parameters, std::vector<std::string> bufferNames, CachedTokens &Toks, llvm::raw_string_ostream &OS) { llvm::raw_string_ostream &OS, bool add_het_map_ctor) { // Get the Diagnostics engine and create a few custom // error messgaes auto &diagnostics = PP.getDiagnostics(); Loading Loading @@ -200,19 +200,24 @@ void QCORSyntaxHandler::GetReplacement( } OS << ") {}\n"; if (add_het_map_ctor) { // Third constructor, give us a way to provide a HeterogeneousMap of // arguments, this is used for Pythonic QJIT... // KERNEL_NAME(HeterogeneousMap args); OS << kernel_name << "(HeterogeneousMap& args): QuantumKernel<" << kernel_name << ", " << program_arg_types[0]; OS << kernel_name << "(HeterogeneousMap& args): QuantumKernel<" << kernel_name << ", " << program_arg_types[0]; for (int i = 1; i < program_arg_types.size(); i++) { OS << ", " << program_arg_types[i]; } OS << "> (args.get<" << program_arg_types[0] << ">(\"" << program_parameters[0] << "\")"; OS << "> (args.get<" << program_arg_types[0] << ">(\"" << program_parameters[0] << "\")"; for (int i = 1; i < program_parameters.size(); i++) { OS << ", " << "args.get<" << program_arg_types[0] << ">(\"" << program_parameters[i] << "\""; OS << ", " << "args.get<" << program_arg_types[i] << ">(\"" << program_parameters[i] << "\")"; } OS << ") {}\n"; } // Destructor definition OS << "virtual ~" << kernel_name << "() {\n"; Loading Loading @@ -305,11 +310,13 @@ void QCORSyntaxHandler::GetReplacement( OS << ");\n"; OS << "}\n"; if (add_het_map_ctor) { // Add the HeterogeneousMap args function overload OS << "void " << kernel_name << "__with_hetmap_args(HeterogeneousMap& args) {\n"; OS << "void " << kernel_name << "__with_hetmap_args(HeterogeneousMap& args) {\n"; OS << "class " << kernel_name << " __ker__temp__(args);\n"; OS << "}\n"; } auto s = OS.str(); qcor::info("[qcor syntax-handler] Rewriting " + kernel_name + " to\n\n" + s); } Loading handlers/qcor_syntax_handler.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ public: std::vector<std::string> program_arg_types, std::vector<std::string> program_parameters, std::vector<std::string> bufferNames, CachedTokens &Toks, llvm::raw_string_ostream &OS); llvm::raw_string_ostream &OS, bool add_het_map_ctor = false); void AddToPredefines(llvm::raw_string_ostream &OS) override; }; Loading python/py-qcor.cpp +14 −3 Original line number Diff line number Diff line Loading @@ -134,19 +134,30 @@ PYBIND11_MODULE(_pyqcor, m) { m.def( "set_qpu", [](const std::string &name) { xacc::internal_compiler::qpu = xacc::getAccelerator(name); [](const std::string &name, PyHeterogeneousMap p = {}) { xacc::internal_compiler::qpu = xacc::getAccelerator(name, heterogeneousMapConvert(p)); }, py::arg("name"), py::arg("p") = PyHeterogeneousMap(), "Set the QPU backend."); m.def("qalloc", &::qalloc, py::return_value_policy::reference, ""); py::class_<xacc::internal_compiler::qreg>(m, "qreg", "") .def("size", &xacc::internal_compiler::qreg::size, "") .def("print", &xacc::internal_compiler::qreg::print, ""); .def("print", &xacc::internal_compiler::qreg::print, "") .def("counts", &xacc::internal_compiler::qreg::counts, "") .def("exp_val_z", &xacc::internal_compiler::qreg::exp_val_z, ""); py::class_<qcor::QJIT, std::shared_ptr<qcor::QJIT>>(m, "QJIT", "") .def(py::init<>(), "") .def("jit_compile", &qcor::QJIT::jit_compile, "") .def( "internal_python_jit_compile", [](qcor::QJIT &qjit, const std::string src) { bool turn_on_hetmap_kernel_ctor = true; qjit.jit_compile(src, turn_on_hetmap_kernel_ctor); }, "") .def("run_syntax_handler", &qcor::QJIT::run_syntax_handler, "") .def( "invoke", Loading python/qcor.py +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ class qjit(object): # Run JIT, this will reused cached JIT LLVM Modules _qjit = QJIT() _qjit.jit_compile(fbody_src) _qjit.internal_python_jit_compile(fbody_src) # Create a dictionary for the function arguments args_dict = {} Loading python/tests/CMakeLists.txt +10 −1 Original line number Diff line number Diff line Loading @@ -2,3 +2,12 @@ add_test (NAME qcor_qsim_python_bindings COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_qsim.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(qcor_qsim_python_bindings PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}") add_test (NAME qcor_simple_kernel_jit_python COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_kernel_jit.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(qcor_simple_kernel_jit_python PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}") No newline at end of file Loading
handlers/qcor_syntax_handler.cpp +25 −18 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ void QCORSyntaxHandler::GetReplacement( std::vector<std::string> program_arg_types, std::vector<std::string> program_parameters, std::vector<std::string> bufferNames, CachedTokens &Toks, llvm::raw_string_ostream &OS) { llvm::raw_string_ostream &OS, bool add_het_map_ctor) { // Get the Diagnostics engine and create a few custom // error messgaes auto &diagnostics = PP.getDiagnostics(); Loading Loading @@ -200,19 +200,24 @@ void QCORSyntaxHandler::GetReplacement( } OS << ") {}\n"; if (add_het_map_ctor) { // Third constructor, give us a way to provide a HeterogeneousMap of // arguments, this is used for Pythonic QJIT... // KERNEL_NAME(HeterogeneousMap args); OS << kernel_name << "(HeterogeneousMap& args): QuantumKernel<" << kernel_name << ", " << program_arg_types[0]; OS << kernel_name << "(HeterogeneousMap& args): QuantumKernel<" << kernel_name << ", " << program_arg_types[0]; for (int i = 1; i < program_arg_types.size(); i++) { OS << ", " << program_arg_types[i]; } OS << "> (args.get<" << program_arg_types[0] << ">(\"" << program_parameters[0] << "\")"; OS << "> (args.get<" << program_arg_types[0] << ">(\"" << program_parameters[0] << "\")"; for (int i = 1; i < program_parameters.size(); i++) { OS << ", " << "args.get<" << program_arg_types[0] << ">(\"" << program_parameters[i] << "\""; OS << ", " << "args.get<" << program_arg_types[i] << ">(\"" << program_parameters[i] << "\")"; } OS << ") {}\n"; } // Destructor definition OS << "virtual ~" << kernel_name << "() {\n"; Loading Loading @@ -305,11 +310,13 @@ void QCORSyntaxHandler::GetReplacement( OS << ");\n"; OS << "}\n"; if (add_het_map_ctor) { // Add the HeterogeneousMap args function overload OS << "void " << kernel_name << "__with_hetmap_args(HeterogeneousMap& args) {\n"; OS << "void " << kernel_name << "__with_hetmap_args(HeterogeneousMap& args) {\n"; OS << "class " << kernel_name << " __ker__temp__(args);\n"; OS << "}\n"; } auto s = OS.str(); qcor::info("[qcor syntax-handler] Rewriting " + kernel_name + " to\n\n" + s); } Loading
handlers/qcor_syntax_handler.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ public: std::vector<std::string> program_arg_types, std::vector<std::string> program_parameters, std::vector<std::string> bufferNames, CachedTokens &Toks, llvm::raw_string_ostream &OS); llvm::raw_string_ostream &OS, bool add_het_map_ctor = false); void AddToPredefines(llvm::raw_string_ostream &OS) override; }; Loading
python/py-qcor.cpp +14 −3 Original line number Diff line number Diff line Loading @@ -134,19 +134,30 @@ PYBIND11_MODULE(_pyqcor, m) { m.def( "set_qpu", [](const std::string &name) { xacc::internal_compiler::qpu = xacc::getAccelerator(name); [](const std::string &name, PyHeterogeneousMap p = {}) { xacc::internal_compiler::qpu = xacc::getAccelerator(name, heterogeneousMapConvert(p)); }, py::arg("name"), py::arg("p") = PyHeterogeneousMap(), "Set the QPU backend."); m.def("qalloc", &::qalloc, py::return_value_policy::reference, ""); py::class_<xacc::internal_compiler::qreg>(m, "qreg", "") .def("size", &xacc::internal_compiler::qreg::size, "") .def("print", &xacc::internal_compiler::qreg::print, ""); .def("print", &xacc::internal_compiler::qreg::print, "") .def("counts", &xacc::internal_compiler::qreg::counts, "") .def("exp_val_z", &xacc::internal_compiler::qreg::exp_val_z, ""); py::class_<qcor::QJIT, std::shared_ptr<qcor::QJIT>>(m, "QJIT", "") .def(py::init<>(), "") .def("jit_compile", &qcor::QJIT::jit_compile, "") .def( "internal_python_jit_compile", [](qcor::QJIT &qjit, const std::string src) { bool turn_on_hetmap_kernel_ctor = true; qjit.jit_compile(src, turn_on_hetmap_kernel_ctor); }, "") .def("run_syntax_handler", &qcor::QJIT::run_syntax_handler, "") .def( "invoke", Loading
python/qcor.py +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ class qjit(object): # Run JIT, this will reused cached JIT LLVM Modules _qjit = QJIT() _qjit.jit_compile(fbody_src) _qjit.internal_python_jit_compile(fbody_src) # Create a dictionary for the function arguments args_dict = {} Loading
python/tests/CMakeLists.txt +10 −1 Original line number Diff line number Diff line Loading @@ -2,3 +2,12 @@ add_test (NAME qcor_qsim_python_bindings COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_qsim.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(qcor_qsim_python_bindings PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}") add_test (NAME qcor_simple_kernel_jit_python COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_kernel_jit.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(qcor_simple_kernel_jit_python PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}") No newline at end of file