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

First pass of support for C++ operators #2511

Open
wants to merge 317 commits into
base: experimental/operators
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
317 commits
Select commit Hold shift + click to select a range
9d48f3b
more clean up
bettinaheim Jan 29, 2025
2a7fd34
more clean up
bettinaheim Jan 29, 2025
bf691ca
finished cleanup of arithmetics
bettinaheim Jan 29, 2025
91d0e44
picking up Anthony's changes
bettinaheim Jan 30, 2025
619b266
just a quick renaming
bettinaheim Jan 30, 2025
d12f9cb
minor thing
bettinaheim Jan 30, 2025
5ce0c07
minor thing
bettinaheim Jan 30, 2025
0454209
minor things
bettinaheim Jan 31, 2025
93525b3
enabling a whole bunch of additional tests
bettinaheim Jan 31, 2025
15634ff
some more product op fixes
bettinaheim Feb 3, 2025
1336ada
just some test fixes
bettinaheim Feb 3, 2025
f4ea5b5
fixing matrix reordering issues
bettinaheim Feb 3, 2025
1cd4ffd
enabling the rest of the tests
bettinaheim Feb 3, 2025
f7a9d1b
Adding template parameter HandlerTy for operator_sum and formatting
sacpis Feb 4, 2025
c0ffcc7
Fixing Rydberg with template HandlerTy
sacpis Feb 4, 2025
8d67f30
Fixing with template typename
sacpis Feb 4, 2025
83f7137
Fixing HandlerTy tenplate by setting it to a value
sacpis Feb 4, 2025
193d636
Fixing unittests
sacpis Feb 4, 2025
e4e4699
Adding missing functions in helpers and updating initialize_operator_…
sacpis Feb 4, 2025
cc62bac
fixing helpers.h path
sacpis Feb 5, 2025
1e46c24
Adding equality comparision operation for matrix_2
sacpis Feb 5, 2025
ef3530a
Fixing the helpers.h path
sacpis Feb 5, 2025
b75d4a0
Adding HandlerTy
sacpis Feb 5, 2025
5dc3c9e
Disabling unneeded (for now) variables
sacpis Feb 5, 2025
68188c7
Adding cudaq::matrix_operator as a handler
sacpis Feb 6, 2025
71b87c2
Disabling template method
sacpis Feb 6, 2025
eb7fdc5
Fixing template definition in the header and instatiating it in teh c…
sacpis Feb 6, 2025
37a0ee3
Enabling tests
sacpis Feb 6, 2025
02d4362
Fixing Rydberg and renaming fixture in test_cudm_helpers
sacpis Feb 6, 2025
34b40be
* Enabling dynamic_cast for scalar operator
sacpis Feb 6, 2025
bbd7434
Minor cmake restructure
1tnguyen Feb 6, 2025
bd67453
Adding cudm_op_conversion interface
sacpis Feb 6, 2025
a086a33
Fixing the return type of _wrap_callback_tensor
sacpis Feb 6, 2025
8883ea7
Updating cudm_op_conversion interface to accommodate wrap callback an…
sacpis Feb 6, 2025
4b20e97
Adding cudm_op_conversion implementation, exposing get_generator for …
sacpis Feb 7, 2025
5e9c058
Fix segfault and add an end-to-end stepper check
1tnguyen Feb 7, 2025
bc43e40
Fix RK 1st order and add a test
1tnguyen Feb 7, 2025
3d8b598
Adding unittests for cudm_op_conversion
sacpis Feb 7, 2025
90972a6
Adding operator* method
sacpis Feb 7, 2025
04b85b0
Removing norm method from state
sacpis Feb 7, 2025
18f6072
Fixing midpoint integration
sacpis Feb 7, 2025
3c22ad5
Setting the accumulation for 4 states
sacpis Feb 7, 2025
d279c07
Disabling RK4 for now
sacpis Feb 8, 2025
d5eb3fb
* Adding mode_action_duality
sacpis Feb 8, 2025
29ab744
Fixing AddComplexScalars unittest
sacpis Feb 9, 2025
0c83b33
Fixing AddScalarAndOperator unittest
sacpis Feb 9, 2025
635cd0e
* Changing return type from double to std::complex<double>
sacpis Feb 9, 2025
1e94961
Fixing RK4
sacpis Feb 9, 2025
23bfb2b
Add expectation
1tnguyen Feb 10, 2025
526e4b2
Using cudensitymatStateComputeScaling for multiplication of state wit…
sacpis Feb 10, 2025
2cb8adb
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 10, 2025
962f130
Merge in dynamics work and squash commit history (#12)
anthony-santana Jan 9, 2025
1821361
Cleaning up docs preview for PR #12.
cuda-quantum-bot Jan 9, 2025
3ecd247
fixing spellings
sacpis Jan 9, 2025
33925b7
Adding base_integrator and base_time_stepper
sacpis Jan 9, 2025
8aab215
adding base_operators interface
sacpis Jan 13, 2025
39cf6ab
keeping degrees to match the current implementation
sacpis Jan 13, 2025
599fb57
adding base integrator and time stepper
sacpis Jan 13, 2025
c89e9d9
* Adding base test cases for Runge-Kutta stepper and integrator
sacpis Jan 14, 2025
48d4b75
* Adding helpers functionlity
sacpis Jan 14, 2025
4e95258
Formatting
sacpis Jan 14, 2025
fb1ad13
Adding evolution API header
sacpis Jan 15, 2025
f07c55b
Formatting
sacpis Jan 15, 2025
9434238
Replacing Eigen::MatrixXcd with matrix_2
sacpis Jan 15, 2025
824b876
* Adding Rydberg hamiltonian operator
sacpis Jan 16, 2025
94f910e
Adding interface for cudm_helpers
sacpis Jan 16, 2025
d8a9903
Changing matrix to operator_sum
sacpis Jan 16, 2025
8170e32
cudm_helpers implementation
sacpis Jan 21, 2025
5aeb4d7
Formatting
sacpis Jan 21, 2025
664515d
* Adding macro for handling error
sacpis Jan 21, 2025
8058b27
Adding MACRO for error handling
sacpis Jan 22, 2025
e865f76
Fixing convert_to_cudensitymat_operator as per the cudensitymat APIs
sacpis Jan 22, 2025
5668907
Updating CMakeLists and unittests
sacpis Jan 22, 2025
5608fdd
* Adding vector of cudensitymatElementaryOperator_t to store and destroy
sacpis Jan 23, 2025
271558f
Refactoring the code
sacpis Jan 23, 2025
a4c104a
Fixing the matrix in the unittest and other code in compute_lindblad …
sacpis Jan 23, 2025
11c7b65
Adding cudm_state with unittests
sacpis Jan 25, 2025
40e52d9
Addign few more unit tests for cudm_state
sacpis Jan 25, 2025
4ea6415
Adding an enum with initial quantum state and initilize_state based o…
sacpis Jan 25, 2025
31709a4
Fixing spelling
sacpis Jan 26, 2025
dafc31a
* Renaming cudm_mat_state -> cudm_state
sacpis Jan 28, 2025
e51696a
Exposing state's rawData to be used in the stepper
sacpis Jan 28, 2025
8a0bd3a
Adding cudm_time_stepper with unittests
sacpis Jan 28, 2025
d2e0441
Refactoring time_stepper compute method to align with cuquantum workflow
sacpis Jan 30, 2025
67d658b
Exposing handle and adding operator overloading for + and *
sacpis Jan 31, 2025
5d74f17
Removing redundant constructor and updating tests for cudm_state
sacpis Jan 31, 2025
ef1d09d
Implementing compute function in cudm_time_stepper
sacpis Jan 31, 2025
6544bee
Adding test_mocks for unittests
sacpis Jan 31, 2025
847c383
Adding check for step_size=0 condition and few more unittests
sacpis Jan 31, 2025
a51a70c
Adding #pragma once so that header files are included only once durin…
sacpis Jan 31, 2025
ef24742
* Adding partial implementation of runge-kutta integrator
sacpis Jan 31, 2025
04b9d77
* Implementing move constructor and move assignment
sacpis Feb 1, 2025
6cb5db2
temp
sacpis Feb 2, 2025
aea580f
Using cudensitymatStateComputeAccumulation and cudensitymatStateCompu…
sacpis Feb 3, 2025
6cbdd28
Allocating k1, k2, k3, k4 inside the scope blocks
sacpis Feb 3, 2025
c35225b
Adding operator+= to do an accumulation instead of moving the state
sacpis Feb 3, 2025
24ea1a0
just some test renaming to make it easier to find
bettinaheim Jan 13, 2025
0d69aab
a bunch of templates to draft how dragging type information through t…
bettinaheim Jan 13, 2025
265e3b3
wip to use elementary_operator as matrix handler
bettinaheim Jan 14, 2025
46fe387
wip to use elementary_operator as matrix handler
bettinaheim Jan 14, 2025
9912357
kinded of more cleaned up but left-hand arithmethics need more thought
bettinaheim Jan 14, 2025
02fc125
constrain the templates
bettinaheim Jan 14, 2025
071b115
making the left hand arithmetics friends
bettinaheim Jan 14, 2025
c12d4c9
cleaned up assignments
bettinaheim Jan 15, 2025
6d3e4bf
fixing a some types
bettinaheim Jan 16, 2025
ccc5cc2
this builds, but needs to be cleaned up
bettinaheim Jan 16, 2025
1a909db
scalar ops tests
bettinaheim Jan 17, 2025
314d61f
to be deleted again - just some notes
bettinaheim Jan 23, 2025
b3e2edd
more memory experiments
bettinaheim Jan 24, 2025
86e1337
revised the data structures - all tests now pass again
bettinaheim Jan 24, 2025
6908d91
store one coefficient per product only
bettinaheim Jan 27, 2025
69a3412
getting rid of all elementary operator overloads
bettinaheim Jan 27, 2025
ced3e6a
clean up for scalars
bettinaheim Jan 28, 2025
b50ae07
some clean up of op sum
bettinaheim Jan 28, 2025
d8c1689
some clean up for products
bettinaheim Jan 28, 2025
5c932b1
no type constraints for HandlerTy
bettinaheim Jan 29, 2025
9f102e9
left hand arithmetics cleanup
bettinaheim Jan 29, 2025
326b607
more clean up
bettinaheim Jan 29, 2025
42908b0
more clean up
bettinaheim Jan 29, 2025
666734d
more clean up
bettinaheim Jan 29, 2025
53eed45
finished cleanup of arithmetics
bettinaheim Jan 29, 2025
97198fc
picking up Anthony's changes
bettinaheim Jan 30, 2025
759ac0b
just a quick renaming
bettinaheim Jan 30, 2025
d0b0d26
minor thing
bettinaheim Jan 30, 2025
144ed26
minor thing
bettinaheim Jan 30, 2025
aa98969
minor things
bettinaheim Jan 31, 2025
9591195
enabling a whole bunch of additional tests
bettinaheim Jan 31, 2025
28b748f
some more product op fixes
bettinaheim Feb 3, 2025
b118f81
just some test fixes
bettinaheim Feb 3, 2025
b350295
fixing matrix reordering issues
bettinaheim Feb 3, 2025
8d844c1
enabling the rest of the tests
bettinaheim Feb 3, 2025
a4504ad
Adding template parameter HandlerTy for operator_sum and formatting
sacpis Feb 4, 2025
299cb28
Fixing Rydberg with template HandlerTy
sacpis Feb 4, 2025
4edcc73
Fixing with template typename
sacpis Feb 4, 2025
d3decea
Fixing HandlerTy tenplate by setting it to a value
sacpis Feb 4, 2025
cf37744
Fixing unittests
sacpis Feb 4, 2025
7d3a8ff
Adding missing functions in helpers and updating initialize_operator_…
sacpis Feb 4, 2025
a95d141
fixing helpers.h path
sacpis Feb 5, 2025
a4f94fb
Adding equality comparision operation for matrix_2
sacpis Feb 5, 2025
27dd340
Fixing the helpers.h path
sacpis Feb 5, 2025
4eca1b0
Adding HandlerTy
sacpis Feb 5, 2025
e0709e2
Disabling unneeded (for now) variables
sacpis Feb 5, 2025
2150ed2
Adding cudaq::matrix_operator as a handler
sacpis Feb 6, 2025
d6ef90b
Disabling template method
sacpis Feb 6, 2025
f244d9d
Fixing template definition in the header and instatiating it in teh c…
sacpis Feb 6, 2025
6c09737
Enabling tests
sacpis Feb 6, 2025
1881519
Fixing Rydberg and renaming fixture in test_cudm_helpers
sacpis Feb 6, 2025
d42e173
* Enabling dynamic_cast for scalar operator
sacpis Feb 6, 2025
7da22de
Minor cmake restructure
1tnguyen Feb 6, 2025
0a0b435
Adding cudm_op_conversion interface
sacpis Feb 6, 2025
281079c
Fixing the return type of _wrap_callback_tensor
sacpis Feb 6, 2025
700fc35
Updating cudm_op_conversion interface to accommodate wrap callback an…
sacpis Feb 6, 2025
fc7d038
Adding cudm_op_conversion implementation, exposing get_generator for …
sacpis Feb 7, 2025
86292c7
Fix segfault and add an end-to-end stepper check
1tnguyen Feb 7, 2025
2833124
Fix RK 1st order and add a test
1tnguyen Feb 7, 2025
4f33f64
Adding unittests for cudm_op_conversion
sacpis Feb 7, 2025
ea79f4c
Adding operator* method
sacpis Feb 7, 2025
dfbf83f
Removing norm method from state
sacpis Feb 7, 2025
f2ec850
Fixing midpoint integration
sacpis Feb 7, 2025
bb0baff
Setting the accumulation for 4 states
sacpis Feb 7, 2025
1c798e1
Disabling RK4 for now
sacpis Feb 8, 2025
9911353
* Adding mode_action_duality
sacpis Feb 8, 2025
eb48e97
Fixing AddComplexScalars unittest
sacpis Feb 9, 2025
4a70b23
Fixing AddScalarAndOperator unittest
sacpis Feb 9, 2025
0c2a4b5
* Changing return type from double to std::complex<double>
sacpis Feb 9, 2025
a67cec9
Fixing RK4
sacpis Feb 9, 2025
c67d19c
Using cudensitymatStateComputeScaling for multiplication of state wit…
sacpis Feb 10, 2025
573952b
Add expectation
1tnguyen Feb 10, 2025
b857150
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 11, 2025
7c64f06
Moving wrapper callbacks into cudm_helpers.cpp and disabling cudm_op_…
sacpis Feb 11, 2025
c503e7f
Adding tests for callback functions
sacpis Feb 11, 2025
0c8607b
[WIP] evolve single impl
1tnguyen Feb 11, 2025
16b69c1
* WIP fix for compute lindblad
sacpis Feb 11, 2025
f3bbf4b
Fix issue with append_elementary_operator_to_term
1tnguyen Feb 11, 2025
4839077
* Moving the tensor callbck wrapper in create_elementary_operator
sacpis Feb 11, 2025
7a2c7e7
replacing tensor callback parameter
sacpis Feb 11, 2025
2c74fa2
End-end evolve test
1tnguyen Feb 12, 2025
3e81144
Fixing lindblad operator
sacpis Feb 12, 2025
47bfb80
reverting accidental change to the logic handling already existing ma…
sacpis Feb 12, 2025
1e1b44e
Add composite system test and fix an issue with create a product term…
1tnguyen Feb 12, 2025
c134c57
Updating compute_lindblad_op with the updated append_elementary_opera…
sacpis Feb 12, 2025
1e693dc
Code restructure: separate cudm-dependency into nvqir target; no oper…
1tnguyen Feb 13, 2025
3b46cc8
Fix RK unit test
1tnguyen Feb 13, 2025
9cf261b
Adding TimeSteppingWithLindblad unitest to test compute_lindblad_oper…
sacpis Feb 13, 2025
9538ec2
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 13, 2025
ed5da79
completing tests, including for custom matrices
bettinaheim Feb 4, 2025
f145e3c
minor clean up
bettinaheim Feb 4, 2025
d308886
general clean up
bettinaheim Feb 4, 2025
138b2e9
clean up (moving some files)
bettinaheim Feb 5, 2025
2669d95
prep for adding different handlers
bettinaheim Feb 5, 2025
5a85e9f
trivial spin ops to set up tests before digging into perf optimizations
bettinaheim Feb 5, 2025
59386f3
some more tests, and making dimensions not required for evaluation if…
bettinaheim Feb 5, 2025
7a1aefe
more spin ops tests
bettinaheim Feb 6, 2025
c277d11
commit before removing inheritance
bettinaheim Feb 7, 2025
aa86a87
removing the inheritance from operator sum
bettinaheim Feb 7, 2025
8767426
some more clean up
bettinaheim Feb 7, 2025
3aa6283
implementing remaining conversions
bettinaheim Feb 10, 2025
1377a2f
finished conversion tests
bettinaheim Feb 10, 2025
261f744
gathering some perf numbers before optimization
bettinaheim Feb 10, 2025
705a650
always link the operator lib
bettinaheim Feb 10, 2025
b422030
undoing accidentally committed change
bettinaheim Feb 10, 2025
e411cb7
product optimizations
bettinaheim Feb 10, 2025
de49502
first version with perf improvements
bettinaheim Feb 13, 2025
a70b22c
perf version 2 with map
bettinaheim Feb 13, 2025
fcdb4c8
Fix linblad test and fix leak
1tnguyen Feb 14, 2025
44341e0
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 14, 2025
5d6e73e
Add full density matrix evolve and reduce test time
1tnguyen Feb 14, 2025
6769eb6
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 14, 2025
0d31c8b
Support static collapse op and add a test
1tnguyen Feb 14, 2025
2178b0e
Merge branch 'dynamics_cpp_operators' of https://github.com/sacpis/cu…
sacpis Feb 14, 2025
eb5688b
* Adding conversion mechanism (to operator_sum<product_operator>) after
sacpis Feb 14, 2025
f2ba966
changes to the test script
bettinaheim Feb 13, 2025
b5ada26
checking in v2 perf numbers for comparison
bettinaheim Feb 14, 2025
79a9b15
Bringing in more commits from Bettina's branch
bettinaheim Feb 14, 2025
ae4ae7c
Hook public API
1tnguyen Feb 15, 2025
4bd04be
Port cudm_state under cudaq::SimulationState type
1tnguyen Feb 17, 2025
69118b5
More cleanup: only use cudaq::state at the API surface
1tnguyen Feb 17, 2025
9fdf186
More cleanup: remove the type alias
1tnguyen Feb 17, 2025
6f03515
Add handle to sim class
1tnguyen Feb 17, 2025
d1ddf76
Some fixes for _wrap_callback and add TODO
1tnguyen Feb 17, 2025
737c667
commit before switching branches
bettinaheim Feb 14, 2025
b682430
third and final version with a decent performance across the board
bettinaheim Feb 17, 2025
a3ad658
adding missing rvalue overloads
bettinaheim Feb 17, 2025
8ee54f2
Fixing Scalar callback using Python callback from cudensitymat and fo…
sacpis Feb 18, 2025
aa8d3f0
Removing mutex
sacpis Feb 18, 2025
272f436
Passing param names to scalar callback
1tnguyen Feb 19, 2025
0521183
integrator + schedule in the loop to resolve parameter values
1tnguyen Feb 19, 2025
1a652bf
Adding tensor callback with the unittest
sacpis Feb 19, 2025
0784b45
Support state vec -> density matrix conversion if collapse ops are pr…
1tnguyen Feb 19, 2025
1b2eecc
Removing batch_size from tensor_callback and formatting
sacpis Feb 19, 2025
d684a15
Fixing unittest and string formatting
sacpis Feb 19, 2025
fb0e146
Fixing checkScalarTd
sacpis Feb 19, 2025
c1a3b2c
Fixing CheckScalarCallback by enabling memcpy to copy the flattened m…
sacpis Feb 19, 2025
7efb20c
Adding cavity_qed example for C++ dynamics
sacpis Feb 20, 2025
d612030
Adding cross_resonance example for C++ dynamics
sacpis Feb 20, 2025
677f460
Hook callback support to Linblad conversion
1tnguyen Feb 20, 2025
0c9a219
[Code Cleanup] Create a global context to track the handle + scratch …
1tnguyen Feb 20, 2025
44ea577
Merge remote-tracking branch 'origin/dynamics_cpp_operators' into dyn…
sacpis Feb 20, 2025
9a4cc40
getting updates from main
bettinaheim Feb 18, 2025
4b47201
removing some files that should not be part of this PR
bettinaheim Feb 18, 2025
3695e7b
forgot one file
bettinaheim Feb 18, 2025
309b8dd
forgot one file
bettinaheim Feb 18, 2025
940cdc4
[Cleanup] Tidy up the code
1tnguyen Feb 20, 2025
788ab73
Merge branch 'dynamics_cpp_operators' of github.com:sacpis/cuda-quant…
1tnguyen Feb 20, 2025
3909ef2
just some clean up
bettinaheim Feb 18, 2025
4307a89
just some clean up
bettinaheim Feb 18, 2025
b0f60ce
full in-place multiplication for bosons
bettinaheim Feb 19, 2025
c582721
additional boson tests and clean up
bettinaheim Feb 19, 2025
b52b3f4
Merging Bettina's changes and formatting
sacpis Feb 20, 2025
97f229b
Fix the order of elemetary op application in a product term: we write…
1tnguyen Feb 20, 2025
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
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@
"C_Cpp.inlayHints.referenceOperator.enabled": false,
"C_Cpp.doxygen.generateOnType": false,
"C_Cpp.default.cStandard": "c17",
"C_Cpp.default.cppStandard": "c++20",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/debug/compile_commands.json",
"C_Cpp.default.includePath": [
"${workspaceFolder}/**",
"${CUDAQ_INSTALL_PREFIX}/**",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ jobs:
fi; \
done`

rm -rf examples applications targets && mv github-repo/docs/sphinx/examples examples && mv github-repo/docs/sphinx/applications applications && mv github-repo/docs/sphinx/targets targets
rm -rf examples applications targets snippets && mv github-repo/docs/sphinx/examples examples && mv github-repo/docs/sphinx/applications applications && mv github-repo/docs/sphinx/targets targets && mv github-repo/docs/sphinx/snippets/python snippets
mv github-repo/docs/notebook_validation.py .
GITHUB_STEP_SUMMARY=$GITHUB_STEP_SUMMARY \
bash github-repo/scripts/validate_container.sh $backends_to_test | tee /tmp/validation.out
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ endif()
if(NOT CUTENSORNET_ROOT)
SET(CUTENSORNET_ROOT "$ENV{CUQUANTUM_INSTALL_PREFIX}")
endif()
if(NOT CUDENSITYMAT_ROOT)
SET(CUDENSITYMAT_ROOT "$ENV{CUQUANTUM_INSTALL_PREFIX}")
endif()
if(NOT CUTENSOR_ROOT)
SET(CUTENSOR_ROOT "$ENV{CUTENSOR_INSTALL_PREFIX}")
endif()
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(CONFIG_FILES
CUDAQEmDefaultConfig.cmake
CUDAQNloptConfig.cmake
CUDAQSpinConfig.cmake
CUDAQOperatorConfig.cmake
CUDAQConfig.cmake
CUDAQEnsmallenConfig.cmake
CUDAQPlatformDefaultConfig.cmake
Expand Down
3 changes: 3 additions & 0 deletions cmake/Modules/CUDAQConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ list(APPEND CMAKE_MODULE_PATH "${CUDAQ_CMAKE_DIR}")
set (CUDAQSpin_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQSpin REQUIRED)

set (CUDAQOperator_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQOperator REQUIRED)

set (CUDAQCommon_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQCommon REQUIRED)

Expand Down
3 changes: 3 additions & 0 deletions cmake/Modules/CUDAQEmDefaultConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ get_filename_component(CUDAQ_EM_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set (CUDAQSpin_DIR "${CUDAQ_EM_CMAKE_DIR}")
find_dependency(CUDAQSpin REQUIRED)

set (CUDAQOperator_DIR "${CUDAQ_EM_CMAKE_DIR}")
find_dependency(CUDAQOperator REQUIRED)

set (CUDAQCommon_DIR "${CUDAQ_EM_CMAKE_DIR}")
find_dependency(CUDAQCommon REQUIRED)

Expand Down
13 changes: 13 additions & 0 deletions cmake/Modules/CUDAQOperatorConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ============================================================================ #
# Copyright (c) 2022 - 2025 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. #
# ============================================================================ #

get_filename_component(CUDAQ_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

if(NOT TARGET cudaq::cudaq-operator)
include("${CUDAQ_CMAKE_DIR}/CUDAQOperatorTargets.cmake")
endif()
3 changes: 3 additions & 0 deletions cmake/Modules/CUDAQPlatformDefaultConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ get_filename_component(CUDAQ_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set (CUDAQEmDefault_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQEmDefault REQUIRED)

set (CUDAQOperator_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQOperator REQUIRED)

set (CUDAQSpin_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQSpin REQUIRED)

Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/NVQIRConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include(CMakeFindDependencyMacro)
get_filename_component(PARENT_DIRECTORY ${NVQIR_CMAKE_DIR} DIRECTORY)

find_dependency(CUDAQSpin REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
find_dependency(CUDAQOperator REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
find_dependency(CUDAQCommon REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
find_package(fmt QUIET)
if (NOT fmt_FOUND)
Expand Down
4 changes: 0 additions & 4 deletions docker/build/devdeps.ext.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,3 @@ ENV CUTENSOR_INSTALL_PREFIX="$CUTENSOR_INSTALL_PREFIX"
ENV CUTENSOR_ROOT="$CUTENSOR_INSTALL_PREFIX"
ENV LD_LIBRARY_PATH="$CUTENSOR_INSTALL_PREFIX/lib:$LD_LIBRARY_PATH"
ENV CPATH="$CUTENSOR_INSTALL_PREFIX/include:$CPATH"

# Active MPI support for the cuTensorNet library
RUN cd "$CUQUANTUM_INSTALL_PREFIX/distributed_interfaces/" && source activate_mpi_cutn.sh
ENV CUTENSORNET_COMM_LIB="$CUQUANTUM_INSTALL_PREFIX/distributed_interfaces/libcutensornet_distributed_interface_mpi.so"
142 changes: 142 additions & 0 deletions docs/sphinx/examples/cpp/dynamics/cavity_qed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*******************************************************************************
* Copyright (c) 2022 - 2025 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. *
******************************************************************************/

#include "cudaq/algorithms/evolve.h"
#include "cudaq/dynamics_integrators.h"
#include "cudaq/evolution.h"
#include "cudaq/operators.h"
#include "cudaq/schedule.h"
#include "matplotlibcpp.h"
#include <cudaq.h>

namespace plt = matplotlibcpp;

int main() {

cudaq::set_target_backend("dynamics");

// System dimensions:
// subsystem 0 (atom) has 2 levels
// subsystem 1 (cavity) has 10 levels
std::map<int, int> dimensions{{0, 2}, {1, 10}};

// For the cavity subsystem 1
auto a = cudaq::matrix_operator::annihilate(1);
auto a_dag = cudaq::matrix_operator::create(1);

// For the atom subsystem 0
auto sm = cudaq::matrix_operator::annihilate(0);
auto sm_dag = cudaq::matrix_operator::create(0);

cudaq::product_operator<cudaq::matrix_operator> atom_occ_op_t =
cudaq::matrix_operator::number(0);
cudaq::operator_sum<cudaq::matrix_operator> atom_occ_op(atom_occ_op_t);

cudaq::product_operator<cudaq::matrix_operator> cavity_occ_op_t =
cudaq::matrix_operator::number(1);
cudaq::operator_sum<cudaq::matrix_operator> cavity_occ_op(cavity_occ_op_t);

auto hamiltonian = 2 * M_PI * atom_occ_op + 2 * M_PI * cavity_occ_op +
2 * M_PI * 0.25 * (sm * a_dag + sm_dag * a);

// Build the initial state
// For the atom, the density matrix in the ground state
cudaq::matrix_2 qubit_state({1.0, 0.0}, {0.0, 0.0});

// For the cavity, 1 10x10 matrix with a single photon number state at |5>
cudaq::matrix_2 cavity_state = cudaq::matrix_2(10, 10);
cavity_state[{5, 5}] = 1.0;

// Compute the tensor (kronecker) product of the atom and cavity states
cudaq::matrix_2 rho = qubit_state.kronecker_inplace(cavity_state);

// Flatten the matrix
std::vector<std::complex<double>> flat_rho;
for (size_t j = 0; j < rho.get_columns(); ++j) {
for (size_t i = 0; i < rho.get_rows(); ++i) {
flat_rho.push_back(rho[{i, j}]);
}
}

cudaq::state_data rho_data = flat_rho;

// Create a CUDA quantum state from a density matrix
auto rho0 = cudaq::state::from_data(rho_data);

// Create time steps between 0 and 10
const int num_steps = 201;
const double t0 = 0.0, t1 = 10.0;
std::vector<double> steps(num_steps);
double dt = (t1 - t0) / (num_steps - 1);
for (int i = 0; i < num_steps; ++i) {
steps[i] = t0 + i * dt;
}

// Create a schedule for the time steps and a label for the time parameter
std::vector<std::string> labels = {"time"};
cudaq::Schedule schedule(steps, labels);

cudaq::runge_kutta integrator;
integrator.dt = 0.001;
integrator.order = 1;

// Evolve without collapse operators
cudaq::evolve_result evolve_result =
cudaq::evolve(hamiltonian, dimensions, schedule, rho0, integrator, {},
{hamiltonian}, true);

constexpr double decay_rate = 0.1;
auto collapse_operator = std::sqrt(decay_rate) * a;
// Evolve with collapse operators
cudaq::evolve_result evolve_result_decay =
cudaq::evolve(hamiltonian, dimensions, schedule, rho0, integrator,
{collapse_operator}, {hamiltonian}, true);

// Lambda to extract expectation values for a given observable index
auto get_expectation = [](int idx,
const auto &result) -> std::vector<double> {
std::vector<double> expectations;

auto all_exps = result.get_expectation_values().value();
for (const auto &exp_vals : all_exps) {
expectations.push_back((double)exp_vals[idx]);
}
return expectations;
};

auto ideal_result0 = get_expectation(0, evolve_result);
auto ideal_result1 = get_expectation(1, evolve_result);
auto decay_result0 = get_expectation(0, evolve_result_decay);
auto decay_result1 = get_expectation(1, evolve_result_decay);

// Plot the results
plt::figure_size(1000, 600);

// Subplot 1: No decay
plt::subplot(1, 2, 1);
plt::plot(steps, ideal_result0, {{"label", "Cavity Photon Number"}});
plt::plot(steps, ideal_result1, {{"label", "Atom Excitation Probability"}});
plt::xlabel("Time");
plt::ylabel("Expectation value");
plt::legend();
plt::title("No decay");

// Subplot 2: With decay
plt::subplot(1, 2, 2);
plt::plot(steps, decay_result0, {{"label", "Cavity Photon Number"}});
plt::plot(steps, decay_result1, {{"label", "Atom Excitation Probability"}});
plt::xlabel("Time");
plt::ylabel("Expectation value");
plt::legend();
plt::title("No decay");

plt::save("cavity_qed.png");

std::cout << "Simulation complete. Plot saved to cavity_qed.png" << std::endl;
return 0;
}
138 changes: 138 additions & 0 deletions docs/sphinx/examples/cpp/dynamics/cross_resonance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*******************************************************************************
* Copyright (c) 2022 - 2025 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. *
******************************************************************************/

#include "cudaq/algorithms/evolve.h"
#include "cudaq/dynamics_integrators.h"
#include "cudaq/evolution.h"
#include "cudaq/operators.h"
#include "cudaq/schedule.h"
#include "matplotlibcpp.h"
#include <cudaq.h>

namespace plt = matplotlibcpp;

int main() {

cudaq::set_target_backend("dynamics");

// Detuning between two qubits
double delta = 100 * 2 * M_PI;
// Static coupling between qubits
double J = 7 * 2 * M_PI;
// Spurious electromagnetic crosstalk
double m_12 = 0.2;
// Drive strength
double Omega = 20 * 2 * M_PI;

auto hamiltonian =
(delta / 2.0) * cudaq::spin_operator::z(0) +
J * (cudaq::spin_operator::minus(1) * cudaq::spin_operator::plus(0) +
cudaq::spin_operator::plus(1) * cudaq::spin_operator::minus(0)) +
Omega * cudaq::spin_operator::x(0) +
m_12 * Omega * cudaq::spin_operator::x(1);

std::map<int, int> dimensions{{0, 2}, {1, 2}};

// Build the initial state
cudaq::matrix_2 rho_mat({1.0, 0.0}, {0.0, 0.0});

// Flatten the matrix
std::vector<std::complex<double>> flat_rho;
for (size_t j = 0; j < rho_mat.get_columns(); ++j) {
for (size_t i = 0; i < rho_mat.get_rows(); ++i) {
flat_rho.push_back(rho_mat[{i, j}]);
}
}

cudaq::state_data rho_data = flat_rho;
auto rho0 = cudaq::state::from_data(rho_data);

// Two initial state vectors for the 2-qubit system (dimension 4)
// psi_00 corresponds to |00> and psi_10 corresponds to |10>
auto psi_00 = cudaq::state::from_data({1.0, 0.0, 0.0, 0.0});
auto psi_10 = cudaq::state::from_data({0.0, 0.0, 1.0, 0.0});

// Create a schedule of time steps
const int num_steps = 1001;
const double t0 = 0.0, t1 = 1.0;
std::vector<double> steps(num_steps);
double dt = (t1 - t0) / (num_steps - 1);
for (int i = 0; i < num_steps; ++i) {
steps[i] = t0 + i * dt;
}
std::vector<std::string> labels = {"time"};
cudaq::Schedule schedule(steps, labels);

cudaq::runge_kutta integrator;
integrator.dt = 0.001;
integrator.order = 1;

std::vector<cudaq::spin_operator> observables = {
cudaq::spin_operator::x(0), cudaq::spin_operator::y(0),
cudaq::spin_operator::z(0), cudaq::spin_operator::x(1),
cudaq::spin_operator::y(1), cudaq::spin_operator::z(1)};

// Evolution for initial state |00>
auto evolution_result_00 =
cudaq::evolve(hamiltonian, dimensions, schedule, psi_00, observables, {},
true, integrator);

// Evolution for initial state |10>
auto evolution_result_10 =
cudaq::evolve(hamiltonian, dimensions, schedule, psi_10, observables, {},
true, integrator);

auto get_result = [](int idx, const auto &result) -> std::vector<double> {
std::vector<double> expectations;
auto all_exps = result.get_expectation_values().value();
for (const auto &exp_vals : all_exps) {
expectations.push_back((double)exp_vals[idx]);
}
return expectations;
};

// For the two evolutions, extract the six observable trajectories.
auto result_00_0 = get_result(0, evolution_result_00);
auto result_00_1 = get_result(1, evolution_result_00);
auto result_00_2 = get_result(2, evolution_result_00);
auto result_00_3 = get_result(3, evolution_result_00);
auto result_00_4 = get_result(4, evolution_result_00);
auto result_00_5 = get_result(5, evolution_result_00);

auto result_10_0 = get_result(0, evolution_result_10);
auto result_10_1 = get_result(1, evolution_result_10);
auto result_10_2 = get_result(2, evolution_result_10);
auto result_10_3 = get_result(3, evolution_result_10);
auto result_10_4 = get_result(4, evolution_result_10);
auto result_10_5 = get_result(5, evolution_result_10);

// Plot the results
plt::figure_size(1000, 600);

// Subplot 1: Expectation value <Z> for qubit 1.
plt::subplot(1, 2, 1);
plt::plot(steps, result_00_5, {{"label", "$|\\psi_0\\rangle=|00\\rangle$"}});
plt::plot(steps, result_10_5, {{"label", "$|\\psi_0\\rangle=|10\\rangle$"}});
plt::xlabel("Time");
plt::ylabel("$\\langle Z_2 \\rangle$");
plt::legend();

// Subplot 2: Expectation value <Y> for qubit 1.
plt::subplot(1, 2, 2);
plt::plot(steps, result_00_4, {{"label", "$|\\psi_0\\rangle=|00\\rangle$"}});
plt::plot(steps, result_10_4, {{"label", "$|\\psi_0\\rangle=|10\\rangle$"}});
plt::xlabel("Time");
plt::ylabel("$\\langle Y_2 \\rangle$");
plt::legend();

plt::save("cross_resonance.png");

std::cout << "Simulation complete. Plot saved to cross_resonance.png"
<< std::endl;
return 0;
}
9 changes: 5 additions & 4 deletions docs/sphinx/using/backends/sims/tnsims.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ Use the following commands to enable distribution across multiple GPUs (adjust t
mpiexec -np 2 ./program.x

.. note::
MPI parallelization on the :code:`tensornet` backend requires CUDA-Q's MPI support.
Please refer to the instructions on how to :ref:`enable MPI parallelization <distributed-computing-with-mpi>` within CUDA-Q.
CUDA-Q containers are shipped with a pre-built MPI plugin; hence no additional setup is needed.

If the `CUTENSORNET_COMM_LIB` environment variable is not set, MPI parallelization on the :code:`tensornet` backend may fail.
If you are using a CUDA-Q container, this variable is pre-configured and no additional setup is needed. If you are customizing your installation or have built CUDA-Q from source, please follow the instructions for `activating the distributed interface <https://docs.nvidia.com/cuda/cuquantum/latest/getting-started/index.html#from-nvidia-devzone>`__ for the `cuTensorNet` library. This requires
:ref:`installing CUDA development dependencies <additional-cuda-tools>`, and setting the `CUTENSORNET_COMM_LIB`
environment variable to the newly built `libcutensornet_distributed_interface_mpi.so` library.
.. note::
If the `CUTENSORNET_COMM_LIB` environment variable is set following the activation procedure described in the `cuTensorNet documentation <https://docs.nvidia.com/cuda/cuquantum/latest/getting-started/index.html#from-nvidia-devzone>`__, the cuTensorNet MPI plugin will take precedence over the builtin support from CUDA-Q.

Specific aspects of the simulation can be configured by setting the following of environment variables:

Expand Down
Loading
Loading