-
Notifications
You must be signed in to change notification settings - Fork 14
Add support for Pennylane Lightning backend to QIR-EE #28
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
Merged
Merged
Changes from 72 commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
1519286
Implement qir-qsim app for dynamic measurement handling
wongey 177aaa4
Remove redudant qsim folder
wongey 39223c3
Clean up results printing and output from Vicente
wongey c699ae4
Add dyanamic BV example from Vicente
wongey 65054f2
Revert changes to upstream and remove tpls
sethrj 63874bc
Update goldfinger configuration
sethrj 91753d6
Add qsim
sethrj e289381
Update version to get include directories working
sethrj ac7c244
Run clang format
sethrj ece521f
Add qsim dynamicbv test
wongey 713ace6
Merge branch 'ORNL-QCI:main' into qir-qsim
wongey a34f190
Capitalize class names q -> Q
wongey 8fb40f3
Update qsim file names
wongey 25d9433
Add examples
wongey 22d0ac9
Minor formatting
wongey 29be7ae
Resolve seed issue
wongey 19867f3
Minor formatting
wongey ede6e4a
Update qsim unit test
wongey 6fe3474
Refactor to move public to private types
wongey 24a06bb
Unused variables and naming
sethrj aadbb8a
Use PIMPL
sethrj 6f13b04
Delete tuple runtime, fix errors
sethrj 35778ad
Fix qsim test
wongey 8520063
Merge branch 'main' into qir-qsim
wongey 4658b44
Merge branch 'main' into qir-qsim
wongey e77166c
Merge branch 'main' into qir-qsim
wongey 6828673
Merge branch 'ORNL-QCI:main' into qir-qsim
wongey bdd35c4
including OutputDistribution into the libs list
vicenley cb373ba
old BufferManager now in qiree namespace
vicenley 181737d
deleting the old BufferManager
vicenley a92aacf
updating libs list
vicenley 040b834
updating manager (Buffer)
vicenley c5d2f04
REVERT ME Delete OutputDistribution and qsim app temporarily
wongey 10ed1ae
Fix build (some to be reverted)
sethrj f5f54cc
Store results in a buffer for post-entrypoint retrieval
sethrj 43c5b79
Add helper function
sethrj 5e32f3e
add qirlightning runtime
josephleekl 40c8fb7
add simple demo
josephleekl a76563c
Update README.md
josephleekl 611fa66
remove catalyst runtime deps and update demo
josephleekl de4d402
Merge branch 'qir-lightning' of github.com:PennyLaneAI/qiree into qir…
josephleekl 6c72907
remove redundant file
josephleekl 6da98d3
update lightningquantum
josephleekl ceea8ac
Merge branch 'main' into qir-lightning
josephleekl 7713cca
update
josephleekl e777b9c
format
josephleekl 6caa667
support lightning
josephleekl 422b3e7
add seeding
josephleekl 7f6598a
update
josephleekl 6246010
update
josephleekl 88dbe30
update readme
josephleekl 5a51303
Merge branch 'main' into qir-lightning
josephleekl 99800fa
update readme
josephleekl 3eb3002
update
josephleekl b8ec071
remove paths
josephleekl ce5d764
update
josephleekl 13cdde7
Merge branch 'main' into qir-lightning
josephleekl b7b6aee
update installation instructions
josephleekl d15106b
update tests and GH workflow
josephleekl a10c915
Merge branch 'main' into qir-lightning
josephleekl 227f5c6
update reset
josephleekl 17bae43
Merge branch 'main' into qir-lightning
josephleekl cf66bdb
single-result update
josephleekl b5eb61b
Merge branch 'main' into qir-lightning
josephleekl f9b76ae
update lightnign installation instructions
josephleekl 01dc855
Merge branch 'main' into qir-lightning
josephleekl 5574e46
update shots to seed
josephleekl 00080eb
update github workflow to run build-lightning
josephleekl aa25420
remove demo and pin catalyst
josephleekl cffe641
Merge branch 'main' into qir-lightning
josephleekl a93414e
update
josephleekl f8e43c5
update docs
josephleekl 2602033
update private member names
josephleekl c8c6917
seth comments
josephleekl 6737300
remove simple_demo
josephleekl b1344f7
remove build-lightning workflow
josephleekl 290a7e8
remove build-lightning workflow
josephleekl d1d1c5c
improve formatting for cmake/support_catalyst.cmake
josephleekl a1736ce
Merge branch 'main' into qir-lightning
josephleekl 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # Build directly on the GitHub runner with caching | ||
| name: build-lightning | ||
| on: | ||
| workflow_dispatch: | ||
| workflow_call: | ||
|
|
||
| concurrency: | ||
| group: build-lightning-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}-${{github.workflow}} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| linux: | ||
| name: ${{matrix.runner}}-${{matrix.compiler}}-${{matrix.version}}-llvm${{matrix.llvm}} | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - runner: jammy | ||
| compiler: gcc | ||
| version: 12 | ||
| llvm: 14 | ||
| - runner: jammy | ||
| compiler: clang | ||
| version: 15 | ||
| llvm: 15 | ||
| runs-on: >- | ||
| ${{ matrix.runner == 'focal' && 'ubuntu-20.04' | ||
| || matrix.runner == 'jammy' && 'ubuntu-22.04' | ||
| || null | ||
| }} | ||
| env: | ||
| CCACHE_DIR: "${{github.workspace}}/.ccache" | ||
| CCACHE_MAXSIZE: "10G" | ||
| CC: ${{matrix.compiler}}-${{matrix.version}} | ||
| CXX: ${{matrix.compiler == 'gcc' && 'g++' || 'clang++'}}-${{matrix.version}} | ||
| steps: | ||
| - uses: actions/setup-python@v5 | ||
| name: Install Python | ||
| with: | ||
| python-version: '3.10' | ||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get -q -y update | ||
| sudo apt-get -q -y install \ | ||
| ccache cmake ninja-build libgtest-dev \ | ||
| llvm-${{matrix.llvm}}-dev \ | ||
| ${{matrix.compiler}}-${{matrix.version}} \ | ||
| ${{matrix.compiler == 'gcc' && format('g++-{0}', matrix.version) || ''}} | ||
| echo "Installed toolchain:" | ||
| ld --version | head -1 | ||
| $CC --version | head -1 | ||
| $CXX --version | head -1 | ||
| llvm-config-${{matrix.llvm}} --version | head -1 | ||
| python -m pip install pennylane-lightning | ||
| - name: Check out | ||
| uses: actions/checkout@v4 | ||
| - name: Set up ccache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ${{env.CCACHE_DIR}} | ||
| key: ccache-${{matrix.runner}}-${{matrix.compiler}}-${{matrix.version}}-${{github.run_id}} | ||
| restore-keys: ccache-${{matrix.runner}}-${{matrix.compiler}}-${{matrix.version}} | ||
| - name: Zero ccache stats | ||
| run: | | ||
| ccache -z | ||
| - name: Configure | ||
| run: | | ||
| export LIGHTNING_SIM_PATH=$(python -c "import site; print( f'{site.getsitepackages()[0]}/pennylane_lightning')")/liblightning_qubit_catalyst.so | ||
sethrj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mkdir build && cd build | ||
| cmake -GNinja \ | ||
| -DQIREE_GIT_DESCRIBE="${{github.event.pull_request | ||
| && format(';-pr.{0};', github.event.pull_request.number) | ||
| || format(';-{0};', github.ref_name)}}" \ | ||
| -DQIREE_BUILD_TESTS:BOOL=ON \ | ||
| -DQIREE_DEBUG:BOOL=ON \ | ||
| -DQIREE_USE_XACC:BOOL=OFF \ | ||
| -DQIREE_USE_LIGHTNING:BOOL=ON \ | ||
| -DCMAKE_BUILD_TYPE="Release" \ | ||
| -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install" \ | ||
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | ||
| -DCMAKE_CXX_FLAGS="-Wall -Wextra -pedantic" \ | ||
| .. | ||
| - name: Build all | ||
| working-directory: build | ||
| run: | | ||
| ninja | ||
| - name: Run tests | ||
| working-directory: build | ||
| run: | | ||
| ctest --parallel 2 --timeout 15 --output-on-failure | ||
| - name: Install | ||
| working-directory: build | ||
| run: | | ||
| ninja install | ||
| - name: Show ccache stats | ||
| run: | | ||
| ccache -s | ||
|
|
||
| # vim: set nowrap tw=100: | ||
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,74 @@ | ||
| //----------------------------------*-C++-*----------------------------------// | ||
| // Copyright 2024 UT-Battelle, LLC, and other QIR-EE developers. | ||
| // See the top-level COPYRIGHT file for details. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| //---------------------------------------------------------------------------// | ||
| //! \file app/qir-lightning.cc | ||
| //---------------------------------------------------------------------------// | ||
| #include <cstdlib> | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <CLI/CLI.hpp> | ||
|
|
||
| #include "qiree/Executor.hh" | ||
| #include "qiree/Module.hh" | ||
| #include "qiree/ResultDistribution.hh" | ||
| #include "qirlightning/LightningQuantum.hh" | ||
| #include "qirlightning/LightningRuntime.hh" | ||
|
|
||
| using namespace std::string_view_literals; | ||
|
|
||
| namespace qiree | ||
| { | ||
| namespace app | ||
| { | ||
| //---------------------------------------------------------------------------// | ||
| void run(std::string const& filename, int num_shots) | ||
| { | ||
| // Load the input | ||
| Executor execute{Module{filename}}; | ||
|
|
||
| // Set up qsim | ||
| LightningQuantum sim(std::cout, 0); | ||
| LightningRuntime rt(std::cout, sim); | ||
| ResultDistribution distribution; | ||
|
|
||
| // Run several time = shots (default 1) | ||
| for (int i = 0; i < num_shots; i++) | ||
| { | ||
| execute(sim, rt); | ||
| distribution.accumulate(rt.result()); | ||
| } | ||
|
|
||
| std::cout << distribution.to_json() << std::endl; | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| } // namespace app | ||
| } // namespace qiree | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Execute and run. | ||
| */ | ||
| int main(int argc, char* argv[]) | ||
| { | ||
| int num_shots{1}; | ||
| std::string filename; | ||
|
|
||
| CLI::App app; | ||
|
|
||
| auto* filename_opt | ||
| = app.add_option("--input,-i,input", filename, "QIR input file"); | ||
| filename_opt->required(); | ||
|
|
||
| auto* nshot_opt | ||
| = app.add_option("-s,--shots", num_shots, "Number of shots"); | ||
| nshot_opt->capture_default_str(); | ||
|
|
||
| CLI11_PARSE(app, argc, argv); | ||
|
|
||
| qiree::app::run(filename, num_shots); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } |
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,69 @@ | ||
| #---------------------------------*-CMake-*----------------------------------# | ||
| # Copyright 2024 UT-Battelle, LLC, and other QIR-EE developers. | ||
| # See the top-level COPYRIGHT file for details. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| #----------------------------------------------------------------------------# | ||
|
|
||
| # Fetch Catalyst runtime include files | ||
| include(FetchContent) | ||
|
|
||
| include("${CMAKE_CURRENT_SOURCE_DIR}/support_catalyst.cmake") | ||
| FindCatalyst(qirlightning) | ||
|
|
||
| # Set the path to the lightning simulator shared library | ||
| if(DEFINED ENV{LIGHTNING_SIM_PATH}) | ||
| set(RTDLIB_PATH "$ENV{LIGHTNING_SIM_PATH}") | ||
| message(STATUS "RTDLIB_PATH set from environment variable LIGHTNING_SIM_PATH: ${RTDLIB_PATH}") | ||
| else() | ||
| # Throw an error if the environment variable is not defined | ||
| message(FATAL_ERROR "Environment variable LIGHTNING_SIM_PATH is not defined. Please set it to the path of the Lightning simulator shared library.") | ||
| endif() | ||
|
|
||
| # Set the device name for the lightning simulator | ||
| execute_process( | ||
| COMMAND nm -DC "${RTDLIB_PATH}" | grep " Factory" | ||
| OUTPUT_VARIABLE GREP_OUTPUT | ||
| ERROR_QUIET | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ) | ||
|
|
||
| if(GREP_OUTPUT) | ||
| string(REGEX MATCH "T (.*)Factory" SYMBOL_MATCH "${GREP_OUTPUT}") | ||
| if(SYMBOL_MATCH) | ||
| string(REGEX REPLACE "T (.*)Factory" "\\1" RTDDEVICE_NAME "${SYMBOL_MATCH}") | ||
| message(STATUS "Found Lightning Simulator. Extracted RTDDEVICE_NAME: ${RTDDEVICE_NAME}") | ||
| else() | ||
| message(FATAL_ERROR "Symbol 'Factory' found, but regex failed to extract.") | ||
| endif() | ||
| else() | ||
| message(FATAL_ERROR "Symbol 'Factory' not found in ${RTDLIB_PATH}. Please ensure LIGHTNING_SIM_PATH is set correctly.") | ||
| endif() | ||
|
|
||
|
|
||
josephleekl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Adding lightning as a library to qiree | ||
| qiree_add_library(qirlightning | ||
| LightningQuantum.cc | ||
| LightningRuntime.cc | ||
| ) | ||
|
|
||
| target_compile_definitions(qirlightning PRIVATE | ||
| RTDLIB="${RTDLIB_PATH}" | ||
| RTDDEVICE="${RTDDEVICE_NAME}" | ||
| ) | ||
sethrj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #Link the lightning library to qiree and any other relevant libraries | ||
| target_link_libraries(qirlightning | ||
| PUBLIC QIREE::qiree # Link to qiree | ||
| PRIVATE QIREE::lightning | ||
| ) | ||
|
|
||
| #----------------------------------------------------------------------------# | ||
| # HEADERS | ||
| #----------------------------------------------------------------------------# | ||
|
|
||
| # Install headers, matching the relevant .hh files for qsim integration | ||
| install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/" | ||
| DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qirlightning" | ||
| COMPONENT development | ||
| FILES_MATCHING REGEX ".*\\.hh?$" | ||
| ) | ||
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.