Skip to content

Commit

Permalink
Merge branch 'experimental/python' into new-remote-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khalatepradnya authored Feb 9, 2024
2 parents db6d065 + 8f2fcbe commit 4b26909
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ To build the CUDA Quantum Python API from source using pip, run the following co
git clone https://github.com/NVIDIA/cuda-quantum.git
cd cuda-quantum && bash scripts/install_prerequisites.sh
pip install .
pip install . --user
For more information about building the entire C++ and Python API from source, we refer to the `CUDA Quantum GitHub repository`_.

Expand Down
25 changes: 13 additions & 12 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ include(AddMLIRPython)
# If this is better addressed after updating to a newer LLVM version, track as an issue on GitHub.
add_compile_options(-Wno-ambiguous-reversed-operator)

# Specifies that all MLIR packages are co-located under the `mlir_cudaq`
# Specifies that all MLIR packages are co-located under the cudaq
# top level package (the API has been embedded in a relocatable way).
# TODO: Add an upstream cmake param for this vs having a global here.
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir_cudaq.")
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=cudaq.mlir.")

if (CMAKE_COMPILER_IS_GNUCXX)
# Deals with warnings in gcc12 - may not be needed for gcc 13.
Expand All @@ -41,15 +40,15 @@ declare_mlir_python_sources(CUDAQuantumPythonSources)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CUDAQuantumPythonSources
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_cudaq"
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cudaq/mlir"
TD_FILE dialects/QuakeOps.td
SOURCES
dialects/quake.py
DIALECT_NAME quake)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CUDAQuantumPythonSources
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_cudaq"
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cudaq/mlir"
TD_FILE dialects/CCOps.td
SOURCES
dialects/cc.py
Expand Down Expand Up @@ -112,8 +111,8 @@ target_link_libraries(CUDAQuantumPythonSources.Extension INTERFACE

add_mlir_python_common_capi_library(CUDAQuantumPythonCAPI
INSTALL_COMPONENT CUDAQuantumPythonModules
INSTALL_DESTINATION mlir_cudaq/_mlir_libs
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python/mlir_cudaq/_mlir_libs"
INSTALL_DESTINATION cudaq/mlir/_mlir_libs
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python/cudaq/mlir/_mlir_libs"
RELATIVE_INSTALL_ROOT "../.."
DECLARED_SOURCES
CUDAQuantumPythonSources
Expand All @@ -128,8 +127,8 @@ add_mlir_python_common_capi_library(CUDAQuantumPythonCAPI
################################################################################

add_mlir_python_modules(CUDAQuantumPythonModules
ROOT_PREFIX "${MLIR_BINARY_DIR}/python/mlir_cudaq"
INSTALL_PREFIX "mlir_cudaq"
ROOT_PREFIX "${MLIR_BINARY_DIR}/python/cudaq/mlir"
INSTALL_PREFIX "cudaq/mlir"
DECLARED_SOURCES
CUDAQuantumPythonSources
# TODO: Remove this in favor of showing fine grained registration once
Expand All @@ -142,23 +141,25 @@ add_mlir_python_modules(CUDAQuantumPythonModules

file (COPY cudaq DESTINATION ${CMAKE_BINARY_DIR}/python/)

## The Python bindings module for Quake dialect depends on CUDAQ libraires
## The Python bindings module for Quake dialect depends on CUDAQ libraries
## which it can't locate since they are in "../../lib" and the 'rpath' is set
## to '$ORIGIN' by default.
set(_origin_prefix "\$ORIGIN")
if(APPLE)
set(_origin_prefix "@loader_path")
endif()
set_property(TARGET CUDAQuantumPythonModules.extension._quakeDialects.dso
APPEND PROPERTY INSTALL_RPATH "${_origin_prefix}:${_origin_prefix}/../../lib/")

add_subdirectory(runtime/cudaq/distributed)
add_subdirectory(runtime/cudaq/domains/plugins)

if (NOT SKBUILD)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN/../../lib:$ORIGIN/../../lib/plugins")
set_property(TARGET CUDAQuantumPythonModules.extension._quakeDialects.dso
APPEND PROPERTY INSTALL_RPATH "${_origin_prefix}/../../../lib:${_origin_prefix}/../../../lib/plugins")
else()
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN/../cuda_quantum.libs")
set_property(TARGET CUDAQuantumPythonModules.extension._quakeDialects.dso
APPEND PROPERTY INSTALL_RPATH "${_origin_prefix}/../../../lib:${_origin_prefix}/../../../cuda_quantum.libs")
endif()

if (NOT SKBUILD)
Expand Down
2 changes: 1 addition & 1 deletion python/cudaq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .runtime.sample import sample
from .runtime.observe import observe
from .runtime.state import get_state
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from .mlir._mlir_libs._quakeDialects import cudaq_runtime

global globalJIT

Expand Down
6 changes: 3 additions & 3 deletions python/cudaq/kernel/analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
Expand All @@ -8,8 +8,8 @@

import ast, inspect, importlib
from .utils import globalAstRegistry, globalKernelRegistry, mlirTypeFromAnnotation
from mlir_cudaq.dialects import cc
from mlir_cudaq.ir import *
from ..mlir.dialects import cc
from ..mlir.ir import *


class MidCircuitMeasurementAnalyzer(ast.NodeVisitor):
Expand Down
12 changes: 6 additions & 6 deletions python/cudaq/kernel/ast_bridge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
Expand All @@ -13,11 +13,11 @@
import numpy as np
from .analysis import FindDepKernelsVisitor
from .utils import globalAstRegistry, globalKernelRegistry, nvqppPrefix, mlirTypeFromAnnotation
from mlir_cudaq.ir import *
from mlir_cudaq.passmanager import *
from mlir_cudaq.dialects import quake, cc
from mlir_cudaq.dialects import builtin, func, arith, math, complex
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime, load_intrinsic
from ..mlir.ir import *
from ..mlir.passmanager import *
from ..mlir.dialects import quake, cc
from ..mlir.dialects import builtin, func, arith, math, complex
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime, load_intrinsic

# This file implements the CUDA Quantum Python AST to MLIR conversion.
# It provides a `PyASTBridge` class that implements the `ast.NodeVisitor` type
Expand Down
12 changes: 6 additions & 6 deletions python/cudaq/kernel/kernel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from .common.givens import givens_builder
from .common.fermionic_swap import fermionic_swap_builder

from mlir_cudaq.ir import *
from mlir_cudaq.passmanager import *
from mlir_cudaq.execution_engine import *
from mlir_cudaq.dialects import quake, cc
from mlir_cudaq.dialects import builtin, func, arith
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir.ir import *
from ..mlir.passmanager import *
from ..mlir.execution_engine import *
from ..mlir.dialects import quake, cc
from ..mlir.dialects import builtin, func, arith
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime

qvector = cudaq_runtime.qvector

Expand Down
10 changes: 5 additions & 5 deletions python/cudaq/kernel/kernel_decorator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
Expand All @@ -9,14 +9,14 @@
import importlib
import inspect
from typing import Callable
from mlir_cudaq.ir import *
from mlir_cudaq.passmanager import *
from mlir_cudaq.dialects import quake, cc
from ..mlir.ir import *
from ..mlir.passmanager import *
from ..mlir.dialects import quake, cc
from .ast_bridge import compile_to_mlir
from .utils import mlirTypeFromPyType, nvqppPrefix, mlirTypeToPyType
from .qubit_qis import h, x, y, z, s, t, rx, ry, rz, r1, swap, exp_pauli, mx, my, mz, adjoint, control, compute_action
from .analysis import MidCircuitMeasurementAnalyzer, RewriteMeasures
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime

# This file implements the decorator mechanism needed to
# JIT compile CUDA Quantum kernels. It exposes the cudaq.kernel()
Expand Down
12 changes: 6 additions & 6 deletions python/cudaq/kernel/quake_value.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
Expand All @@ -13,11 +13,11 @@
import numpy as np
import ctypes

from mlir_cudaq.ir import *
from mlir_cudaq.passmanager import *
from mlir_cudaq.dialects import quake, cc
from mlir_cudaq.dialects import builtin, func, arith
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir.ir import *
from ..mlir.passmanager import *
from ..mlir.dialects import quake, cc
from ..mlir.dialects import builtin, func, arith
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from .utils import mlirTypeFromPyType

qvector = cudaq_runtime.qvector
Expand Down
4 changes: 2 additions & 2 deletions python/cudaq/kernel/qubit_qis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
Expand All @@ -13,7 +13,7 @@
from abc import abstractmethod, ABCMeta
import inspect
import numpy as np
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from typing import Callable

qvector = cudaq_runtime.qvector
Expand Down
10 changes: 5 additions & 5 deletions python/cudaq/kernel/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from mlir_cudaq.dialects import quake, cc
from mlir_cudaq.ir import *
from mlir_cudaq.passmanager import *
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir.dialects import quake, cc
from ..mlir.ir import *
from ..mlir.passmanager import *
import numpy as np
from typing import Callable
import ast
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions python/cudaq/runtime/observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from ..kernel.kernel_builder import PyKernel
from .utils import __isBroadcast, __createArgumentSet
from mlir_cudaq.dialects import quake, cc
from ..mlir.dialects import quake, cc


def __broadcastObserve(kernel, spin_operator, *args, shots_count=0):
Expand Down
4 changes: 2 additions & 2 deletions python/cudaq/runtime/sample.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from .utils import __isBroadcast, __createArgumentSet


Expand Down
4 changes: 2 additions & 2 deletions python/cudaq/runtime/state.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime


def get_state(kernel, *args):
Expand Down
6 changes: 3 additions & 3 deletions python/cudaq/runtime/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
from mlir_cudaq._mlir_libs._quakeDialects import cudaq_runtime
from ..mlir._mlir_libs._quakeDialects import cudaq_runtime
from ..kernel.kernel_builder import PyKernel
from ..kernel.kernel_decorator import PyKernelDecorator
from mlir_cudaq.dialects import quake, cc
from ..mlir.dialects import quake, cc

import numpy as np

Expand Down
6 changes: 3 additions & 3 deletions python/tests/mlir/bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

# RUN: PYTHONPATH=../../ python3 %s | FileCheck %s

from mlir_cudaq.ir import *
from mlir_cudaq.dialects import quake
from mlir_cudaq.dialects import builtin, func, arith
from ..mlir.ir import *
from ..mlir.dialects import quake
from ..mlir.dialects import builtin, func, arith

with Context() as ctx:
quake.register_dialect()
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_cudaq.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
Expand Down

0 comments on commit 4b26909

Please sign in to comment.