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

[WIP] Operators and Integration with cudensitymat #2407

Closed
wants to merge 248 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
248 commits
Select commit Hold shift + click to select a range
106f1e3
Merge in dynamics work and squash commit history (#12)
anthony-santana Jan 9, 2025
4e11669
Cleaning up docs preview for PR #12.
cuda-quantum-bot Jan 9, 2025
b2a6682
fixing spellings
sacpis Jan 9, 2025
42d0aeb
Adding base_integrator and base_time_stepper
sacpis Jan 9, 2025
baa1d10
adding base_operators interface
sacpis Jan 13, 2025
463afdf
keeping degrees to match the current implementation
sacpis Jan 13, 2025
b7a3bfa
adding base integrator and time stepper
sacpis Jan 13, 2025
6701ed8
* Adding base test cases for Runge-Kutta stepper and integrator
sacpis Jan 14, 2025
e0aa4fe
* Adding helpers functionlity
sacpis Jan 14, 2025
1fd530e
Formatting
sacpis Jan 14, 2025
18a69d1
Adding evolution API header
sacpis Jan 15, 2025
c074ffd
Formatting
sacpis Jan 15, 2025
3d51d6e
Replacing Eigen::MatrixXcd with matrix_2
sacpis Jan 15, 2025
abc447f
* Adding Rydberg hamiltonian operator
sacpis Jan 16, 2025
913d601
Adding interface for cudm_helpers
sacpis Jan 16, 2025
ea9e1d9
Changing matrix to operator_sum
sacpis Jan 16, 2025
efabd77
cudm_helpers implementation
sacpis Jan 21, 2025
10f69e1
Formatting
sacpis Jan 21, 2025
0259b90
* Adding macro for handling error
sacpis Jan 21, 2025
0415b0d
Adding MACRO for error handling
sacpis Jan 22, 2025
09252ca
Fixing convert_to_cudensitymat_operator as per the cudensitymat APIs
sacpis Jan 22, 2025
b06aef2
Updating CMakeLists and unittests
sacpis Jan 22, 2025
ba35c89
* Adding vector of cudensitymatElementaryOperator_t to store and destroy
sacpis Jan 23, 2025
6ce13c0
Refactoring the code
sacpis Jan 23, 2025
e150ee0
Fixing the matrix in the unittest and other code in compute_lindblad …
sacpis Jan 23, 2025
2b26974
Adding cudm_state with unittests
sacpis Jan 25, 2025
d1acad3
Addign few more unit tests for cudm_state
sacpis Jan 25, 2025
7ad8c82
Adding an enum with initial quantum state and initilize_state based o…
sacpis Jan 25, 2025
97c337d
Fixing spelling
sacpis Jan 26, 2025
83b2d63
* Renaming cudm_mat_state -> cudm_state
sacpis Jan 28, 2025
ad6e5eb
Exposing state's rawData to be used in the stepper
sacpis Jan 28, 2025
a5415fc
Adding cudm_time_stepper with unittests
sacpis Jan 28, 2025
dd5ebb0
Refactoring time_stepper compute method to align with cuquantum workflow
sacpis Jan 30, 2025
0973be4
Exposing handle and adding operator overloading for + and *
sacpis Jan 31, 2025
0abfabb
Removing redundant constructor and updating tests for cudm_state
sacpis Jan 31, 2025
c166ec3
Implementing compute function in cudm_time_stepper
sacpis Jan 31, 2025
b470e21
Adding test_mocks for unittests
sacpis Jan 31, 2025
783deac
Adding check for step_size=0 condition and few more unittests
sacpis Jan 31, 2025
8594a21
Adding #pragma once so that header files are included only once durin…
sacpis Jan 31, 2025
9975121
* Adding partial implementation of runge-kutta integrator
sacpis Jan 31, 2025
4315b52
* Implementing move constructor and move assignment
sacpis Feb 1, 2025
1355a4d
temp
sacpis Feb 2, 2025
154d05d
Using cudensitymatStateComputeAccumulation and cudensitymatStateCompu…
sacpis Feb 3, 2025
3ab4e76
Allocating k1, k2, k3, k4 inside the scope blocks
sacpis Feb 3, 2025
d7d2aae
Adding operator+= to do an accumulation instead of moving the state
sacpis Feb 3, 2025
0d243b8
just some test renaming to make it easier to find
bettinaheim Jan 13, 2025
93551f6
a bunch of templates to draft how dragging type information through t…
bettinaheim Jan 13, 2025
11df37b
wip to use elementary_operator as matrix handler
bettinaheim Jan 14, 2025
3511e7c
wip to use elementary_operator as matrix handler
bettinaheim Jan 14, 2025
68c07c8
kinded of more cleaned up but left-hand arithmethics need more thought
bettinaheim Jan 14, 2025
45f6926
constrain the templates
bettinaheim Jan 14, 2025
d663b02
making the left hand arithmetics friends
bettinaheim Jan 14, 2025
3dc2d50
cleaned up assignments
bettinaheim Jan 15, 2025
3d52d47
fixing a some types
bettinaheim Jan 16, 2025
6c04650
this builds, but needs to be cleaned up
bettinaheim Jan 16, 2025
0cb84a8
scalar ops tests
bettinaheim Jan 17, 2025
a5399d3
to be deleted again - just some notes
bettinaheim Jan 23, 2025
a637313
more memory experiments
bettinaheim Jan 24, 2025
0aa6e85
revised the data structures - all tests now pass again
bettinaheim Jan 24, 2025
8cb682e
store one coefficient per product only
bettinaheim Jan 27, 2025
ac469ff
getting rid of all elementary operator overloads
bettinaheim Jan 27, 2025
26e356c
clean up for scalars
bettinaheim Jan 28, 2025
357a136
some clean up of op sum
bettinaheim Jan 28, 2025
79a51b3
some clean up for products
bettinaheim Jan 28, 2025
39fd8c2
no type constraints for HandlerTy
bettinaheim Jan 29, 2025
e5ffd5c
left hand arithmetics cleanup
bettinaheim Jan 29, 2025
e4a07e2
more clean up
bettinaheim Jan 29, 2025
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
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
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
47 changes: 47 additions & 0 deletions docs/sphinx/api/languages/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,53 @@ Utilities
.. doxygentypedef:: cudaq::real

.. doxygenfunction:: cudaq::range(std::size_t)

Dynamics
=========

.. .. doxygenclass:: cudaq::EvolveResult
:members:

.. .. doxygenclass:: cudaq::AsyncEvolveResult
:members:

.. doxygenclass:: cudaq::operator_sum
:members:

.. doxygenclass:: cudaq::product_operator
:members:

.. doxygenclass:: cudaq::scalar_operator
:members:

.. doxygenclass:: cudaq::matrix_operator
:members:

.. doxygenclass:: cudaq::OperatorArithmetics
:members:

.. doxygenclass:: cudaq::MatrixArithmetics
:members:

.. doxygenclass:: cudaq::Schedule
:members:

.. doxygenclass:: cudaq::operators
:members:

.. doxygenclass:: cudaq::pauli
:members:

.. .. doxygenfunction:: cudaq::evolve(Operator hamiltonian, std::map<int,int> dimensions, Schedule schedule, bool store_intermediate_states)

.. .. doxygenfunction:: cudaq::evolve(Operator hamiltonian, std::map<int,int> dimensions, Schedule schedule, std::vector<Operator> collapse_operators, std::vector<Operator> observables, bool store_intermediate_states)

.. .. doxygenfunction:: cudaq::evolve(Operator hamiltonian, std::map<int,int> dimensions, Schedule schedule, state initial_state, std::vector<Operator> collapse_operators, std::vector<Operator> observables, bool store_intermediate_states)

.. .. doxygenfunction:: cudaq::evolve(Operator hamiltonian, std::map<int,int> dimensions, Schedule schedule, std::vector<state> initial_states, std::vector<Operator> collapse_operators, std::vector<Operator> observables, bool store_intermediate_states)

.. .. doxygenfunction:: cudaq::evolve_async


Namespaces
===========
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/EvolveResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class evolve_result {
return final_expectation_values;
}

std::optional<std::vector<std::vector<observe_result>>>
get_expectation_values() {
const std::optional<std::vector<std::vector<observe_result>>> &
get_expectation_values() const {
return expectation_values;
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/cudaq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (CUDA_FOUND)
PRIVATE .)

target_link_libraries(${LIBRARY_NAME}
PUBLIC dl cudaq-spin cudaq-common cudaq-nlopt cudaq-ensmallen
PUBLIC dl cudaq-spin cudaq-operators cudaq-common cudaq-nlopt cudaq-ensmallen
PRIVATE nvqir fmt::fmt-header-only CUDA::cudart_static)

target_compile_definitions(${LIBRARY_NAME} PRIVATE CUDAQ_HAS_CUDA)
Expand All @@ -52,7 +52,7 @@ else()
PRIVATE .)

target_link_libraries(${LIBRARY_NAME}
PUBLIC dl cudaq-spin cudaq-common cudaq-nlopt cudaq-ensmallen
PUBLIC dl cudaq-spin cudaq-operators cudaq-common cudaq-nlopt cudaq-ensmallen
PRIVATE nvqir fmt::fmt-header-only)
endif()

Expand All @@ -61,6 +61,7 @@ add_subdirectory(algorithms)
add_subdirectory(platform)
add_subdirectory(builder)
add_subdirectory(domains)
add_subdirectory(dynamics)

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

Expand Down
81 changes: 81 additions & 0 deletions runtime/cudaq/base_integrator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/****************************************************************-*- C++ -*-****
* 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. *
******************************************************************************/

#pragma once

#include "base_time_stepper.h"
#include "operators.h"
#include "schedule.h"
#include <map>
#include <memory>
#include <vector>

namespace cudaq {
template <typename TState>
class BaseIntegrator {
protected:
std::map<std::string, double> integrator_options;
TState state;
double t;
// std::map<int, int> dimensions;
// std::shared_ptr<Schedule> schedule;
// std::shared_ptr<operator_sum<HandlerTy>> hamiltonian;
std::shared_ptr<BaseTimeStepper<TState>> stepper;
// std::vector<std::shared_ptr<operator_sum<HandlerTy>>> collapse_operators;

virtual void post_init() = 0;

public:
/// @brief Default constructor
BaseIntegrator() = default;

/// @brief Constructor to initialize the integrator with a state and time
/// stepper.
/// @param initial_state Initial quantum state.
/// @param t0 Initial time.
/// @param stepper Time stepper instance.
BaseIntegrator(TState &&initial_state, double t0,
std::shared_ptr<BaseTimeStepper<TState>> stepper)
: state(std::move(initial_state)), t(t0), stepper(std::move(stepper)) {
if (!this->stepper) {
throw std::runtime_error("Time stepper is not initialized.");
}
}

virtual ~BaseIntegrator() = default;

/// @brief Set the initial state and time
void set_state(const TState &initial_state, double t0 = 0.0) {
state = initial_state;
t = t0;
}

/// @brief Set an option for the integrator
void set_option(const std::string &key, double value) {
integrator_options[key] = value;
}

/// @brief Set the system parameters (dimensions, schedule, and operators)
// void set_system(const std::map<int, int> &dimensions,
// std::shared_ptr<Schedule> schedule,
// std::shared_ptr<operator_sum<HandlerTy>> hamiltonian,
// std::vector<std::shared_ptr<operator_sum<HandlerTy>>>
// collapse_operators = {}) {
// this->dimensions = dimensions;
// this->schedule = schedule;
// this->hamiltonian = hamiltonian;
// this->collapse_operators = collapse_operators;
// }

/// @brief Perform integration to the target time.
virtual void integrate(double target_time) = 0;

/// @brief Get the current time and state.
std::pair<double, const TState &> get_state() const { return {t, state}; }
};
} // namespace cudaq
24 changes: 24 additions & 0 deletions runtime/cudaq/base_time_stepper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/****************************************************************-*- C++ -*-****
* 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. *
******************************************************************************/

#pragma once

namespace cudaq {
template <typename TState>
class BaseTimeStepper {
public:
virtual ~BaseTimeStepper() = default;

/// @brief Compute the next time step for the given quantum state.
/// @param state The quantum state to evolve.
/// @param t Current time.
/// @param step_size Time step size.
/// @return The updated quantum state after stepping.
virtual TState compute(TState &state, double t, double step_size) = 0;
};
} // namespace cudaq
30 changes: 30 additions & 0 deletions runtime/cudaq/cudm_error_handling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/****************************************************************-*- C++ -*-****
* 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. *
******************************************************************************/

#pragma once
#include <cudensitymat.h>
#include <fmt/core.h>
#include <stdexcept>

#define HANDLE_CUDM_ERROR(x) \
{ \
const auto err = x; \
if (err != CUDENSITYMAT_STATUS_SUCCESS) { \
throw std::runtime_error(fmt::format("[cudaq] %{} in {} (line {})", err, \
__FUNCTION__, __LINE__)); \
} \
}

#define HANDLE_CUDA_ERROR(x) \
{ \
const auto err = x; \
if (err != cudaSuccess) { \
throw std::runtime_error(fmt::format("[cuda] %{} in {} (line {})", err, \
__FUNCTION__, __LINE__)); \
} \
}
35 changes: 35 additions & 0 deletions runtime/cudaq/cudm_expectation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/****************************************************************-*- C++ -*-****
* 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. *
******************************************************************************/

#pragma once
#include <complex>
#include <cudensitymat.h>
namespace cudaq {

class cudm_expectation {
cudensitymatHandle_t m_handle{nullptr};
cudensitymatOperator_t m_hamOp{nullptr};
cudensitymatExpectation_t m_expectation{nullptr};
cudensitymatWorkspaceDescriptor_t m_workspace{nullptr};

public:
cudm_expectation(cudensitymatHandle_t handle, cudensitymatOperator_t op);
cudm_expectation(const cudm_expectation &) = delete;
cudm_expectation &operator=(const cudm_expectation &) = delete;
cudm_expectation(cudm_expectation &&src) {
std::swap(m_handle, src.m_handle);
std::swap(m_hamOp, src.m_hamOp);
std::swap(m_expectation, src.m_expectation);
std::swap(m_workspace, src.m_workspace);
}
~cudm_expectation();
void prepare(cudensitymatState_t state);
std::complex<double> compute(cudensitymatState_t state, double time);
};

} // namespace cudaq
98 changes: 98 additions & 0 deletions runtime/cudaq/cudm_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/****************************************************************-*- C++ -*-****
* 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. *
******************************************************************************/

#pragma once

#include "cudaq/operators.h"
#include "cudaq/utils/tensor.h"
#include <cudensitymat.h>
#include <iostream>
#include <map>
#include <stdexcept>
#include <vector>

namespace cudaq {
class cudm_helper {
public:
explicit cudm_helper(cudensitymatHandle_t handle);
~cudm_helper();

// Matrix flattening
static std::vector<std::complex<double>>
flatten_matrix(const matrix_2 &matrix);

// State Operations
void scale_state(cudensitymatState_t state, double scale_factor,
cudaStream_t stream);

// Compute Lindblad Operator
cudensitymatOperator_t
compute_lindblad_operator(const std::vector<matrix_2> &c_ops,
const std::vector<int64_t> &mode_extents);

// Convert operator sum to cudensitymat operator
template <typename HandlerTy>
cudensitymatOperator_t convert_to_cudensitymat_operator(
const std::map<std::string, std::complex<double>> &parameters,
const operator_sum<HandlerTy> &op,
const std::vector<int64_t> &mode_extents);

// Construct Liouvillian
cudensitymatOperator_t construct_liouvillian(
const operator_sum<cudaq::matrix_operator> &op,
const std::vector<operator_sum<cudaq::matrix_operator> *>
&collapse_operators,
const std::vector<int64_t> &mode_extents,
const std::map<std::string, std::complex<double>> &parameters,
bool is_master_equation);

// Construct Liouvillian
cudensitymatOperator_t construct_liouvillian(
const cudensitymatOperator_t &hamiltonian,
const std::vector<cudensitymatOperator_t> &collapse_operators,
double gamma);

// Helper Functions
std::map<int, int>
convert_dimensions(const std::vector<int64_t> &mode_extents);
std::vector<int64_t>
get_subspace_extents(const std::vector<int64_t> &mode_extents,
const std::vector<int> &degrees);

// Callback Wrappers
static cudensitymatWrappedScalarCallback_t
_wrap_callback(const scalar_operator &scalar_op);
static cudensitymatWrappedTensorCallback_t
_wrap_tensor_callback(const matrix_operator &op);

// Elementary Operator Functions
void append_scalar_to_term(cudensitymatOperatorTerm_t term,
const scalar_operator &scalar_op);
cudensitymatElementaryOperator_t create_elementary_operator(
const cudaq::matrix_operator &elem_op,
const std::map<std::string, std::complex<double>> &parameters,
const std::vector<int64_t> &mode_extents);
void append_elementary_operator_to_term(
cudensitymatOperatorTerm_t term,
const std::vector<cudensitymatElementaryOperator_t> &elem_ops,
const std::vector<std::vector<int>> &degrees, bool is_dagger);

// GPU memory management
static void *
create_array_gpu(const std::vector<std::complex<double>> &cpu_array);
static void destroy_array_gpu(void *gpu_array);

private:
cudensitymatHandle_t handle;
};

extern template cudensitymatOperator_t
cudm_helper::convert_to_cudensitymat_operator<cudaq::matrix_operator>(
const std::map<std::string, std::complex<double>> &,
const operator_sum<cudaq::matrix_operator> &, const std::vector<int64_t> &);
} // namespace cudaq
Loading
Loading