Skip to content

Commit

Permalink
sync with internal repo (commit c8565a66)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofang committed Dec 17, 2021
1 parent 03305a2 commit 50e40da
Show file tree
Hide file tree
Showing 88 changed files with 10,078 additions and 36 deletions.
82 changes: 82 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Code of Conduct

## Overview

Define the code of conduct followed and enforced for the cuQuantum Python project.

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at
[[email protected]](mailto:[email protected]) All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an
incident. Further details of specific enforcement policies may be posted
separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Contributing

Thank you for your interest in contributing to cuQuantum Python! Based on the type of contribution, it will fall into two categories:

1. You want to report a bug, feature request, or documentation issue
- File an [issue](https://github.com/NVIDIA/cuQuantum/issues/new)
describing what you encountered or what you want to see changed.
- The NVIDIA team will evaluate the issues and triage them, scheduling
them for a release. If you believe the issue needs priority attention
comment on the issue to notify the team.
2. You want to implement a feature or bug-fix
- At this time we do not accept code contributions.
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
BSD-3-Clause

Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
82 changes: 82 additions & 0 deletions python/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Code of Conduct

## Overview

Define the code of conduct followed and enforced for the cuQuantum Python project.

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at
[[email protected]](mailto:[email protected]) All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an
incident. Further details of specific enforcement policies may be posted
separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
12 changes: 12 additions & 0 deletions python/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Contributing

Thank you for your interest in contributing to cuQuantum Python! Based on the type of contribution, it will fall into two categories:

1. You want to report a bug, feature request, or documentation issue
- File an [issue](https://github.com/NVIDIA/cuQuantum/issues/new)
describing what you encountered or what you want to see changed.
- The NVIDIA team will evaluate the issues and triage them, scheduling
them for a release. If you believe the issue needs priority attention
comment on the issue to notify the team.
2. You want to implement a feature or bug-fix
- At this time we do not accept code contributions.
28 changes: 28 additions & 0 deletions python/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD-3-Clause

Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 changes: 78 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# cuQuantum Python

## Documentation

Please visit the [NVIDIA cuQuantum SDK documentation](https://docs.nvidia.com/cuda/cuquantum/).

## Building

### Requirements

Build-time dependencies of the cuQuantum Python package and some versions that
are known to work are as follows:

* CUDA Toolkit 11.4+
* cuQuantum 0.1.0
* cuTENSOR 1.4.0+
* Cython - e.g. 0.29.21

### Install cuQuantum Python from conda-forge

If you already have a Conda environment set up, it is the easiest to install cuQuantum Python from the conda-forge channel:
```
conda install -c conda-forge cuquantum-python
```
The Conda solver will address all dependencies for you.

### Install cuQuantum Python from source

To compile and install cuQuantum Python from source, please follow the steps below:

1. Set `CUDA_PATH` to point to your CUDA installation
2. Set `CUQUANTUM_ROOT` to point to your cuQuantum installation
3. Set `CUTENSOR_ROOT` to point to your cuTENSOR installation
4. Make sure CUDA, cuQuantum and cuTENSOR are visible in your `LD_LIBRARY_PATH`
5. Run `pip install -v .`

Notes:
- For the `pip install` step, adding the `-e` flag after `-v` would allow installing the package in-place (i.e., in "editable mode" for testing/developing).
- If `CUSTATEVEC_ROOT` and `CUTENSORNET_ROOT` are set (for the cuStateVec and the cuTensorNet libraries, respectively), they overwrite `CUQUANTUM_ROOT`.
- For local development, set `CUQUANTUM_IGNORE_SOLVER=1` to ignore the dependency on the `cuquantum` wheel.


## Running

### Requirements

Runtime dependencies of the cuQuantum Python package include:

* An NVIDIA GPU with compute capability 7.0+
* Driver: Linux (450.80.02+)
* CUDA Toolkit 11.4+
* cuQuantum 0.1.0
* cuTENSOR 1.4.0+
* NumPy v1.17+
* CuPy v9.5.0+
* PyTorch v1.10+ (optional)

If you install everything from conda-forge, the dependencies are taken care for you (except for the driver).

If you build cuQuantum Python from source, please make sure the paths to the cuQuantum and cuTENSOR libraries are added
to your `LD_LIBRARY_PATH` environment variable.

Known issues:
- 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!
- In certain environments, if PyTorch is installed `import cuquantum` could fail (with a segmentation fault). It is currently under investigation and a temporary workaround is to import `torch` before importing `cuquantum`.

### Samples

Samples for demonstrating the usage of both low-level and high-level Python APIs are
available in the `samples` directory. The low-level API samples are 1:1 translations of the corresponding
samples written in C. The high-level API samples demonstrate pythonic usages of the cuTensorNet
library in Python.


## Testing

If pytest is installed, run `pytest tests` in the Python source root directory would
run all tests.
Empty file added python/cuquantum/__init__.pxd
Empty file.
29 changes: 29 additions & 0 deletions python/cuquantum/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from cuquantum import custatevec
from cuquantum import cutensornet
from cuquantum.cutensornet import (
contract, contract_path, einsum, einsum_path, Network,
NetworkOptions, OptimizerInfo, OptimizerOptions, PathFinderOptions, ReconfigOptions, SlicerOptions)
from cuquantum.utils import ComputeType, cudaDataType, libraryPropertyType


# We patch all enum values so that they have the correct docstrings
for enum in (
custatevec.Pauli,
custatevec.MatrixLayout,
custatevec.MatrixType,
custatevec.Collapse,
custatevec.SamplerOutput,
cutensornet.ContractionOptimizerInfoAttribute,
cutensornet.ContractionOptimizerConfigAttribute,
cutensornet.ContractionAutotunePreferenceAttribute,
):
cutensornet._internal.enum_utils.add_enum_class_doc(enum, chomp="_ATTRIBUTE|_PREFERENCE_ATTRIBUTE")
# these have yet another convention...
for v in cutensornet.GraphAlgorithm:
v.__doc__ = f"See `CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_GRAPH_ALGORITHM_{v.name}`."
cutensornet.MemoryModel.SLICER_HEURISTIC.__doc__ = \
f"See `CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MEMORY_MODEL_HEURISTIC`."
cutensornet.MemoryModel.SLICER_CUTENSOR.__doc__ = \
f"See `CUTENSORNET_CONTRACTION_OPTIMIZER_CONFIG_SLICER_MEMORY_MODEL_CUTENSOR`."

del enum, utils, v
1 change: 1 addition & 0 deletions python/cuquantum/custatevec/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from cuquantum.custatevec.custatevec import *
57 changes: 57 additions & 0 deletions python/cuquantum/custatevec/custatevec.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# TODO: Ultimately, everything should be auto-generated using
# the scripts from the CUDA Python team

from libc.stdint cimport intptr_t, int32_t, uint32_t, int64_t


# The C types are prefixed with an underscore because we are not
# yet protected by the module namespaces as done in CUDA Python.
# Once we switch over the names would be prettier (in the Cython
# layer).

cdef extern from '<custatevec.h>' nogil:
# cuStateVec types
ctypedef void* _Handle 'custatevecHandle_t'
ctypedef int64_t _Index 'custatevecIndex_t'
ctypedef int _Status 'custatevecStatus_t'
ctypedef struct _SamplerDescriptor 'custatevecSamplerDescriptor_t':
pass
ctypedef struct _AccessorDescriptor 'custatevecAccessorDescriptor':
pass
ctypedef enum _ComputeType 'custatevecComputeType_t':
pass
# ctypedef void(*custatevecLoggerCallback_t)(
# int32_t logLevel,
# const char* functionName,
# const char* message)
# ctypedef custatevecLoggerCallback_t LoggerCallback

# cuStateVec enums
ctypedef enum _Pauli 'custatevecPauli_t':
CUSTATEVEC_PAULI_I
CUSTATEVEC_PAULI_X
CUSTATEVEC_PAULI_Y
CUSTATEVEC_PAULI_Z

ctypedef enum _MatrixLayout 'custatevecMatrixLayout_t':
CUSTATEVEC_MATRIX_LAYOUT_COL
CUSTATEVEC_MATRIX_LAYOUT_ROW

ctypedef enum _MatrixType 'custatevecMatrixType_t':
CUSTATEVEC_MATRIX_TYPE_GENERAL
CUSTATEVEC_MATRIX_TYPE_UNITARY
CUSTATEVEC_MATRIX_TYPE_HERMITIAN

ctypedef enum _CollapseOp 'custatevecCollapseOp_t':
CUSTATEVEC_COLLAPSE_NONE
CUSTATEVEC_COLLAPSE_NORMALIZE_AND_ZERO

ctypedef enum _SamplerOutput 'custatevecSamplerOutput_t':
CUSTATEVEC_SAMPLER_OUTPUT_RANDNUM_ORDER
CUSTATEVEC_SAMPLER_OUTPUT_ASCENDING_ORDER

# cuStateVec consts
int CUSTATEVEC_VER_MAJOR
int CUSTATEVEC_VER_MINOR
int CUSTATEVEC_VER_PATCH
int CUSTATEVEC_VERSION
Loading

0 comments on commit 50e40da

Please sign in to comment.