Skip to content

Commit fe1396b

Browse files
authored
Operator classes (#2631)
This PR introduces general operator classes in C++. Existing spin ops are not yet replaced, and integration with dynamics will follow in a separate PR.
1 parent e669d62 commit fe1396b

Some content is hidden

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

49 files changed

+15000
-8
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
"C_Cpp.inlayHints.referenceOperator.enabled": false,
242242
"C_Cpp.doxygen.generateOnType": false,
243243
"C_Cpp.default.cStandard": "c17",
244-
"C_Cpp.default.cppStandard": "c++20",
244+
"C_Cpp.default.cppStandard": "c++17",
245245
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
246246
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
247247
"C_Cpp.default.includePath": [

.github/workflows/config/spelling_allowlist.txt

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ discoverable
193193
discretization
194194
discretize
195195
discretized
196+
eigenbasis
196197
eigensolver
197198
eigensolvers
198199
eigenstate
@@ -202,6 +203,7 @@ eigenvalues
202203
eigenvector
203204
eigenvectors
204205
endian
206+
endianness
205207
enqueue
206208
enqueues
207209
enqueuing

cmake/Modules/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(CONFIG_FILES
1111
CUDAQEmDefaultConfig.cmake
1212
CUDAQNloptConfig.cmake
1313
CUDAQSpinConfig.cmake
14+
CUDAQOperatorConfig.cmake
1415
CUDAQConfig.cmake
1516
CUDAQEnsmallenConfig.cmake
1617
CUDAQPlatformDefaultConfig.cmake

cmake/Modules/CUDAQConfig.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ list(APPEND CMAKE_MODULE_PATH "${CUDAQ_CMAKE_DIR}")
1414
set (CUDAQSpin_DIR "${CUDAQ_CMAKE_DIR}")
1515
find_dependency(CUDAQSpin REQUIRED)
1616

17+
set (CUDAQOperator_DIR "${CUDAQ_CMAKE_DIR}")
18+
find_dependency(CUDAQOperator REQUIRED)
19+
1720
set (CUDAQCommon_DIR "${CUDAQ_CMAKE_DIR}")
1821
find_dependency(CUDAQCommon REQUIRED)
1922

cmake/Modules/CUDAQEmDefaultConfig.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ get_filename_component(CUDAQ_EM_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
1111
set (CUDAQSpin_DIR "${CUDAQ_EM_CMAKE_DIR}")
1212
find_dependency(CUDAQSpin REQUIRED)
1313

14+
set (CUDAQOperator_DIR "${CUDAQ_EM_CMAKE_DIR}")
15+
find_dependency(CUDAQOperator REQUIRED)
16+
1417
set (CUDAQCommon_DIR "${CUDAQ_EM_CMAKE_DIR}")
1518
find_dependency(CUDAQCommon REQUIRED)
1619

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ============================================================================ #
2+
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. #
3+
# All rights reserved. #
4+
# #
5+
# This source code and the accompanying materials are made available under #
6+
# the terms of the Apache License 2.0 which accompanies this distribution. #
7+
# ============================================================================ #
8+
9+
get_filename_component(CUDAQ_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
10+
11+
if(NOT TARGET cudaq::cudaq-operator)
12+
include("${CUDAQ_CMAKE_DIR}/CUDAQOperatorTargets.cmake")
13+
endif()

cmake/Modules/CUDAQPlatformDefaultConfig.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ get_filename_component(CUDAQ_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
1111
set (CUDAQEmDefault_DIR "${CUDAQ_CMAKE_DIR}")
1212
find_dependency(CUDAQEmDefault REQUIRED)
1313

14+
set (CUDAQOperator_DIR "${CUDAQ_CMAKE_DIR}")
15+
find_dependency(CUDAQOperator REQUIRED)
16+
1417
set (CUDAQSpin_DIR "${CUDAQ_CMAKE_DIR}")
1518
find_dependency(CUDAQSpin REQUIRED)
1619

cmake/Modules/NVQIRConfig.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ include(CMakeFindDependencyMacro)
1212
get_filename_component(PARENT_DIRECTORY ${NVQIR_CMAKE_DIR} DIRECTORY)
1313

1414
find_dependency(CUDAQSpin REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
15+
find_dependency(CUDAQOperator REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
1516
find_dependency(CUDAQCommon REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
1617
find_package(fmt QUIET)
1718
if (NOT fmt_FOUND)

python/cudaq/operator/definitions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
# Operators as defined here (watch out of differences in convention):
19-
# https://www.dynamiqs.org/python_api/utils/operators/sigmay.html
19+
# https://www.dynamiqs.org/stable/python_api/utils/operators/create.html
2020
class operators:
2121

2222
class matrices:

runtime/cudaq/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (CUDA_FOUND)
4040
PRIVATE .)
4141

4242
target_link_libraries(${LIBRARY_NAME}
43-
PUBLIC dl cudaq-spin cudaq-common cudaq-nlopt cudaq-ensmallen
43+
PUBLIC dl cudaq-spin cudaq-operator cudaq-common cudaq-nlopt cudaq-ensmallen
4444
PRIVATE nvqir fmt::fmt-header-only CUDA::cudart_static)
4545

4646
target_compile_definitions(${LIBRARY_NAME} PRIVATE CUDAQ_HAS_CUDA)
@@ -52,7 +52,7 @@ else()
5252
PRIVATE .)
5353

5454
target_link_libraries(${LIBRARY_NAME}
55-
PUBLIC dl cudaq-spin cudaq-common cudaq-nlopt cudaq-ensmallen
55+
PUBLIC dl cudaq-spin cudaq-operator cudaq-common cudaq-nlopt cudaq-ensmallen
5656
PRIVATE nvqir fmt::fmt-header-only)
5757
endif()
5858

@@ -61,6 +61,7 @@ add_subdirectory(algorithms)
6161
add_subdirectory(platform)
6262
add_subdirectory(builder)
6363
add_subdirectory(domains)
64+
add_subdirectory(dynamics)
6465

6566
install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-targets DESTINATION lib)
6667

runtime/cudaq/dynamics/CMakeLists.txt

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# ============================================================================ #
2+
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. #
3+
# All rights reserved. #
4+
# #
5+
# This source code and the accompanying materials are made available under #
6+
# the terms of the Apache License 2.0 which accompanies this distribution. #
7+
# ============================================================================ #
8+
9+
set(LIBRARY_NAME cudaq-operator)
10+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ctad-maybe-unsupported")
11+
set(INTERFACE_POSITION_INDEPENDENT_CODE ON)
12+
13+
set(CUDAQ_OPS_SRC
14+
callback.cpp
15+
scalar_operators.cpp
16+
spin_operators.cpp
17+
boson_operators.cpp
18+
fermion_operators.cpp
19+
matrix_operators.cpp
20+
product_operators.cpp
21+
operator_sum.cpp
22+
handler.cpp
23+
schedule.cpp
24+
helpers.cpp
25+
)
26+
27+
add_library(${LIBRARY_NAME} SHARED ${CUDAQ_OPS_SRC})
28+
set_property(GLOBAL APPEND PROPERTY CUDAQ_RUNTIME_LIBS ${LIBRARY_NAME})
29+
target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_INSTANTIATE_TEMPLATES)
30+
31+
target_include_directories(${LIBRARY_NAME}
32+
PUBLIC
33+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/runtime>
34+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/tpls/eigen>
35+
$<INSTALL_INTERFACE:include>
36+
PRIVATE .)
37+
38+
set (OPERATOR_DEPENDENCIES "")
39+
list(APPEND OPERATOR_DEPENDENCIES fmt::fmt-header-only)
40+
add_openmp_configurations(${LIBRARY_NAME} OPERATOR_DEPENDENCIES)
41+
42+
target_link_libraries(${LIBRARY_NAME} PRIVATE ${OPERATOR_DEPENDENCIES})
43+
44+
install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-operator-targets DESTINATION lib)
45+
46+
install(EXPORT cudaq-operator-targets
47+
FILE CUDAQOperatorTargets.cmake
48+
NAMESPACE cudaq::
49+
DESTINATION lib/cmake/cudaq)

0 commit comments

Comments
 (0)