Loading docker/deploy/code-server/base/Dockerfiledeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line FROM codercom/code-server:latest ENV DEBIAN_FRONTEND noninteractive RUN echo 'deb http://deb.debian.org/debian testing main' | sudo tee /etc/apt/sources.list.d/testing.list RUN sudo apt-get update \ && sudo apt-get install -y \ curl build-essential wget gdb \ dumb-init \ zsh \ htop \ locales \ man \ nano \ git \ procps \ openssh-client \ sudo \ vim.tiny libssl-dev liblapack-dev libblas-dev ninja-build zlib1g-dev \ libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev \ lsb-release libcurl4-openssl-dev \ && sudo rm -rf /var/lib/apt/lists/* \ && sudo wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz \ && sudo tar xzf Python-3.8.2.tgz && cd Python-3.8.2 \ && sudo CCSHARED='-fPIC' ./configure --prefix=/usr --exec-prefix=/usr --enable-shared --enable-optimizations \ && sudo make altinstall && cd ../ && sudo rm -rf Python-3.8.2* \ && wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/PUBLIC-KEY.gpg | sudo apt-key add - \ && wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/focal/aide-qc.list" | sudo tee -a /etc/apt/sources.list.d/aide-qc.list \ && /usr/bin/pip3.8 install ipopo cmake --user \ && sudo unlink /usr/bin/python3 && sudo ln -s /usr/bin/python3.8 /usr/bin/python3 \ && sudo sed -i 's/#!\/usr\/bin\/python3/#!\/usr\/bin\/python3.9/' /usr/bin/lsb_release examples/CMakeLists.txt +3 −2 Original line number Diff line number Diff line Loading @@ -53,10 +53,10 @@ add_qcor_compile_and_exe_test(quasimo_vqe quasimo/VqeWithAnsatzCircuit.cpp) add_qcor_compile_and_exe_test(quasimo_trotter quasimo/TrotterTdWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_iqpe_vqe quasimo/IterativeQpeVqe.cpp) add_qcor_compile_and_exe_test(quasimo_adapt_vqe quasimo/AdaptVqeWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_qaoa quasimo/QaoaWorkflow.cpp) #add_qcor_compile_and_exe_test(quasimo_qaoa quasimo/QaoaWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_qite quasimo/QiteWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_heisenberg quasimo/TdWorkflowHeisenbergModel.cpp) add_qcor_compile_and_exe_test(quasimo_verified_qpe quasimo/VerifiedQuantumPhaseEstimation.cpp) #add_qcor_compile_and_exe_test(quasimo_verified_qpe quasimo/VerifiedQuantumPhaseEstimation.cpp) add_qcor_compile_and_exe_test(hadamard_ctrl_test ctrl-gates/simple_hadamard_test.cpp) add_qcor_compile_and_exe_test(multi_ctrl_test ctrl-gates/multiple_controls.cpp) Loading @@ -73,6 +73,7 @@ add_qcor_compile_and_exe_test(qrt_qpu_lambdas_in_loop qpu_lambda/deuteron_lambda add_qcor_compile_and_exe_test(qrt_qpu_lambda_deuteron qpu_lambda/deuteron_vqe.cpp) add_qcor_compile_and_exe_test(qrt_qpu_lambda_objfunc qpu_lambda/deuteron_vqe_obj_func.cpp) add_qcor_compile_and_exe_test(qrt_qpu_lambda_hadamard_test ctrl-gates/hadamard_test.cpp) add_qcor_compile_and_exe_test(qrt_qpu_lambda_compute_action qpu_lambda/lambda_with_compute_action.cpp) # Arithmetic tests add_qcor_compile_and_exe_test(qrt_qpu_arith_adder arithmetic/simple.cpp) Loading examples/qpu_lambda/lambda_with_compute_action.cpp 0 → 100644 +32 −0 Original line number Diff line number Diff line #include "qcor.hpp" int main() { auto ansatz = qpu_lambda([](qreg q, double theta) { X(q[0]); X(q[2]); compute { Rx(q[0], constants::pi / 2); for (auto i : range(3)) H(q[i + 1]); for (auto i : range(3)) { CX(q[i], q[i + 1]); } } action { Rz(q[3], theta); } }); std::string s = R"#((0.0454063,0) 2^ 0^ 1 3 + (0.0454063,0) 1^ 2^ 3 0 + (0.168336,0) 2^ 0^ 0 2 + (0.1202,0) 1^ 0^ 0 1 + (0.174073,0) 1^ 3^ 3 1 + (-0.174073,-0) 1^ 3^ 1 3 + (-0.0454063,-0) 3^ 0^ 2 1 + (-0.0454063,-0) 2^ 0^ 3 1 + (-0.0454063,-0) 1^ 2^ 0 3 + (-0.168336,-0) 2^ 0^ 2 0 + (-0.1202,-0) 2^ 3^ 2 3 + (-0.0454063,-0) 3^ 1^ 2 0 + (-0.165607,-0) 1^ 2^ 1 2 + (0.165607,0) 0^ 3^ 3 0 + (-0.1202,-0) 0^ 1^ 0 1 + (0.0454063,0) 3^ 1^ 0 2 + (0.165607,0) 1^ 2^ 2 1 + (0.165607,0) 2^ 1^ 1 2 + (0.0454063,0) 1^ 3^ 2 0 + (-0.0454063,-0) 0^ 3^ 1 2 + (-0.1202,-0) 3^ 2^ 3 2 + (-0.0454063,-0) 2^ 1^ 3 0 + (-0.174073,-0) 3^ 1^ 3 1 + (0.1202,0) 2^ 3^ 3 2 + (0.0454063,0) 3^ 0^ 1 2 + (-0.165607,-0) 3^ 0^ 3 0 + (0.165607,0) 3^ 0^ 0 3 + (0.174073,0) 3^ 1^ 1 3 + (0.1202,0) 3^ 2^ 2 3 + (0.0454063,0) 0^ 2^ 3 1 + (0.168336,0) 0^ 2^ 2 0 + (0.1202,0) 0^ 1^ 1 0 + (-0.0454063,-0) 0^ 2^ 1 3 + (-0.165607,-0) 2^ 1^ 2 1 + (-0.165607,-0) 0^ 3^ 0 3 + (-0.1202,-0) 1^ 0^ 1 0 + (-0.168336,-0) 0^ 2^ 0 2 + (0.0454063,0) 2^ 1^ 0 3 + (-0.479678,-0) 3^ 3 + (-1.24885,-0) 0^ 0 + (-0.479678,-0) 1^ 1 + (0.708024,0) + (0.0454063,0) 0^ 3^ 2 1 + (-0.0454063,-0) 1^ 3^ 0 2 + (-1.24885,-0) 2^ 2)#"; auto H = createOperator( "fermion", s); auto q = qalloc(4); auto objective = createObjectiveFunction(ansatz, H, q, 1); auto optimizer = createOptimizer("nlopt", {{"maxeval", 20}}); // Optimize the above function auto [optval, opt_params] = optimizer->optimize(*objective.get()); // Print the result printf("energy = %f\n", optval); } No newline at end of file handlers/token_collector/pyxasm/pyxasm_token_collector.cpp +9 −2 Original line number Diff line number Diff line Loading @@ -79,10 +79,12 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP, line += for_stmt; } // If statement: // If statement or while statement: // Add a space b/w tokens. // Note: Python has an "elif" token, which doesn't have a C++ equiv. if (Toks[i].is(clang::tok::TokenKind::kw_if) || PP.getSpelling(Toks[i]) == "elif") { PP.getSpelling(Toks[i]) == "elif" || Toks[i].is(clang::tok::TokenKind::kw_while)) { line += " "; i += 1; line += PP.getSpelling(Toks[i]); Loading Loading @@ -171,6 +173,11 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP, // Remove the first two characters ("el") // hence this line will be parsed as an idependent C++ if block: lineText.erase(0, 2); } else if (line.first.rfind("while ", 0) == 0) { // rewrite to // while (condition) {} // Just capture the indent level to close the scope properly scope_block_indent.push(line.second); } // is_in_for_loop = line.first.find("for ") != std::string::npos && // line.second >= previous_col; Loading handlers/token_collector/pyxasm/pyxasm_visitor.hpp +44 −1 Original line number Diff line number Diff line Loading @@ -457,7 +457,17 @@ class pyxasm_visitor : public pyxasmBaseVisitor { return 0; } } else { return visitChildren(ctx); // Visit child node: auto child_result = visitChildren(ctx); const auto translated_src = sub_node_translation.str(); sub_node_translation.str(std::string()); // If no child nodes, perform the codegen (result.first is not set) // but just appending the incremental translation collector; // return the collected C++ statement. if (result.first.empty() && !translated_src.empty()) { result.first = translated_src + ";\n"; } return child_result; } } Loading Loading @@ -501,6 +511,39 @@ class pyxasm_visitor : public pyxasmBaseVisitor { return visitChildren(ctx); } virtual antlrcpp::Any visitWhile_stmt(pyxasmParser::While_stmtContext *ctx) override { std::stringstream ss; ss << "while (" << ctx->test()->getText() << ") {\n"; result.first = ss.str(); return 0; } virtual antlrcpp::Any visitTestlist_star_expr( pyxasmParser::Testlist_star_exprContext *context) override { // std::cout << "Testlist_star_exprContext:" << context->getText() << "\n"; const auto var_name = context->getText(); if (xacc::container::contains(declared_var_names, var_name)) { sub_node_translation << var_name << " "; return 0; } return visitChildren(context); } virtual antlrcpp::Any visitAugassign(pyxasmParser::AugassignContext *context) override { // std::cout << "Augassign:" << context->getText() << "\n"; sub_node_translation << context->getText() << " "; return 0; } virtual antlrcpp::Any visitTestlist(pyxasmParser::TestlistContext *context) override { // std::cout << "visitTestlist:" << context->getText() << "\n"; sub_node_translation << context->getText() << " "; return 0; } private: // Replaces common Python constants, e.g. 'math.pi' or 'numpy.pi'. // Note: the library names have been resolved to their original names. Loading Loading
docker/deploy/code-server/base/Dockerfiledeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line FROM codercom/code-server:latest ENV DEBIAN_FRONTEND noninteractive RUN echo 'deb http://deb.debian.org/debian testing main' | sudo tee /etc/apt/sources.list.d/testing.list RUN sudo apt-get update \ && sudo apt-get install -y \ curl build-essential wget gdb \ dumb-init \ zsh \ htop \ locales \ man \ nano \ git \ procps \ openssh-client \ sudo \ vim.tiny libssl-dev liblapack-dev libblas-dev ninja-build zlib1g-dev \ libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev \ lsb-release libcurl4-openssl-dev \ && sudo rm -rf /var/lib/apt/lists/* \ && sudo wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz \ && sudo tar xzf Python-3.8.2.tgz && cd Python-3.8.2 \ && sudo CCSHARED='-fPIC' ./configure --prefix=/usr --exec-prefix=/usr --enable-shared --enable-optimizations \ && sudo make altinstall && cd ../ && sudo rm -rf Python-3.8.2* \ && wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/PUBLIC-KEY.gpg | sudo apt-key add - \ && wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/focal/aide-qc.list" | sudo tee -a /etc/apt/sources.list.d/aide-qc.list \ && /usr/bin/pip3.8 install ipopo cmake --user \ && sudo unlink /usr/bin/python3 && sudo ln -s /usr/bin/python3.8 /usr/bin/python3 \ && sudo sed -i 's/#!\/usr\/bin\/python3/#!\/usr\/bin\/python3.9/' /usr/bin/lsb_release
examples/CMakeLists.txt +3 −2 Original line number Diff line number Diff line Loading @@ -53,10 +53,10 @@ add_qcor_compile_and_exe_test(quasimo_vqe quasimo/VqeWithAnsatzCircuit.cpp) add_qcor_compile_and_exe_test(quasimo_trotter quasimo/TrotterTdWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_iqpe_vqe quasimo/IterativeQpeVqe.cpp) add_qcor_compile_and_exe_test(quasimo_adapt_vqe quasimo/AdaptVqeWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_qaoa quasimo/QaoaWorkflow.cpp) #add_qcor_compile_and_exe_test(quasimo_qaoa quasimo/QaoaWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_qite quasimo/QiteWorkflow.cpp) add_qcor_compile_and_exe_test(quasimo_heisenberg quasimo/TdWorkflowHeisenbergModel.cpp) add_qcor_compile_and_exe_test(quasimo_verified_qpe quasimo/VerifiedQuantumPhaseEstimation.cpp) #add_qcor_compile_and_exe_test(quasimo_verified_qpe quasimo/VerifiedQuantumPhaseEstimation.cpp) add_qcor_compile_and_exe_test(hadamard_ctrl_test ctrl-gates/simple_hadamard_test.cpp) add_qcor_compile_and_exe_test(multi_ctrl_test ctrl-gates/multiple_controls.cpp) Loading @@ -73,6 +73,7 @@ add_qcor_compile_and_exe_test(qrt_qpu_lambdas_in_loop qpu_lambda/deuteron_lambda add_qcor_compile_and_exe_test(qrt_qpu_lambda_deuteron qpu_lambda/deuteron_vqe.cpp) add_qcor_compile_and_exe_test(qrt_qpu_lambda_objfunc qpu_lambda/deuteron_vqe_obj_func.cpp) add_qcor_compile_and_exe_test(qrt_qpu_lambda_hadamard_test ctrl-gates/hadamard_test.cpp) add_qcor_compile_and_exe_test(qrt_qpu_lambda_compute_action qpu_lambda/lambda_with_compute_action.cpp) # Arithmetic tests add_qcor_compile_and_exe_test(qrt_qpu_arith_adder arithmetic/simple.cpp) Loading
examples/qpu_lambda/lambda_with_compute_action.cpp 0 → 100644 +32 −0 Original line number Diff line number Diff line #include "qcor.hpp" int main() { auto ansatz = qpu_lambda([](qreg q, double theta) { X(q[0]); X(q[2]); compute { Rx(q[0], constants::pi / 2); for (auto i : range(3)) H(q[i + 1]); for (auto i : range(3)) { CX(q[i], q[i + 1]); } } action { Rz(q[3], theta); } }); std::string s = R"#((0.0454063,0) 2^ 0^ 1 3 + (0.0454063,0) 1^ 2^ 3 0 + (0.168336,0) 2^ 0^ 0 2 + (0.1202,0) 1^ 0^ 0 1 + (0.174073,0) 1^ 3^ 3 1 + (-0.174073,-0) 1^ 3^ 1 3 + (-0.0454063,-0) 3^ 0^ 2 1 + (-0.0454063,-0) 2^ 0^ 3 1 + (-0.0454063,-0) 1^ 2^ 0 3 + (-0.168336,-0) 2^ 0^ 2 0 + (-0.1202,-0) 2^ 3^ 2 3 + (-0.0454063,-0) 3^ 1^ 2 0 + (-0.165607,-0) 1^ 2^ 1 2 + (0.165607,0) 0^ 3^ 3 0 + (-0.1202,-0) 0^ 1^ 0 1 + (0.0454063,0) 3^ 1^ 0 2 + (0.165607,0) 1^ 2^ 2 1 + (0.165607,0) 2^ 1^ 1 2 + (0.0454063,0) 1^ 3^ 2 0 + (-0.0454063,-0) 0^ 3^ 1 2 + (-0.1202,-0) 3^ 2^ 3 2 + (-0.0454063,-0) 2^ 1^ 3 0 + (-0.174073,-0) 3^ 1^ 3 1 + (0.1202,0) 2^ 3^ 3 2 + (0.0454063,0) 3^ 0^ 1 2 + (-0.165607,-0) 3^ 0^ 3 0 + (0.165607,0) 3^ 0^ 0 3 + (0.174073,0) 3^ 1^ 1 3 + (0.1202,0) 3^ 2^ 2 3 + (0.0454063,0) 0^ 2^ 3 1 + (0.168336,0) 0^ 2^ 2 0 + (0.1202,0) 0^ 1^ 1 0 + (-0.0454063,-0) 0^ 2^ 1 3 + (-0.165607,-0) 2^ 1^ 2 1 + (-0.165607,-0) 0^ 3^ 0 3 + (-0.1202,-0) 1^ 0^ 1 0 + (-0.168336,-0) 0^ 2^ 0 2 + (0.0454063,0) 2^ 1^ 0 3 + (-0.479678,-0) 3^ 3 + (-1.24885,-0) 0^ 0 + (-0.479678,-0) 1^ 1 + (0.708024,0) + (0.0454063,0) 0^ 3^ 2 1 + (-0.0454063,-0) 1^ 3^ 0 2 + (-1.24885,-0) 2^ 2)#"; auto H = createOperator( "fermion", s); auto q = qalloc(4); auto objective = createObjectiveFunction(ansatz, H, q, 1); auto optimizer = createOptimizer("nlopt", {{"maxeval", 20}}); // Optimize the above function auto [optval, opt_params] = optimizer->optimize(*objective.get()); // Print the result printf("energy = %f\n", optval); } No newline at end of file
handlers/token_collector/pyxasm/pyxasm_token_collector.cpp +9 −2 Original line number Diff line number Diff line Loading @@ -79,10 +79,12 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP, line += for_stmt; } // If statement: // If statement or while statement: // Add a space b/w tokens. // Note: Python has an "elif" token, which doesn't have a C++ equiv. if (Toks[i].is(clang::tok::TokenKind::kw_if) || PP.getSpelling(Toks[i]) == "elif") { PP.getSpelling(Toks[i]) == "elif" || Toks[i].is(clang::tok::TokenKind::kw_while)) { line += " "; i += 1; line += PP.getSpelling(Toks[i]); Loading Loading @@ -171,6 +173,11 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP, // Remove the first two characters ("el") // hence this line will be parsed as an idependent C++ if block: lineText.erase(0, 2); } else if (line.first.rfind("while ", 0) == 0) { // rewrite to // while (condition) {} // Just capture the indent level to close the scope properly scope_block_indent.push(line.second); } // is_in_for_loop = line.first.find("for ") != std::string::npos && // line.second >= previous_col; Loading
handlers/token_collector/pyxasm/pyxasm_visitor.hpp +44 −1 Original line number Diff line number Diff line Loading @@ -457,7 +457,17 @@ class pyxasm_visitor : public pyxasmBaseVisitor { return 0; } } else { return visitChildren(ctx); // Visit child node: auto child_result = visitChildren(ctx); const auto translated_src = sub_node_translation.str(); sub_node_translation.str(std::string()); // If no child nodes, perform the codegen (result.first is not set) // but just appending the incremental translation collector; // return the collected C++ statement. if (result.first.empty() && !translated_src.empty()) { result.first = translated_src + ";\n"; } return child_result; } } Loading Loading @@ -501,6 +511,39 @@ class pyxasm_visitor : public pyxasmBaseVisitor { return visitChildren(ctx); } virtual antlrcpp::Any visitWhile_stmt(pyxasmParser::While_stmtContext *ctx) override { std::stringstream ss; ss << "while (" << ctx->test()->getText() << ") {\n"; result.first = ss.str(); return 0; } virtual antlrcpp::Any visitTestlist_star_expr( pyxasmParser::Testlist_star_exprContext *context) override { // std::cout << "Testlist_star_exprContext:" << context->getText() << "\n"; const auto var_name = context->getText(); if (xacc::container::contains(declared_var_names, var_name)) { sub_node_translation << var_name << " "; return 0; } return visitChildren(context); } virtual antlrcpp::Any visitAugassign(pyxasmParser::AugassignContext *context) override { // std::cout << "Augassign:" << context->getText() << "\n"; sub_node_translation << context->getText() << " "; return 0; } virtual antlrcpp::Any visitTestlist(pyxasmParser::TestlistContext *context) override { // std::cout << "visitTestlist:" << context->getText() << "\n"; sub_node_translation << context->getText() << " "; return 0; } private: // Replaces common Python constants, e.g. 'math.pi' or 'numpy.pi'. // Note: the library names have been resolved to their original names. Loading