Skip to content
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

[WIP] Cutensornet High-Level API exploration #680

Draft
wants to merge 75 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
665fb47
Remove StateVector dependency for utils tests
multiphaseCFD Apr 11, 2024
3621d23
Auto update version
github-actions[bot] Apr 11, 2024
7254de6
update changelog
multiphaseCFD Apr 11, 2024
0dd944b
Merge branch 'clean_LGPU_utils_test' of https://github.com/PennyLaneA…
multiphaseCFD Apr 11, 2024
b08d8d1
add missing header file
multiphaseCFD Apr 11, 2024
033ec01
Initial commit
multiphaseCFD Apr 11, 2024
de45233
fix for multiple backends
multiphaseCFD Apr 11, 2024
e480920
add change log
multiphaseCFD Apr 11, 2024
5c6777b
Merge branch 'master' into create_cuda_utils_module
multiphaseCFD Apr 12, 2024
9cd6c42
Auto update version
github-actions[bot] Apr 12, 2024
7990a81
Trigger CI
multiphaseCFD Apr 12, 2024
fb2e60d
Merge branch 'create_cuda_utils_module' of https://github.com/PennyLa…
multiphaseCFD Apr 12, 2024
86daa95
rename utils_mpi test cpp
multiphaseCFD Apr 12, 2024
ca3bad3
update format
multiphaseCFD Apr 12, 2024
aed4495
Link utils against cuda_utils
multiphaseCFD Apr 12, 2024
1b00711
Initial commit
multiphaseCFD Apr 12, 2024
5ddeab7
Error Handle with cuErrors.hpp
multiphaseCFD Apr 12, 2024
caa3c78
merge master
multiphaseCFD Apr 12, 2024
41816b8
Auto update version
github-actions[bot] Apr 12, 2024
8ba948a
Init commit
multiphaseCFD Apr 12, 2024
d258aad
Add MidMeasureMP Kokkos (#658)
tomlqc Apr 12, 2024
1cb364e
Trigger CI
multiphaseCFD Apr 12, 2024
7243da1
make format
multiphaseCFD Apr 12, 2024
450ef72
add cuTensorNetError.hpp
multiphaseCFD Apr 12, 2024
c013ce8
MPSHelper->MPS fix typo
multiphaseCFD Apr 12, 2024
79ddfaf
Auto update version
github-actions[bot] Apr 12, 2024
5cd4324
remove exploration codes
multiphaseCFD Apr 15, 2024
d78a84f
remove test.cpp
multiphaseCFD Apr 15, 2024
0a41824
Init commit for state vector set and return
multiphaseCFD Apr 16, 2024
9ab44ee
tidy up code
multiphaseCFD Apr 16, 2024
4a10b2d
refactor test6.cpp
multiphaseCFD Apr 16, 2024
3edb83e
add docstring
multiphaseCFD Apr 16, 2024
b0cf77e
add lightning.tensor logo
multiphaseCFD Apr 16, 2024
0bd59e2
move cuGates_host.hpp to cuda_utils
multiphaseCFD Apr 16, 2024
4477996
construct cudevicetensor with emplace_back
multiphaseCFD Apr 16, 2024
ae8f25d
initial gateOperation implementation
multiphaseCFD Apr 16, 2024
4e04e95
initial applyOperation implementation
multiphaseCFD Apr 16, 2024
7bdbf35
tidy up workspace creation
multiphaseCFD Apr 17, 2024
85803a3
Auto update version
github-actions[bot] Apr 17, 2024
a445780
easier work space setup
multiphaseCFD Apr 17, 2024
8130d4c
update main.cpp
multiphaseCFD Apr 17, 2024
142d980
add controlled gate support
multiphaseCFD Apr 17, 2024
13a2c40
Auto update version
github-actions[bot] Apr 17, 2024
cefca98
refactor and build lightning_tensor lib
multiphaseCFD Apr 17, 2024
12c0380
add next plan for obs_cuMPS and measurement_cuMPS
multiphaseCFD Apr 18, 2024
18889e7
store custatetensor_handle with share_ptr
multiphaseCFD Apr 18, 2024
424f052
add obs & gate tests
multiphaseCFD Apr 19, 2024
5a6ae9b
add obs support 0
multiphaseCFD Apr 19, 2024
e048bc3
merge master + remove main.cpp
multiphaseCFD Apr 19, 2024
3479eab
Merge branch 'master' into cutensornet_api_exploration
multiphaseCFD Apr 19, 2024
70fa4b5
Auto update version
github-actions[bot] Apr 19, 2024
729806c
create TN Ops with shared_ptr<GateTensorCache<T>>
multiphaseCFD Apr 19, 2024
3dbc4b3
update CMakeLisits.txt src/utils
multiphaseCFD Apr 19, 2024
caad601
update cuTensorNetError.hpp
multiphaseCFD Apr 19, 2024
f691b11
update cuMPS
multiphaseCFD Apr 19, 2024
9e3e1e3
add TODO tasks for copy ctor of cuMPS
multiphaseCFD Apr 19, 2024
f225b77
test cuMPS copy ctor
multiphaseCFD Apr 22, 2024
841b37e
add measurement feature
multiphaseCFD Apr 22, 2024
bc9cfb7
refactor cuMPS
multiphaseCFD Apr 23, 2024
025ae0b
Auto update version from '0.36.0-dev34' to '0.36.0-dev36'
ringo-but-quantum Apr 23, 2024
fe4b270
renaming cuMPS->MPSCuda
multiphaseCFD Apr 23, 2024
c01c10c
refactor expval to expval_ [skip ci]
multiphaseCFD Apr 23, 2024
49f9e6a
update copy ctor
multiphaseCFD Apr 24, 2024
3a7104a
Auto update version from '0.36.0-dev36' to '0.36.0-dev41'
ringo-but-quantum Apr 24, 2024
66a2fb6
add CI workflow
multiphaseCFD Apr 24, 2024
8e8f5fb
Merge branch 'master' into cutensornet_api_exploration
multiphaseCFD Apr 24, 2024
0e5064e
better 256 aligment for computeState API
multiphaseCFD Apr 25, 2024
b60d037
work flow tests
multiphaseCFD Apr 25, 2024
9f6e27c
update gate unit tests
multiphaseCFD Apr 25, 2024
98968b4
use applyGateTensor for CSWAP
multiphaseCFD Apr 26, 2024
611225c
Auto update version from '0.36.0-dev41' to '0.36.0-dev43'
ringo-but-quantum Apr 26, 2024
c1424b0
add gate id in the graph to cuGateCache
multiphaseCFD May 4, 2024
85da39d
Auto update version from '0.36.0-dev43' to '0.36.0-dev48'
ringo-but-quantum May 4, 2024
a384479
proof that applyGateTensor only append gate to graph
multiphaseCFD May 7, 2024
3c32fd6
Auto update version from '0.36.0-dev48' to '0.37.0-dev4'
ringo-but-quantum May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions .github/workflows/tests_cutn_mps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
name: Testing::Linux::x86_64::CuTN_MPS
on:
workflow_call:
inputs:
lightning-version:
type: string
required: true
description: The version of Lightning to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
pennylane-version:
type: string
required: true
description: The version of PennyLane to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
release:
pull_request:
push:
branches:
- master

env:
CI_CUDA_ARCH: 86
COVERAGE_FLAGS: "--cov=pennylane_lightning --cov-report=term-missing --cov-report=xml:./coverage.xml --no-flaky-report -p no:warnings --tb=native"
GCC_VERSION: 11

concurrency:
group: tests_gpu-${{ github.ref }}
cancel-in-progress: true

jobs:
builddeps:
runs-on:
- self-hosted
- ubuntu-22.04
- gpu

strategy:
max-parallel: 1
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_tensor"]
cuda_version: ["12"]

steps:
- name: Validate GPU version and installed compiler
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/${{ matrix.cuda_version }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
nvidia-smi

cpptestswithcuTNMPS:
if: ${{ !contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }}
needs: [builddeps]
strategy:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_tensor"]
cuda_version: ["12"]

name: C++ tests (Lightning-Tensor-CuTN-MPS)
runs-on:
- ${{ matrix.os }}
- self-hosted
- gpu

steps:
- name: Validate GPU version and installed compiler
run: |
source /etc/profile.d/modules.sh
module use /opt/modules
module load cuda/${{ matrix.cuda_version }}
echo "${PATH}" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
nvcc --version
nvidia-smi

- name: Checkout PennyLane-Lightning-Tensor-CuTNMPS
uses: actions/checkout@v4
with:
path: main

- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.9'

- name: Setup Python virtual environment
id: setup_venv
env:
VENV_NAME: ${{ github.workspace }}/venv_${{ steps.setup_python.outputs.python-version }}_${{ github.sha }}
run: |
# Clear any pre-existing venvs
rm -rf venv_*

# Create new venv for this workflow_run
python --version
python -m venv ${{ env.VENV_NAME }}

# Add the venv to PATH for subsequent steps
echo ${{ env.VENV_NAME }}/bin >> $GITHUB_PATH

# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT

- name: Display Python-Path
id: python_path
run: |
py_path=$(which python)
echo "Python Interpreter Path => $py_path"
echo "python=$py_path" >> $GITHUB_OUTPUT

pip_path=$(which python)
echo "PIP Path => $pip_path"
echo "pip=$pip_path" >> $GITHUB_OUTPUT

- name: Install required packages
run: |
python -m pip install ninja cmake scipy custatevec-cu${{ matrix.cuda_version }} cutensornet-cu${{ matrix.cuda_version }}

- name: Build and run unit tests
run: |
set -x
cd main
cmake . -BBuild \
-DCUQUANTUM_SDK=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum')")\
-DBUILD_TESTS=ON \
-DENABLE_PYTHON=OFF \
-DPL_BACKEND=${{ matrix.pl_backend }} \
-DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION) \
-DENABLE_COVERAGE=ON \
-G Ninja
cmake --build ./Build
cd ./Build
mkdir -p ./tests/results_${{ github.job }}_${{ matrix.pl_backend }}
for file in *runner ; do ./$file --order lex --reporter junit --out ./tests/results_${{ github.job }}_${{ matrix.pl_backend }}/report_$file.xml; done;
lcov --directory . -b ../pennylane_lightning/core/src --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
mv coverage.info coverage-${{ github.job }}-${{ matrix.pl_backend }}.info
set +x
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: ubuntu-tests-reports-${{ github.job }}_${{ matrix.pl_backend }}
path: ./main/Build/tests/results_${{ github.job }}_${{ matrix.pl_backend }}
if-no-files-found: error

- name: Upload code coverage results
uses: actions/upload-artifact@v3
with:
name: ubuntu-codecov-results-cpp
path: ./main/Build/coverage-${{ github.job }}-${{ matrix.pl_backend }}.info
if-no-files-found: error


upload-to-codecov-linux-cpp:
needs: [cpptestswithcuTNMPS]
name: Upload coverage data to codecov
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download coverage reports
uses: actions/download-artifact@v3
with:
name: ubuntu-codecov-results-cpp

- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Cleanup
if: always()
run: |
rm -rf ${{ steps.setup_venv.outputs.venv_name }}
rm -rf *
rm -rf .git
rm -rf .gitignore
rm -rf .github
pip cache purge
2 changes: 1 addition & 1 deletion .github/workflows/tests_gpu_cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
required: true
description: The version of PennyLane to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
release:
pull_request:
#pull_request:
push:
branches:
- master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_gpu_kokkos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
type: string
required: true
description: The version of PennyLane to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
pull_request:
#pull_request:
push:
branches:
- master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
type: string
required: true
description: The version of PennyLane to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
pull_request:
#pull_request:
push:
branches:
- master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_linux_x86_mpi_gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
push:
branches:
- main
pull_request:
#pull_request:

env:
COVERAGE_FLAGS: "--cov=pennylane_lightning --cov-report=term-missing --cov-report=xml:./coverage.xml --no-flaky-report -p no:warnings --tb=native"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
push:
branches:
- master
pull_request:
#pull_request:

concurrency:
group: tests_windows-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_without_binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
type: string
required: true
description: The version of PennyLane to use. Valid values are either 'release' (most recent release candidate), 'stable' (most recent git-tag) or 'latest' (most recent commit from master)
pull_request:
#pull_request:
push:
branches:
- master
Expand Down
48 changes: 48 additions & 0 deletions cmake/support_pllgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,51 @@ macro(findCustatevec external_libs)
target_link_libraries(${external_libs} INTERFACE custatevec)
endif()
endmacro()

# Macro to aid in finding cuStateVec lib
macro(findCutensornet external_libs)
find_library(CUTENSORNET_LIB
NAMES libcutensornet.so.2
HINTS /usr/lib
/usr/local/cuda
/usr/local/lib
/opt
/opt/cuda
lib
lib64
${CUQUANTUM_SDK}/lib
${CUQUANTUM_SDK}/lib64
${CUDAToolkit_LIBRARY_DIR}
${CUDA_TOOLKIT_ROOT_DIR}/lib
${CUDA_TOOLKIT_ROOT_DIR}/lib64
${Python_SITELIB}/cuquantum/lib
ENV LD_LIBRARY_PATH
)

find_file( CUTENSORNET_INC
NAMES cutensornet.h
HINTS /usr/include
/usr/local/cuda
/usr/local/include
/opt
/opt/cuda
include
${CUQUANTUM_SDK}/include
${CUDAToolkit_INCLUDE_DIRS}
${CUDA_TOOLKIT_ROOT_DIR}/include
${Python_SITELIB}/cuquantum/include
ENV CPATH
)

if(NOT CUTENSORNET_LIB OR NOT CUTENSORNET_INC)
message(FATAL_ERROR "\nUnable to find cuQuantum SDK installation. Please ensure it is correctly installed and available on path.")
else()
add_library( cutensornet SHARED IMPORTED GLOBAL)

get_filename_component(CUTENSORNET_INC_DIR ${CUTENSORNET_INC} DIRECTORY)
target_include_directories(cutensornet INTERFACE ${CUTENSORNET_INC_DIR})
set_target_properties( cutensornet PROPERTIES IMPORTED_LOCATION ${CUTENSORNET_LIB})

target_link_libraries(${external_libs} INTERFACE cutensornet)
endif()
endmacro()
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.36.0-dev40"
__version__ = "0.37.0-dev4"
6 changes: 6 additions & 0 deletions pennylane_lightning/core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ set(COMPONENT_SUBDIRS algorithms
simulators
utils
)
if("${PL_BACKEND}" STREQUAL "lightning_tensor")
add_subdirectory(simulators)
add_subdirectory(gates)
add_subdirectory(utils)
else()
foreach(COMP ${COMPONENT_SUBDIRS})
add_subdirectory(${COMP})
endforeach()
endif()

if (BUILD_TESTS)
# Include macros supporting tests.
Expand Down
2 changes: 2 additions & 0 deletions pennylane_lightning/core/src/simulators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.20)

project(lightning_simulators LANGUAGES CXX)

if(NOT "${PL_BACKEND}" STREQUAL "lightning_tensor")
add_subdirectory(base)
endif()

###############################################################################
# Determine simulator and include its directory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.21)

project(lightning_tensor_components LANGUAGES CXX)

###############################################################################
# Include all nested sources directories
###############################################################################
set(COMPONENT_SUBDIRS base
mps
utils
)

foreach(COMP ${COMPONENT_SUBDIRS})
add_subdirectory(${COMP})
endforeach()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.20)

project(lightning_tensor_base LANGUAGES CXX)

add_library(lightning_tensor_base INTERFACE)

target_include_directories(lightning_tensor_base INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lightning_tensor_base INTERFACE lightning_utils lightning_compile_options lightning_external_libs)

set_property(TARGET lightning_tensor_base PROPERTY POSITION_INDEPENDENT_CODE ON)

if (BUILD_TESTS)
enable_testing()
#add_subdirectory("tests")
endif()
Loading
Loading