diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8d541a1..e8c776d 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install vcpkg (Windows) if: runner.os == 'Windows' @@ -48,16 +48,16 @@ jobs: -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake \ -DINSTALL_SOURCES=ON else - cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ - -DINSTALL_SOURCES=ON + cmake -B build -DINSTALL_SOURCES=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} fi - name: Build staq shell: bash run: | if [ "$RUNNER_OS" == "macOS" ]; then - export CPATH=$LIBRARY_PATH:/usr/local/include - export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib + # Required for libgmp headers + export CPATH=$LIBRARY_PATH:/opt/homebrew/include + export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib fi cmake --build build @@ -91,15 +91,16 @@ jobs: shell: bash run: | if [ "$RUNNER_OS" == "macOS" ]; then - export CPATH=$LIBRARY_PATH:/usr/local/include - export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib + # Required for libgmp headers + export CPATH=$LIBRARY_PATH:/opt/homebrew/include + export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib fi cmake --build build/unit_tests --target unit_tests - name: Run unit tests run: ctest --test-dir build - - name: Uninstall + - name: Uninstall staq shell: bash run: | if [ "$RUNNER_OS" == "Windows" ]; then @@ -109,4 +110,17 @@ jobs: fi - name: Install pystaq - run: pip3 install --user . + shell: bash + run: | + if [ "$RUNNER_OS" == "macOS" ]; then + # Required for libgmp headers + export CPATH=$LIBRARY_PATH:/opt/homebrew/include + export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib + fi + python3 -m venv venv + if [ "$RUNNER_OS" == "Windows" ]; then + venv/Scripts/activate + else + . venv/bin/activate + fi + pip install . diff --git a/INSTALL.md b/INSTALL.md index f48d6e3..d1dffaa 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -3,11 +3,10 @@ **staq** is a full-stack quantum processing toolkit that uses [CMake](https://cmake.org/) as its build/install system. **staq** is platform-independent, supporting -[UNIX](https://www.opengroup.org/membership/forums/platform/unix) -(including -[macOS](https://www.apple.com/macos/)) and UNIX-like operating systems -(e.g., [Linux](https://www.linux.org)), as well -as [Windows](https://www.microsoft.com/en-us/windows). +[UNIX](https://www.opengroup.org/membership/forums/platform/unix) (including +[macOS](https://www.apple.com/macos/)) and UNIX-like operating systems (e.g., +[Linux](https://www.linux.org)), as well as +[Windows](https://www.microsoft.com/en-us/windows). --- @@ -26,25 +25,24 @@ as [Windows](https://www.microsoft.com/en-us/windows). ## UNIX/UNIX-like/Windows -To build both tool suite and the **staq** executable, execute -(in a terminal/console/command prompt) under the project's root directory +To build both tool suite and the **staq** executable, execute (in a +terminal/console/command prompt) under the project's root directory ```shell cmake -B build ``` To be able to install **staq**'s source code in addition to the binaries, -configure -the system with +configure the system with ```shell cmake -B build -DINSTALL_SOURCES=ON ``` -**Important**: If you want to build the grid synth tools `staq_grid_synth` -and `staq_qasm_synth`, install the [GNU MP library](https://gmplib.org/); -`cmake` will take care of the rest. If `cmake` cannot detect GNU MP, then the -grid synth tools will not be part of the build. To install GNU MP on Windows +**Important**: If you want to build the grid synth tools `staq_grid_synth` and +`staq_qasm_synth`, install the [GNU MP library](https://gmplib.org/); `cmake` +will take care of the rest. If `cmake` cannot detect GNU MP, then the grid +synth tools will not be part of the build. To install GNU MP on Windows systems, please follow the [platform-specific instructions below](#windows). For more details about how to install and configure GNU MP on various platforms, diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md index 485406b..4de8e8d 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,21 @@ retrieving the original source code impossible. In particular, OpenQASM 2.0 circuits can be inspected and transformed (in most cases) without losing the original source structure. This makes **staq** ideally suited for source-to-source transformations, where only specific changes are desired. -Likewise, this allows translations to other common circuit description languages -and libraries to closely follow the OpenQASM 2.0 source. +Likewise, this allows translations to other common circuit description +languages and libraries to closely follow the OpenQASM 2.0 source. Check out the [Wiki](https://github.com/softwareQinc/staq/wiki) for more information about the library and included tools. -Copyright (c) 2013 - 2024 softwareQ Inc. All rights reserved. +Copyright (c) 2019 - 2024 softwareQ Inc. All rights reserved. --- ## License **staq** is distributed under the MIT license. Please see the -[`LICENSE`](https://github.com/softwareQinc/staq/blob/main/LICENSE) file for -more details. +[`LICENSE.txt`](https://github.com/softwareQinc/staq/blob/main/LICENSE.txt) +file for more details. --- @@ -45,8 +45,7 @@ more details. Please see the installation guide [`INSTALL.md`](https://github.com/softwareQinc/staq/blob/main/INSTALL.md) and -the -comprehensive [Wiki](https://github.com/softwareQinc/staq/wiki) for further +the comprehensive [Wiki](https://github.com/softwareQinc/staq/wiki) for further documentation and detailed examples. --- @@ -67,8 +66,8 @@ For more details, please see ## Acknowledgements -Thanks to the -excellent [EPFL logic synthesis libraries](https://github.com/lsils/lstools-showcase) +Thanks to the excellent +[EPFL logic synthesis libraries](https://github.com/lsils/lstools-showcase) which are used to perform logic synthesis in **staq**, and in particular Bruno Schmitt's [tweedledum](https://github.com/boschmitt/tweedledum) library, from which the OpenQASM 2.0 parser was adapted. diff --git a/VERSION b/VERSION.txt similarity index 100% rename from VERSION rename to VERSION.txt diff --git a/cmake/staq_uninstall.cmake.in b/cmake/staq_uninstall.cmake.in index 430c77d..947149d 100644 --- a/cmake/staq_uninstall.cmake.in +++ b/cmake/staq_uninstall.cmake.in @@ -1,35 +1,35 @@ -if(POLICY CMP0012) - cmake_policy(SET CMP0012 NEW) -endif() - -if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") - message( - FATAL_ERROR - "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") -endif() - -file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) -string(REGEX REPLACE "\n" ";" files "${files}") -foreach(file ${files}) - message(STATUS "Uninstalling $ENV{DESTDIR}${file}") - if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - execute_process( - COMMAND @CMAKE_COMMAND@ -E rm $ENV{DESTDIR}${file} - OUTPUT_VARIABLE rm_out - RESULT_VARIABLE rm_retval) - if(NOT "${rm_retval}" STREQUAL 0) - message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") - endif() - else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - message(STATUS "File $ENV{DESTDIR}${file} does not exist.") - endif() -endforeach() - -if(NOT "@MSVC@") - message(STATUS "Removing @CMAKE_INSTALL_PREFIX@/lib/cmake/@PROJECT_NAME@") - if("@INSTALL_SOURCES@") - message(STATUS "Removing @STAQ_INSTALL_DIR@") - endif() -else() - message(STATUS "Removing @CMAKE_INSTALL_PREFIX@") -endif() +if(POLICY CMP0012) + cmake_policy(SET CMP0012 NEW) +endif() + +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message( + FATAL_ERROR + "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif() + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling ${file}") + if(IS_SYMLINK "${file}" OR EXISTS "${file}") + execute_process( + COMMAND @CMAKE_COMMAND@ -E rm -f "${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval) + if(${rm_retval}) + message(FATAL_ERROR "Problem when removing ${file}") + endif() + else() + message(STATUS "File ${file} does not exist.") + endif() +endforeach() + +if(NOT "@MSVC@") + message(STATUS "Removing @CMAKE_INSTALL_PREFIX@/lib/cmake/@PROJECT_NAME@") + if("@INSTALL_SOURCES@") + message(STATUS "Removing @STAQ_INSTALL_DIR@") + endif() +else() + message(STATUS "Removing @CMAKE_INSTALL_PREFIX@") +endif() diff --git a/include/staq/output/lattice_surgery.hpp b/include/staq/output/lattice_surgery.hpp index 1363e1d..5715ae9 100644 --- a/include/staq/output/lattice_surgery.hpp +++ b/include/staq/output/lattice_surgery.hpp @@ -745,7 +745,7 @@ void output_lattice_surgery(ast::Program& prog, bool skip_clifford = false, throw; } } - std::cout << out.dump(2) << "\n"; + os << out.dump(2) << "\n"; } /** \brief Compiles an AST into lattice surgery instructions to a given output diff --git a/include/staq/transformations/qasm_synth.hpp b/include/staq/transformations/qasm_synth.hpp index 690ada5..905b074 100644 --- a/include/staq/transformations/qasm_synth.hpp +++ b/include/staq/transformations/qasm_synth.hpp @@ -54,7 +54,7 @@ class QASMSynthImpl final : public ast::Replacer { public: QASMSynthImpl(const GridSynthOptions& opt) : synthesizer_(make_synthesizer(opt)), w_count_(0), check_(opt.check), - details_(opt.details), verbose_(opt.verbose){}; + details_(opt.details), verbose_(opt.verbose) {}; ~QASMSynthImpl() = default; void run(ast::ASTNode& node) { node.accept(*this); } @@ -115,6 +115,8 @@ class QASMSynthImpl final : public ast::Replacer { } else { w_count_ += 2; } + } else if (c == 'I' || c == 'i') { // ignore identity elements + continue; } else { ret.emplace_back( make_gate(std::string(1, tolower(c)), gate)); diff --git a/prettyprint.sh b/prettyprint.sh index a14ac3a..8c7fad5 100755 --- a/prettyprint.sh +++ b/prettyprint.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # $@ - List of directories @@ -14,11 +14,11 @@ else echo "Error: $CLANG_FORMAT executable not found." >&2 exit 1 fi - echo "Code formatting with '$CLANG_FORMAT' the folders:" + echo "Code formatting with '$CLANG_FORMAT' the directories:" fi -for folder in "$@"; do - echo "$folder" - find "$folder" \( -iname '*.cpp' -o -iname '*.c' -o -iname '*.h' \ +for directory in "$@"; do + echo "$directory" + find "$directory" \( -iname '*.cpp' -o -iname '*.c' -o -iname '*.h' \ -o -iname '*.hpp' \) -exec "$CLANG_FORMAT" -style=file -i {} + done diff --git a/qasmtools/include/qasmtools/ast/program.hpp b/qasmtools/include/qasmtools/ast/program.hpp index 7aa370c..6bf8f9b 100644 --- a/qasmtools/include/qasmtools/ast/program.hpp +++ b/qasmtools/include/qasmtools/ast/program.hpp @@ -79,6 +79,13 @@ class Program : public ASTNode { */ std::list>& body() { return body_; } + /** + * \brief Get whether the standard library has been included + * + * \return Bool for whether the standard library has been included + */ + bool std_include() { return std_include_; } + /** * \brief Get the number of bits * diff --git a/setup.py b/setup.py index 609734f..3724fef 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ "-Iinclude", "-Iqasmtools/include", "-Ipystaq/include", + "-I/opt/homebrew/include", ] extra_links_args = []