Skip to content

Commit

Permalink
improvements (#74)
Browse files Browse the repository at this point in the history
* Update CMakeLists.txt

* fixed deprecation warning

* code reformatting

* added pystaq.to_ionq()

* Update staq_wrapper.cpp

* Update CHANGES

* Update CHANGES

* formatting

* Create .clangd

* Delete .clangd

* Update CMakeLists.txt

* updated copyright

* formatting

* Update README.md

* cmake linting and formatting

* formatting

* Update README.md

* Update README.md

* formatting

* Update README.md

* Update prettyprint.sh

* Update .clang-format

* Update .clang-format

* update

* update

* update
  • Loading branch information
vsoftco authored Feb 6, 2024
1 parent fd65df2 commit 5b4c887
Show file tree
Hide file tree
Showing 157 changed files with 1,541 additions and 1,050 deletions.
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ UseTab: Never
PointerAlignment: Left
IndentCaseLabels: true
AlwaysBreakTemplateDeclarations: Yes
InsertBraces: true
SortIncludes: true
# system headers come first
IncludeCategories:
- Regex: "^<.*>"
Priority: 1
- Regex: '^".*\.(h|hpp)"'
Priority: 2
17 changes: 13 additions & 4 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
Pre-release
- All header files are moved into "[include/staq]", so to include staq
headers one now must #include "staq/<header>.hpp". This change was made
for the sake of making the include statements look "uniform" in both
non-installed (compiling without having staq installed) and installed
(compiling with staq installed headers) modes.
- Integrated the 'staq_ionq' OpenQASM2 -> IonQ transpiler into pystaq

Version 3.4 - 1 December 2023
- When configuring staq with `cmake -B build -DINSTALL_SOURCES=ON`,
`cmake --build build --target install` now installs staq's source code in
- When configuring staq with 'cmake -B build -DINSTALL_SOURCES=ON',
'cmake --build build --target install' now installs staq's source code in
addition to the binaries
- Renamed the ["examples"] directory to ["misc"]
- Moved ["qpu_specs"] and ["scripts"] directories to ["misc"]
- Added standalone source code example (requires staq's source installation)
in the ["examples/standalone"] directory
- Added 'staq_ionq' OpenQASM2 -> IonQ transpiler

Version 3.3 - 6 October 2023
- Implemented the grid synth rotation synthesizer algorithm
https://arxiv.org/abs/1403.2975, enabled only when the GNU MP library is
detected. When enabled, the build will include `staq_grid_synth` and
`staq_qasm_synth`.
detected. When enabled, the build will include 'staq_grid_synth' and
'staq_qasm_synth'.

Version 3.2.3 - 14 August 2023
- Minor bugfix in pystaq setup.py that prevented pip install from remote
Expand Down
246 changes: 133 additions & 113 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.15)
set(STAQ_VERSION_NUM 3.4)
set(STAQ_VERSION_STR "${STAQ_VERSION_NUM}")
project(staq VERSION ${STAQ_VERSION_NUM} LANGUAGES CXX)
project(
staq
VERSION ${STAQ_VERSION_NUM}
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand All @@ -10,133 +13,150 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
enable_testing()

#### staq version
# staq version
add_compile_definitions(STAQ_VERSION_NUM=${STAQ_VERSION_NUM})
add_compile_definitions(STAQ_VERSION_STR="${STAQ_VERSION_STR}")

#### staq root directory
# staq root directory
add_compile_definitions(PROJECT_ROOT_DIR="${PROJECT_SOURCE_DIR}")

#### Force clang to use libc++
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options("-stdlib=libc++")
endif ()

#### Windows issues with Microsoft Visual Studio
if (MSVC)
include_directories(SYSTEM libs/third_party/pthreadwin32)
add_compile_options(-bigobj)
if (MSVC_VERSION GREATER_EQUAL 1914)
add_compile_options("/Zc:__cplusplus")
endif ()
endif ()

#### MinGW or Cygwin have issues with object files that are too large
if (MINGW OR CYGWIN)
add_compile_options("-Wa,-mbig-obj")
endif ()

#### Libs
include_directories(SYSTEM libs/third_party)

#### staq headers
# Force clang to use libc++
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options("-stdlib=libc++")
endif()

# Windows issues with Microsoft Visual Studio
if(MSVC)
include_directories(SYSTEM libs/third_party/pthreadwin32)
add_compile_options(-bigobj)
if(MSVC_VERSION GREATER_EQUAL 1914)
add_compile_options("/Zc:__cplusplus")
endif()
endif()

# MinGW or Cygwin have issues with object files that are too large
if(MINGW OR CYGWIN)
add_compile_options("-Wa,-mbig-obj")
endif()

# staq headers
add_library(libstaq INTERFACE)
target_compile_definitions(libstaq INTERFACE -DSTAQ_VERSION_NUM=${STAQ_VERSION_NUM})
target_compile_definitions(libstaq INTERFACE -DSTAQ_VERSION_STR="${STAQ_VERSION_STR}")
target_include_directories(libstaq INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/>)
#### qasmtools library
target_include_directories(libstaq INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/qasmtools/include/>
$<INSTALL_INTERFACE:include/staq/>)
#### 3rd party libs
target_include_directories(libstaq INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libs>
$<INSTALL_INTERFACE:include/staq/third_party>)

#### Enable OpenQASM 2.0 Specs
option(USE_OPENQASM2_SPECS "Use OpenQASM 2.0 standard instead of Qiskit gate specifications" OFF)
if (${USE_OPENQASM2_SPECS})
target_compile_definitions(libstaq INTERFACE -DUSE_OPENQASM2_SPECS=true)
message(STATUS "OpenQASM2 specs - ON")
else ()
target_compile_definitions(libstaq INTERFACE -DUSE_OPENQASM2_SPECS=false)
message(STATUS "OpenQASM2 specs - OFF")
endif ()

#### Compiler
target_compile_definitions(libstaq
INTERFACE -DSTAQ_VERSION_NUM=${STAQ_VERSION_NUM})
target_compile_definitions(libstaq
INTERFACE -DSTAQ_VERSION_STR="${STAQ_VERSION_STR}")
target_include_directories(
libstaq INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/staq>)

# qasmtools library
target_include_directories(
libstaq
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/qasmtools/include/>
$<INSTALL_INTERFACE:include/>)

# 3rd party libs
include_directories(SYSTEM libs/third_party)
target_include_directories(
libstaq INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libs>
$<INSTALL_INTERFACE:include/staq/third_party>)

# pystaq (only if Python development kit is detected)
find_package(Python3 QUIET COMPONENTS Interpreter Development)
if(${Python3_FOUND})
include(cmake/staq_pystaq.cmake)
endif()

# Enable OpenQASM 2.0 Specs
option(USE_OPENQASM2_SPECS
"Use OpenQASM 2.0 standard instead of Qiskit gate specifications" OFF)
if(${USE_OPENQASM2_SPECS})
target_compile_definitions(libstaq INTERFACE -DUSE_OPENQASM2_SPECS=true)
message(STATUS "OpenQASM2 specs - ON")
else()
target_compile_definitions(libstaq INTERFACE -DUSE_OPENQASM2_SPECS=false)
message(STATUS "OpenQASM2 specs - OFF")
endif()

# Compiler
set(COMPILER "staq")
add_executable(${COMPILER} ${PROJECT_SOURCE_DIR}/src/staq/main.cpp)
target_link_libraries(${COMPILER} PUBLIC libstaq)

#### Additional command line tools
# Additional command line tools
add_subdirectory(src/tools)

#### Unit testing
# Unit testing
add_subdirectory(${CMAKE_SOURCE_DIR}/unit_tests/)

#### Enable all warnings for GNU gcc and Clang/AppleClang
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID}
STREQUAL "GNU")
add_compile_options("-pedantic" "-Wall" "-Wextra" "-Weffc++")
endif ()

