Loading examples/unitary/ccnot.cpp 0 → 100644 +43 −0 Original line number Diff line number Diff line // Define a quantum kernel that uses // unitary matrix definition for jit-compile // time decomposition. __qpu__ void ccnot(qreg q) { // set initial state to 111 for (int i = 0; i < q.size(); i++) { X(q[i]); } // To program at the unitary matrix level, // simply indicate you are using qcor::unitary namespace using qcor::unitary; // Create the unitary matrix qcor::UnitaryMatrix ccnot = qcor::UnitaryMatrix::Identity(8, 8); ccnot(6, 6) = 0.0; ccnot(7, 7) = 0.0; ccnot(6, 7) = 1.0; ccnot(7, 6) = 1.0; // Switch back to xasm to add some measures using qcor::xasm; for (int i = 0; i < q.size(); i++) { Measure(q[i]); } } int main() { // allocate 3 qubits auto q = qalloc(3); // By default this uses qfast with adam optimizer // print what the unitary decomp was ccnot::print_kernel(std::cout, q); // Run the unitary evolution. ccnot(q); // should see 011 (msb) for toffoli input 111 q.print(); } No newline at end of file handlers/qcor_syntax_handler.cpp +6 −5 Original line number Diff line number Diff line Loading @@ -132,6 +132,11 @@ public: OS << ", " << program_arg_types[i] << " " << program_parameters[i]; } OS << ") {\n"; if (shots > 0) { OS << "quantum::set_backend(\"" << qpu_name << "\", " << shots << ");\n"; } else { OS << "quantum::set_backend(\"" << qpu_name << "\");\n"; } OS << "if (!parent_kernel) {\n"; OS << "parent_kernel = " "qcor::__internal__::create_composite(kernel_name);\n"; Loading Loading @@ -186,11 +191,7 @@ public: // Destructor definition OS << "virtual ~" << kernel_name << "() {\n"; OS << "if (disable_destructor) {return;}\n"; if (shots > 0) { OS << "quantum::set_backend(\"" << qpu_name << "\", " << shots << ");\n"; } else { OS << "quantum::set_backend(\"" << qpu_name << "\");\n"; } OS << "auto [" << program_parameters[0]; for (int i = 1; i < program_parameters.size(); i++) { OS << ", " << program_parameters[i]; Loading handlers/token_collector/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ install(TARGETS ${LIBRARY_NAME} DESTINATION lib) add_subdirectory(xasm) add_subdirectory(staq) #add_subdirectory(quil) add_subdirectory(unitary) if (QCOR_BUILD_TESTS) add_subdirectory(tests) Loading handlers/token_collector/unitary/CMakeLists.txt 0 → 100644 +57 −0 Original line number Diff line number Diff line # ******************************************************************************* # Copyright (c) 2019 UT-Battelle, LLC. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # and Eclipse Distribution License v.10 which accompany this distribution. # The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License is available at # https://eclipse.org/org/documents/edl-v10.php # # Contributors: # Alexander J. McCaskey - initial API and implementation # *******************************************************************************/ set(LIBRARY_NAME qcor-unitary-token) file(GLOB SRC *.cpp) usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC) usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC) add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories( ${LIBRARY_NAME} PUBLIC . .. ${CMAKE_SOURCE_DIR}/runtime/qrt ${CLANG_INCLUDE_DIRS}) target_link_libraries(${LIBRARY_NAME} PUBLIC ${CLANG_LIBS} ${LLVM_LIBS} xacc::xacc qrt) set(_bundle_name qcor_unitary_token) set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name} US_BUNDLE_NAME ${_bundle_name}) usfunctionembedresources(TARGET ${LIBRARY_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} FILES manifest.json) if(APPLE) set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib;${LLVM_INSTALL_PREFIX}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:${LLVM_INSTALL_PREFIX}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared") endif() install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins) if (QCOR_BUILD_TESTS) add_subdirectory(tests) endif() No newline at end of file handlers/token_collector/unitary/manifest.json 0 → 100644 +6 −0 Original line number Diff line number Diff line { "bundle.symbolic_name" : "qcor_unitary_token", "bundle.activator" : true, "bundle.name" : "Unitary Matrix to Qasm Token Collector", "bundle.description" : "" } Loading
examples/unitary/ccnot.cpp 0 → 100644 +43 −0 Original line number Diff line number Diff line // Define a quantum kernel that uses // unitary matrix definition for jit-compile // time decomposition. __qpu__ void ccnot(qreg q) { // set initial state to 111 for (int i = 0; i < q.size(); i++) { X(q[i]); } // To program at the unitary matrix level, // simply indicate you are using qcor::unitary namespace using qcor::unitary; // Create the unitary matrix qcor::UnitaryMatrix ccnot = qcor::UnitaryMatrix::Identity(8, 8); ccnot(6, 6) = 0.0; ccnot(7, 7) = 0.0; ccnot(6, 7) = 1.0; ccnot(7, 6) = 1.0; // Switch back to xasm to add some measures using qcor::xasm; for (int i = 0; i < q.size(); i++) { Measure(q[i]); } } int main() { // allocate 3 qubits auto q = qalloc(3); // By default this uses qfast with adam optimizer // print what the unitary decomp was ccnot::print_kernel(std::cout, q); // Run the unitary evolution. ccnot(q); // should see 011 (msb) for toffoli input 111 q.print(); } No newline at end of file
handlers/qcor_syntax_handler.cpp +6 −5 Original line number Diff line number Diff line Loading @@ -132,6 +132,11 @@ public: OS << ", " << program_arg_types[i] << " " << program_parameters[i]; } OS << ") {\n"; if (shots > 0) { OS << "quantum::set_backend(\"" << qpu_name << "\", " << shots << ");\n"; } else { OS << "quantum::set_backend(\"" << qpu_name << "\");\n"; } OS << "if (!parent_kernel) {\n"; OS << "parent_kernel = " "qcor::__internal__::create_composite(kernel_name);\n"; Loading Loading @@ -186,11 +191,7 @@ public: // Destructor definition OS << "virtual ~" << kernel_name << "() {\n"; OS << "if (disable_destructor) {return;}\n"; if (shots > 0) { OS << "quantum::set_backend(\"" << qpu_name << "\", " << shots << ");\n"; } else { OS << "quantum::set_backend(\"" << qpu_name << "\");\n"; } OS << "auto [" << program_parameters[0]; for (int i = 1; i < program_parameters.size(); i++) { OS << ", " << program_parameters[i]; Loading
handlers/token_collector/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ install(TARGETS ${LIBRARY_NAME} DESTINATION lib) add_subdirectory(xasm) add_subdirectory(staq) #add_subdirectory(quil) add_subdirectory(unitary) if (QCOR_BUILD_TESTS) add_subdirectory(tests) Loading
handlers/token_collector/unitary/CMakeLists.txt 0 → 100644 +57 −0 Original line number Diff line number Diff line # ******************************************************************************* # Copyright (c) 2019 UT-Battelle, LLC. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # and Eclipse Distribution License v.10 which accompany this distribution. # The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License is available at # https://eclipse.org/org/documents/edl-v10.php # # Contributors: # Alexander J. McCaskey - initial API and implementation # *******************************************************************************/ set(LIBRARY_NAME qcor-unitary-token) file(GLOB SRC *.cpp) usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC) usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC) add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories( ${LIBRARY_NAME} PUBLIC . .. ${CMAKE_SOURCE_DIR}/runtime/qrt ${CLANG_INCLUDE_DIRS}) target_link_libraries(${LIBRARY_NAME} PUBLIC ${CLANG_LIBS} ${LLVM_LIBS} xacc::xacc qrt) set(_bundle_name qcor_unitary_token) set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name} US_BUNDLE_NAME ${_bundle_name}) usfunctionembedresources(TARGET ${LIBRARY_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} FILES manifest.json) if(APPLE) set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib;${LLVM_INSTALL_PREFIX}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:${LLVM_INSTALL_PREFIX}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared") endif() install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins) if (QCOR_BUILD_TESTS) add_subdirectory(tests) endif() No newline at end of file
handlers/token_collector/unitary/manifest.json 0 → 100644 +6 −0 Original line number Diff line number Diff line { "bundle.symbolic_name" : "qcor_unitary_token", "bundle.activator" : true, "bundle.name" : "Unitary Matrix to Qasm Token Collector", "bundle.description" : "" }