Skip to content

Commit 26e3851

Browse files
committed
Merge branch 'main_copy25.09' into 'main'
sync with internal repo1 (commit 62f139f5a) See merge request cuda-hpc-libraries/cuquantum-sdk/cuquantum-public!39
2 parents 67485c4 + f6984ed commit 26e3851

File tree

230 files changed

+22450
-10744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+22450
-10744
lines changed

python/README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ For instructions on installing *cuQuantum Python*, refer to our
1313

1414
The build-time dependencies of the cuQuantum Python package include:
1515

16-
* CUDA Toolkit 11.x or 12.x
16+
* CUDA Toolkit 12.x or 13.x
1717
* Python >=3.11, <3.14
18-
* Cython >=0.29.22
18+
* Cython >=3.0.4,!=3.1.0,!=3.1.1
1919
* pip 21.3.1+
2020
* [packaging](https://packaging.pypa.io/en/latest/)
21-
* setuptools 61.0.0+
21+
* setuptools 77.0.3+
2222
* wheel 0.34.0+
2323

2424
> **Note:** Starting with cuQuantum Python v25.06, cuQuantum C libraries including cuDensityMat, cuStateVec and cuTensorNet are no longer build-time dependencies. However, they are still required at runtime.
@@ -29,37 +29,36 @@ To compile and install cuQuantum Python from source, please follow the steps bel
2929

3030
1. Clone the [NVIDIA/cuQuantum](https://github.com/NVIDIA/cuQuantum) repository: `git clone https://github.com/NVIDIA/cuQuantum`
3131
2. Set `CUDA_PATH` to point to your CUDA installation
32-
3. [optional] Set `CUQUANTUM_ROOT` to point to your cuQuantum installation
33-
4. [optional] Set `CUTENSOR_ROOT` to point to your cuTENSOR installation
34-
5. [optional] Make sure cuQuantum and cuTENSOR are visible in your `LD_LIBRARY_PATH`
35-
6. Switch to the directory containing the Python implementation: `cd cuQuantum/python`
36-
7. Build and install:
37-
- Run `pip install .` if you skip Step 3-5 above
32+
3. [optional] Make sure cuQuantum and cuTENSOR are visible in your `LD_LIBRARY_PATH`
33+
4. Switch to the directory containing the Python implementation: `cd cuQuantum/python`
34+
5. Build and install:
35+
- Run `pip install .` if you skip Step 3 above
3836
- Run `pip install -v --no-deps --no-build-isolation .` otherwise (advanced)
3937

4038
Notes:
41-
- For Step 7, if you are building from source for testing/developing purposes you'd likely want to insert a `-e` flag before the last period (so `pip ... .` becomes `pip ... -e .`):
39+
- For Step 5, if you are building from source for testing/developing purposes you'd likely want to insert a `-e` flag before the last period (so `pip ... .` becomes `pip ... -e .`):
4240
* `-e`: use the "editable" (in-place) mode
4341
* `-v`: enable more verbose output
4442
* `--no-deps`: avoid installing the *run-time* dependencies
4543
* `--no-build-isolation`: reuse the current Python environment instead of creating a new one for building the package (this avoids installing any *build-time* dependencies)
46-
- As an alternative to setting `CUQUANTUM_ROOT`, `CUSTATEVEC_ROOT`, `CUTENSORNET_ROOT` and `CUDENSITYMAT_ROOT` can be set to point to the cuStateVec, cuTensorNet and cuDensityMat libraries, respectively. The latter three environment variables take precedence if defined.
47-
- Please ensure that you use consistent binaries and packages for either CUDA 11 or 12. Mixing-and-matching will result in undefined behavior.
44+
- Please ensure that you use consistent binaries and packages for either CUDA 12 or 13. Mixing-and-matching will result in undefined behavior.
4845

4946
## Running
5047

5148
### Requirements
5249

5350
Runtime dependencies of the cuQuantum Python package include:
5451

55-
* An NVIDIA GPU with compute capability 7.0+
56-
* Driver: Linux (450.80.02+ for CUDA 11, 525.60.13+ for CUDA 12)
57-
* CUDA Toolkit 11.x or 12.x
58-
* cuStateVec 1.9.0+
59-
* cuTensorNet 2.8.0+
60-
* cuDensityMat >=0.2.0, <0.3.0
52+
* An NVIDIA GPU with compute capability 7.5+
53+
* Driver: Linux (525.60.13+ for CUDA 12, 580.65.06+ for CUDA 13)
54+
* CUDA Toolkit 12.x or 13.x
55+
* cuStateVec 1.10.0+
56+
* cuTensorNet 2.9.0+
57+
* cuDensityMat >=0.3.0, <0.4.0
6158
* Python >=3.11, <3.14
6259
* NumPy v1.21+
60+
* nvmath-python ==0.6.0
61+
* cuda-bindings >=12.9.2, <13.0.0 for CUDA 12 or cuda-bindings >=13.0.1, <14.0.0
6362
* CuPy v13.0.0+ (see [installation guide](https://docs.cupy.dev/en/stable/install.html))
6463
* PyTorch v1.10+ (optional, see [installation guide](https://pytorch.org/get-started/locally/))
6564
* Qiskit v1.4.2+ (optional, see [installation guide](https://qiskit.org/documentation/getting_started.html))
@@ -76,7 +75,7 @@ to your `LD_LIBRARY_PATH` environment variable, and that a compatible CuPy is in
7675

7776
Known issues:
7877
- If a system has multiple copies of cuTENSOR, one of which is installed in a default system path, the Python runtime could pick it up despite cuQuantum Python is linked to another copy installed elsewhere, potentially causing a version-mismatch error. The proper fix is to remove cuTENSOR from the system paths to ensure the visibility of the proper copy. **DO NOT ATTEMPT** to use `LD_PRELOAD` to overwrite it --- it could cause hard to debug behaviors!
79-
- Please ensure that you use consistent binaries and packages for either CUDA 11 or 12. Mixing-and-matching will result in undefined behavior.
78+
- Please ensure that you use consistent binaries and packages for either CUDA 12 or 13. Mixing-and-matching will result in undefined behavior.
8079

8180
### Samples
8281

python/builder/utils.py

Lines changed: 24 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,21 @@ def check_cuda_version():
4949
except:
5050
raise
5151
else:
52-
# 11020 -> "11.2"
52+
# 12020 -> "12.2"
5353
return str(ver // 1000) + '.' + str((ver % 100) // 10)
5454

5555

56-
# We support CUDA 11/12 starting 23.03
56+
# We support CUDA 12/13 starting 25.09
5757
cuda_ver = check_cuda_version()
58-
if cuda_ver == '11.0':
59-
cuda_major_ver = '11'
60-
elif '11.0' < cuda_ver < '12.0':
61-
cuda_major_ver = '11'
62-
elif '12.0' <= cuda_ver < '13.0':
58+
print("\n"+"*"*80)
59+
print("CUDA version:", cuda_ver)
60+
print("CUDA path:", cuda_path)
61+
print("*"*80+"\n")
62+
63+
if '12.0' <= cuda_ver < '13.0':
6364
cuda_major_ver = '12'
65+
elif '13.0' <= cuda_ver < '14.0':
66+
cuda_major_ver = '13'
6467
else:
6568
raise RuntimeError(f"Unsupported CUDA version: {cuda_ver}")
6669

@@ -78,67 +81,13 @@ def run(self):
7881

7982
class build_ext(_build_ext):
8083

81-
def _set_library_roots(self):
82-
custatevec_root = cutensornet_root = cudensitymat_root = cuquantum_root = None
83-
# Note that we need sys.path because of build isolation (since PEP 517)
84-
py_paths = sys.path + [site.getusersitepackages()] + site.getsitepackages()
85-
86-
# search order:
87-
# 1. installed "cuquantum" package
88-
# 2. env var
89-
for path in py_paths:
90-
path = os.path.join(path, 'cuquantum')
91-
if os.path.isdir(os.path.join(path, 'include')):
92-
custatevec_root = cutensornet_root = cudensitymat_root = path
93-
break
94-
else:
95-
# We allow setting CUSTATEVEC_ROOT, CUTENSORNET_ROOT & CUDENSITYMAT_ROOT separately for the ease
96-
# of development, but users are encouraged to either install cuquantum from PyPI
97-
# or conda, or set CUQUANTUM_ROOT to the existing installation.
98-
cuquantum_root = os.environ.get('CUQUANTUM_ROOT')
99-
try:
100-
custatevec_root = os.environ['CUSTATEVEC_ROOT']
101-
except KeyError as e:
102-
if cuquantum_root is None:
103-
raise RuntimeError('cuStateVec is not found, please set $CUQUANTUM_ROOT '
104-
'or $CUSTATEVEC_ROOT') from e
105-
try:
106-
cutensornet_root = os.environ['CUTENSORNET_ROOT']
107-
except KeyError as e:
108-
if cuquantum_root is None:
109-
raise RuntimeError('cuTensorNet is not found, please set $CUQUANTUM_ROOT '
110-
'or $CUTENSORNET_ROOT') from e
111-
112-
try:
113-
cudensitymat_root = os.environ['CUDENSITYMAT_ROOT']
114-
except KeyError as e:
115-
if cuquantum_root is None:
116-
raise RuntimeError('cuDensityMat is not found, please set $CUQUANTUM_ROOT '
117-
'or $CUDENSITYMAT_ROOT') from e
118-
119-
return custatevec_root, cutensornet_root, cudensitymat_root, cuquantum_root
120-
121-
def _prep_includes_libs_rpaths(self):
84+
def _prep_includes_libs_rpaths(self, ext_name):
12285
"""
123-
Set global vars cusv_incl_dir, cutn_incl_dir, cudm_incl_dir, and extra_linker_flags.
86+
Set global vars extra_linker_flags.
12487
12588
With the new bindings, we no longer need to link to cuQuantum DSOs.
12689
"""
127-
custatevec_root, cutensornet_root, cudensitymat_root, cuquantum_root = self._set_library_roots()
128-
129-
global cusv_incl_dir, cutn_incl_dir, cudm_incl_dir, cuqnt_incl_dir
130-
cusv_incl_dir = cutn_incl_dir = cudm_incl_dir = cuqnt_incl_dir = None
131-
base_incl_dir = (os.path.join(cuda_path, 'include'),)
132-
if cuquantum_root is not None:
133-
cuqnt_incl_dir = base_incl_dir + (os.path.join(cuquantum_root, 'include'),)
134-
if custatevec_root is not None:
135-
cusv_incl_dir = base_incl_dir + (os.path.join(custatevec_root, 'include'),)
136-
if cutensornet_root is not None:
137-
cutn_incl_dir = base_incl_dir + (os.path.join(cutensornet_root, 'include'),)
138-
if cudensitymat_root is not None:
139-
cudm_incl_dir = base_incl_dir + (os.path.join(cudensitymat_root, 'include'),)
140-
141-
global extra_linker_flags
90+
14291
if not building_wheel:
14392
# Note: with PEP-517 the editable mode would not build a wheel for installation
14493
# (and we purposely do not support PEP-660).
@@ -147,43 +96,29 @@ def _prep_includes_libs_rpaths(self):
14796
# Note: soname = library major version
14897
# We don't need to link to cuBLAS/cuSOLVER/cuTensor at build time
14998
# The rpaths must be adjusted given the following full-wheel installation:
150-
# - cuquantum-python: site-packages/cuquantum/{custatevec, cutensornet, cudensitymat}/_internal/ [=$ORIGIN]
99+
# - cuquantum-python: site-packages/cuquantum/bindings/_internal/ [=$ORIGIN]
151100
# - cusv, cutn & cudm: site-packages/cuquantum/lib/
152101
# - cutensor: site-packages/cutensor/lib/
153102
# - cublas: site-packages/nvidia/cublas/lib/
154103
# - cusolver: site-packages/nvidia/cusolver/lib/
155104
# (Note that starting v22.11 we use the new wheel format, so all lib wheels have suffix -cuXX,
156105
# and cuBLAS/cuSOLVER additionally have prefix nvidia-.)
157-
ldflag = "-Wl,--disable-new-dtags,"
158-
ldflag += "-rpath,$ORIGIN/../../lib,"
159-
ldflag += "-rpath,$ORIGIN/../../../cutensor/lib,"
160-
ldflag += "-rpath,$ORIGIN/../../../nvidia/cublas/lib,"
161-
ldflag += "-rpath,$ORIGIN/../../../nvidia/cusolver/lib"
106+
ldflag = "-Wl,--disable-new-dtags"
107+
ldflag += ",-rpath,$ORIGIN/../../lib"
108+
ldflag += ",-rpath,$ORIGIN/../../../nvidia/cublas/lib"
109+
if "cutensornet" in ext_name or "cudensitymat" in ext_name:
110+
ldflag += ",-rpath,$ORIGIN/../../../cutensor/lib"
111+
ldflag += ",-rpath,$ORIGIN/../../../nvidia/cusolver/lib"
112+
ldflag += ",-rpath,$ORIGIN/../../../nvidia/curand/lib"
162113
extra_linker_flags = [ldflag]
163114

164-
print("\n"+"*"*80)
165-
print("CUDA version:", cuda_ver)
166-
print("CUDA path:", cuda_path)
167-
print("cuStateVec path:", custatevec_root if custatevec_root else cuquantum_root)
168-
print("cuTensorNet path:", cutensornet_root if cutensornet_root else cuquantum_root)
169-
print("cuDensityMat path:", cudensitymat_root if cudensitymat_root else cuquantum_root)
170-
print("*"*80+"\n")
115+
return extra_linker_flags
171116

172117
def build_extension(self, ext):
173-
ext.include_dirs = ()
174-
for include_dir in (cusv_incl_dir, cutn_incl_dir, cudm_incl_dir, cuqnt_incl_dir):
175-
if include_dir is not None:
176-
ext.include_dirs += include_dir
177-
if ext.name.endswith("custatevec"):
178-
ext.extra_link_args = extra_linker_flags
179-
elif ext.name.endswith("cutensornet"):
180-
ext.extra_link_args = extra_linker_flags
181-
elif ext.name.endswith("cudensitymat"):
182-
ext.extra_link_args = extra_linker_flags
183-
118+
ext.include_dirs = (os.path.join(cuda_path, 'include'),)
119+
ext.extra_link_args = self._prep_includes_libs_rpaths(ext.name)
184120
super().build_extension(ext)
185121

186122
def build_extensions(self):
187-
self._prep_includes_libs_rpaths()
188123
self.parallel = 4 # use 4 threads
189124
super().build_extensions()

python/cuquantum/__init__.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,8 @@
33
# SPDX-License-Identifier: BSD-3-Clause
44

55
from cuquantum import bindings
6-
from cuquantum import custatevec
7-
from cuquantum import cutensornet
86
from cuquantum import densitymat
97
from cuquantum import tensornet
10-
from cuquantum.cutensornet import (
11-
contract, contract_path, einsum, einsum_path, tensor, tensor_qualifiers_dtype, BaseCUDAMemoryManager, CircuitToEinsum, MemoryPointer,
12-
Network, NetworkOptions, OptimizerInfo, OptimizerOptions, PathFinderOptions,
13-
ReconfigOptions, SlicerOptions, MemoryLimitExceeded)
8+
from cuquantum.memory import *
149
from cuquantum.bindings._utils import ComputeType, cudaDataType, libraryPropertyType
15-
from cuquantum._internal import enum_utils
1610
from cuquantum._version import __version__
17-
18-
19-
# We patch all enum values so that they have the correct docstrings
20-
for enum in (
21-
custatevec.Pauli,
22-
custatevec.MatrixLayout,
23-
custatevec.MatrixType,
24-
custatevec.MatrixMapType,
25-
custatevec.Collapse,
26-
custatevec.SamplerOutput,
27-
custatevec.DeviceNetworkType,
28-
cutensornet.NetworkAttribute,
29-
custatevec.CommunicatorType,
30-
custatevec.DataTransferType,
31-
custatevec.StateVectorType,
32-
cutensornet.Status,
33-
cutensornet.ContractionOptimizerInfoAttribute,
34-
cutensornet.ContractionOptimizerConfigAttribute,
35-
cutensornet.ContractionAutotunePreferenceAttribute,
36-
cutensornet.NetworkAttribute,
37-
cutensornet.WorksizePref,
38-
cutensornet.WorkspaceKind,
39-
cutensornet.Memspace,
40-
cutensornet.SmartOption,
41-
cutensornet.GraphAlgo,
42-
cutensornet.MemoryModel,
43-
cutensornet.OptimizerCost,
44-
cutensornet.TensorSVDConfigAttribute,
45-
cutensornet.TensorSVDAlgo,
46-
cutensornet.TensorSVDNormalization,
47-
cutensornet.TensorSVDPartition,
48-
cutensornet.TensorSVDInfoAttribute,
49-
cutensornet.GateSplitAlgo,
50-
cutensornet.BoundaryCondition,
51-
cutensornet.StatePurity,
52-
cutensornet.StateAttribute,
53-
cutensornet.MarginalAttribute,
54-
cutensornet.SamplerAttribute,
55-
cutensornet.AccessorAttribute,
56-
cutensornet.ExpectationAttribute,
57-
cutensornet.StateMPOApplication,
58-
cutensornet.StateMPSGaugeOption,
59-
):
60-
enum_utils.add_enum_class_doc(enum, chomp="_ATTRIBUTE|_PREFERENCE_ATTRIBUTE")
61-
62-
del enum
63-
del enum_utils

0 commit comments

Comments
 (0)