#### Default build type
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: \
None Debug Release MinSizeRel RelWithDebInfo."
FORCE)
endif ()

#### Installation (binaries)
# Enable all warnings for GNU gcc and Clang/AppleClang
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID}
STREQUAL "GNU")
add_compile_options("-pedantic" "-Wall" "-Wextra" "-Weffc++")
endif()

# Default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build, options are: \
None Debug Release MinSizeRel RelWithDebInfo." FORCE)
endif()

# Installation (binaries)
install(TARGETS ${COMPILER} DESTINATION ${CMAKE_INSTALL_BINDIR})

option(INSTALL_SOURCES "Enable staq's source code installation" OFF)

#### Installation (source)
if (INSTALL_SOURCES)
set(STAQ_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}")
install(DIRECTORY include/ DESTINATION ${STAQ_INSTALL_DIR})
install(DIRECTORY qasmtools/include/ DESTINATION ${STAQ_INSTALL_DIR})
install(DIRECTORY libs/third_party DESTINATION ${STAQ_INSTALL_DIR})
install(TARGETS libstaq EXPORT staq_targets)
install(EXPORT staq_targets DESTINATION "lib/cmake/${PROJECT_NAME}")
include(CMakePackageConfigHelpers)
configure_package_config_file(
"cmake/staqConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/staqConfig.cmake"
INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/staqConfig.cmake" DESTINATION "lib/cmake/${PROJECT_NAME}")
install(FILES "${CMAKE_SOURCE_DIR}/cmake/staq_msvc.cmake" DESTINATION "lib/cmake/${PROJECT_NAME}")
endif ()

#### Uninstall
#### https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
#### UNIX/Linux: sudo cmake --build build --target uninstall
#### Windows: cmake --build build --target uninstall
if (NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/staq_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
if (NOT MSVC)
if (INSTALL_SOURCES)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${STAQ_INSTALL_DIR}"
)
else ()
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
)
endif ()
else ()
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_INSTALL_PREFIX}"
)
endif ()
endif ()
# Installation (source)
if(INSTALL_SOURCES)
set(STAQ_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}")
install(DIRECTORY include/ DESTINATION ${STAQ_INSTALL_DIR})
install(DIRECTORY qasmtools/include/ DESTINATION ${STAQ_INSTALL_DIR})
install(DIRECTORY libs/third_party DESTINATION ${STAQ_INSTALL_DIR})
install(TARGETS libstaq EXPORT staq_targets)
install(EXPORT staq_targets DESTINATION "lib/cmake/${PROJECT_NAME}")
include(CMakePackageConfigHelpers)
configure_package_config_file(
"cmake/staqConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/staqConfig.cmake"
INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/staqConfig.cmake"
DESTINATION "lib/cmake/${PROJECT_NAME}")
install(FILES "${CMAKE_SOURCE_DIR}/cmake/staq_msvc.cmake"
DESTINATION "lib/cmake/${PROJECT_NAME}")
endif()

