Skip to content

Commit

Permalink
Merge pull request #78 from softwareQinc/program_ast_mod
Browse files Browse the repository at this point in the history
Program ast mod
  • Loading branch information
jimlambert authored Jul 23, 2024
2 parents 5101aba + 2a4a759 commit 2c095bf
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 73 deletions.
32 changes: 23 additions & 9 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 .
24 changes: 11 additions & 13 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

---

Expand All @@ -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,
Expand Down
File renamed without changes.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,29 @@ 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.

---

## Installation instructions

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.

---
Expand All @@ -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.
File renamed without changes.
70 changes: 35 additions & 35 deletions cmake/staq_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion include/staq/output/lattice_surgery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/staq/transformations/qasm_synth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions prettyprint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

# $@ - List of directories

Expand All @@ -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
7 changes: 7 additions & 0 deletions qasmtools/include/qasmtools/ast/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ class Program : public ASTNode {
*/
std::list<ptr<Stmt>>& 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
*
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"-Iinclude",
"-Iqasmtools/include",
"-Ipystaq/include",
"-I/opt/homebrew/include",
]
extra_links_args = []

Expand Down

0 comments on commit 2c095bf

Please sign in to comment.