-
Notifications
You must be signed in to change notification settings - Fork 25
feat: GridSynth #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LonerDavid
wants to merge
12
commits into
DVLab-NTU:main
Choose a base branch
from
LonerDavid:feat/gridsynth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: GridSynth #165
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bf1837d
feat(qcir): integrate gridsynth command for qcir
LonerDavid 71bfefc
chore: keep clang-tidy off GMP/MPFR system headers for lint
LonerDavid c7d7b0f
fix: skip GridSynth W gates for correctness
LonerDavid dde23dd
test: add equiv dof tests
LonerDavid 7a7d216
fix: remove unreachable RZ qubit-count guard
LonerDavid 1f186ff
fix: optional GMP/MPFR link
LonerDavid 2187a0a
fix: warn per skipped controlled-RZ in gridsynth
LonerDavid 26f4be8
add: add new benchmark code
LonerDavid dcbe995
fix: .gitignore and build file updated
LonerDavid 574baa7
fix: force user install gmp/mpfr
LonerDavid 9362cd4
fix: auto-install GMP/MPFR via apt when missing
LonerDavid 25bb383
style: clang-format gridsynth sources
LonerDavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| # Integrate vendored cppgridsynth (GridSynth) as a static library for qsyn. | ||
| # | ||
| # GMP/MPFR are linked only into `cppgridsynth`; qsyn core keeps double/float. | ||
| # Override QSYN_CPPEGRIDSYNTH_DIR only when testing an external cppgridsynth tree. | ||
|
|
||
| option(QSYN_ENABLE_GRIDSYNTH "Build qcir gridsynth (requires GMP and MPFR)" ON) | ||
|
|
||
| if(NOT QSYN_ENABLE_GRIDSYNTH) | ||
| message(STATUS "GridSynth integration disabled (QSYN_ENABLE_GRIDSYNTH=OFF)") | ||
| return() | ||
| endif() | ||
|
|
||
| set(QSYN_CPPEGRIDSYNTH_DIR | ||
| "${CMAKE_SOURCE_DIR}/vendor/cppgridsynth" | ||
| CACHE PATH "cppgridsynth source tree (default: vendored under vendor/)") | ||
|
|
||
| if(NOT EXISTS "${QSYN_CPPEGRIDSYNTH_DIR}/include/cppgridsynth/gridsynth.hpp") | ||
| message(FATAL_ERROR | ||
| "Vendored cppgridsynth not found at ${QSYN_CPPEGRIDSYNTH_DIR}. " | ||
| "Ensure vendor/cppgridsynth is present in the qsyn tree.") | ||
| endif() | ||
|
|
||
| # Auto-install GMP/MPFR when missing (Makefile also runs scripts/ensure_gridsynth_deps.sh). | ||
| execute_process( | ||
| COMMAND "${CMAKE_SOURCE_DIR}/scripts/ensure_gridsynth_deps.sh" | ||
| RESULT_VARIABLE _gridsynth_deps_result | ||
| OUTPUT_QUIET | ||
| ERROR_QUIET) | ||
| if(NOT _gridsynth_deps_result EQUAL 0) | ||
| message(FATAL_ERROR | ||
| "GridSynth: could not install GMP/MPFR (ensure_gridsynth_deps.sh failed). " | ||
| "Try: sudo apt install -y libgmp-dev libmpfr-dev pkg-config") | ||
| endif() | ||
|
|
||
| # Homebrew / MacPorts prefixes (MPFR pkg-config is often missing on macOS). | ||
| set(_gridsynth_prefix_hints) | ||
| if(APPLE) | ||
| foreach(_brew_bin /opt/homebrew/bin/brew /usr/local/bin/brew) | ||
| if(EXISTS "${_brew_bin}") | ||
| execute_process( | ||
| COMMAND "${_brew_bin}" --prefix | ||
| OUTPUT_VARIABLE _brew_prefix | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
| list(APPEND _gridsynth_prefix_hints "${_brew_prefix}") | ||
| break() | ||
| endif() | ||
| endforeach() | ||
| list(APPEND _gridsynth_prefix_hints /opt/homebrew /usr/local /opt/local) | ||
| endif() | ||
|
|
||
| find_package(PkgConfig QUIET) | ||
| set(_gridsynth_gmp_mpfr_ok FALSE) | ||
| if(PkgConfig_FOUND) | ||
| pkg_check_modules(PC_GMP IMPORTED_TARGET gmp) | ||
| pkg_check_modules(PC_MPFR IMPORTED_TARGET mpfr) | ||
| if(PC_GMP_FOUND AND PC_MPFR_FOUND) | ||
| set(_gridsynth_gmp_mpfr_ok TRUE) | ||
| set(_gridsynth_use_pkgconfig TRUE) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(NOT _gridsynth_gmp_mpfr_ok) | ||
| find_path( | ||
| GRIDSYNTH_GMP_INCLUDE | ||
| NAMES gmp.h | ||
| HINTS ${_gridsynth_prefix_hints} | ||
| PATH_SUFFIXES include) | ||
| find_library( | ||
| GRIDSYNTH_GMP_LIB | ||
| NAMES gmp | ||
| HINTS ${_gridsynth_prefix_hints} | ||
| PATH_SUFFIXES lib) | ||
| find_path( | ||
| GRIDSYNTH_MPFR_INCLUDE | ||
| NAMES mpfr.h | ||
| HINTS ${_gridsynth_prefix_hints} | ||
| PATH_SUFFIXES include) | ||
| find_library( | ||
| GRIDSYNTH_MPFR_LIB | ||
| NAMES mpfr | ||
| HINTS ${_gridsynth_prefix_hints} | ||
| PATH_SUFFIXES lib) | ||
| find_library( | ||
| GRIDSYNTH_GMPXX_LIB | ||
| NAMES gmpxx | ||
| HINTS ${_gridsynth_prefix_hints} | ||
| PATH_SUFFIXES lib) | ||
| if(GRIDSYNTH_GMP_INCLUDE | ||
| AND GRIDSYNTH_GMP_LIB | ||
| AND GRIDSYNTH_MPFR_INCLUDE | ||
| AND GRIDSYNTH_MPFR_LIB | ||
| AND GRIDSYNTH_GMPXX_LIB) | ||
| set(_gridsynth_gmp_mpfr_ok TRUE) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(NOT _gridsynth_gmp_mpfr_ok) | ||
| message(FATAL_ERROR | ||
| "GridSynth requires GMP and MPFR, but they were not found.\n" | ||
| "Install them and reconfigure:\n" | ||
| " macOS : brew install gmp mpfr\n" | ||
| " Debian : sudo apt install libgmp-dev libmpfr-dev\n" | ||
| " Fedora : sudo dnf install gmp-devel mpfr-devel\n" | ||
| "Or build without GridSynth: cmake -DQSYN_ENABLE_GRIDSYNTH=OFF ...") | ||
| endif() | ||
|
|
||
| # libgmpxx (GMP's C++ wrapper) has no reliable pkg-config module, so resolve it | ||
| # directly in both the pkg-config and find_library branches. Linking it by its | ||
| # full path avoids relying on libgmpxx being on the default linker search path. | ||
| find_library( | ||
| GRIDSYNTH_GMPXX_LIB | ||
| NAMES gmpxx | ||
| HINTS ${_gridsynth_prefix_hints} | ||
| PATH_SUFFIXES lib) | ||
| if(NOT GRIDSYNTH_GMPXX_LIB) | ||
| message(FATAL_ERROR | ||
| "GridSynth requires libgmpxx (GMP's C++ wrapper), which was not found. " | ||
| "It ships alongside GMP (macOS: brew install gmp; " | ||
| "Debian: apt install libgmp-dev; Fedora: dnf install gmp-c++).") | ||
| endif() | ||
|
|
||
| set(_cppgridsynth_sources | ||
| ${CMAKE_SOURCE_DIR}/src/qcir/gridsynth/gridsynth_adapter.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/mpfloat.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/mymath.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/ring.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/quantum_gate.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/quantum_circuit.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/circuit_stats.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/grid_op.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/region.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/odgp.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/tdgp.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/to_upright.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/diophantine.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/domega_unitary.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/normal_form.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/synthesis_of_cliffordT.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/gridsynth.cpp | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/src/loop_controller.cpp | ||
| ) | ||
|
|
||
| add_library(cppgridsynth STATIC ${_cppgridsynth_sources}) | ||
| add_library(cppgridsynth::cppgridsynth ALIAS cppgridsynth) | ||
|
|
||
| target_include_directories( | ||
| cppgridsynth | ||
| PUBLIC | ||
| ${QSYN_CPPEGRIDSYNTH_DIR}/include | ||
| ${CMAKE_SOURCE_DIR}/src) | ||
|
|
||
| target_compile_features(cppgridsynth PUBLIC cxx_std_20) | ||
|
|
||
| target_compile_options( | ||
| cppgridsynth | ||
| PRIVATE | ||
| -Wall | ||
| -Wextra | ||
| -Wno-unused-parameter) | ||
|
|
||
| if(_gridsynth_use_pkgconfig) | ||
| target_link_libraries( | ||
| cppgridsynth | ||
| PUBLIC | ||
| PkgConfig::PC_GMP | ||
| PkgConfig::PC_MPFR | ||
| ${GRIDSYNTH_GMPXX_LIB}) | ||
| else() | ||
| # SYSTEM PRIVATE: external headers; also keeps clang-tidy off GMP/MPFR. | ||
| target_include_directories( | ||
| cppgridsynth | ||
| SYSTEM PRIVATE | ||
| ${GRIDSYNTH_GMP_INCLUDE} | ||
| ${GRIDSYNTH_MPFR_INCLUDE}) | ||
| target_link_libraries( | ||
| cppgridsynth | ||
| PUBLIC | ||
| ${GRIDSYNTH_MPFR_LIB} | ||
| ${GRIDSYNTH_GMP_LIB} | ||
| ${GRIDSYNTH_GMPXX_LIB}) | ||
| endif() | ||
|
|
||
| function(qsyn_link_gridsynth target) | ||
| target_compile_definitions(${target} PUBLIC QSYN_ENABLE_GRIDSYNTH=1) | ||
| # PUBLIC so final executables (qsyn, unit-test) inherit GMP/MPFR on Linux. | ||
| target_link_libraries(${target} PUBLIC cppgridsynth::cppgridsynth) | ||
| endfunction() | ||
|
|
||
| message(STATUS "GridSynth: cppgridsynth from ${QSYN_CPPEGRIDSYNTH_DIR}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.