# Uninstall
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
# UNIX/Linux: sudo cmake --build build --target uninstall Windows: cmake
# --build build --target uninstall
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/staq_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
if(NOT MSVC)
if(INSTALL_SOURCES)
add_custom_target(
uninstall
COMMAND ${CMAKE_COMMAND} -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${STAQ_INSTALL_DIR}"
COMMENT "Uninstall staq and its sources")
else()
add_custom_target(
uninstall
COMMAND ${CMAKE_COMMAND} -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
COMMENT "Uninstall staq")
endif()
else()
add_custom_target(
uninstall
COMMAND ${CMAKE_COMMAND} -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_INSTALL_PREFIX}"
COMMENT "Uninstall staq")
endif()
endif()
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To build only the **staq** tool suite, execute

```shell
cmake --build build --target tools --parallel 8
````
```

To build only the **staq** executable, execute

Expand Down Expand Up @@ -156,7 +156,7 @@ Finally, configure the system with the additional flag
`-DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake`, e.g.,

```shell
cmake -B build -DCMAKE_TOOLCHAIN_FILE=./vckpg/scripts/buildsystems/vcpkg.cmake -DINSTALL_SOURCES=ON
cmake -B build -DCMAKE_TOOLCHAIN_FILE=./vckpg/scripts/buildsystems/vcpkg.cmake -DINSTALL_SOURCES=ON
```

followed by building the system as usual.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
Copyright (c) 2019 - 2024 softwareQ Inc. All rights reserved.

MIT License

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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 - 2023 softwareQ Inc. All rights reserved.
Copyright (c) 2013 - 2024 softwareQ Inc. All rights reserved.

---

Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions cmake/staq_pystaq.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# LSP and CMake support for pyqpp

# pybind11
include_directories(SYSTEM libs/)
target_include_directories(
libstaq INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libs/>)

# Python development
target_include_directories(libstaq
INTERFACE $<BUILD_INTERFACE:${Python3_INCLUDE_DIRS}>)

# pystaq
target_include_directories(
libstaq
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/pystaq/include/>)
6 changes: 3 additions & 3 deletions cmake/staq_uninstall.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ 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}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
execute_process(
COMMAND @CMAKE_COMMAND@ -E rm $ENV{DESTDIR}${file}
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
RESULT_VARIABLE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
Expand Down
1 change: 1 addition & 0 deletions examples/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(standalone)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# If staq's installation path was non-standard, i.e., specified by
#
Expand Down
Loading

0 comments on commit 5b4c887

Please sign in to comment.