Skip to content

Commit 982df58

Browse files
kvmtoannagrinbmhowe23melody-ren
authored
UCCSD operator pool correction and integration in adapt simulator (#65)
# UCCSD operator pool correction and integration in adapt simulator (Issue #28) This PR fixes #28 . ## Problem Adapt VQE did not provide correct results. The problem could be the creation of the UCCSD operators pool. ## Changes Changes so far have been applied to: - The UCCSD operator pool 'generate' function. - The Testing of the UCCSD operator pool, cpp and py files. - Tested adap_vqe for final results. ## Additional notes Further testing is needed for making sure that adapt VQE works correctly, especially in terms of molecules. --------- Signed-off-by: kvmto <[email protected]> Signed-off-by: Anna Gringauze <[email protected]> Signed-off-by: Kevin Mato <[email protected]> Signed-off-by: Melody Ren <[email protected]> Co-authored-by: Anna Gringauze <[email protected]> Co-authored-by: Ben Howe <[email protected]> Co-authored-by: Melody Ren <[email protected]>
1 parent 529ec6f commit 982df58

File tree

19 files changed

+921
-171
lines changed

19 files changed

+921
-171
lines changed

libs/solvers/include/cudaq/solvers/adapt.h

+65-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,23 @@ class adapt_impl : public extension_point<adapt_impl> {
7070
/// @param pool Pool of operators
7171
/// @param optimizer Optimization algorithm
7272
/// @param gradient Gradient calculation method
73-
/// @param options Additional options for the algorithm
73+
/// @param options Additional options for the algorithm. Supported Keys:
74+
/// - "max_iter" (int): Maximum number of iterations [default: 30]
75+
/// - "grad_norm_tolerance" (double): Convergence tolerance for gradient norm
76+
/// [default: 1e-5]
77+
/// - "grad_norm_diff_tolerance" (double): Tolerance for difference between
78+
/// gradient norms [default: 1e-5]
79+
/// - "threshold_energy" (double): Energy convergence threshold [default:
80+
/// 1e-6]
81+
/// - "initial_theta" (double): Initial value for theta parameter [default:
82+
/// 0.0]
83+
/// - "verbose" (bool): Enable detailed output logging [default: false]
84+
/// - "shots" (int): Number of measurement shots (-1 for exact simulation)
85+
/// [default: -1]
86+
/// - "dynamic_start" (string): Optimization mode for the theta parameters at
87+
/// each iteration.
88+
/// It can be either "warm", or "cold". [default: "cold"]
89+
/// - "tol" (double): Tolerance for optimization [default: 1e-12]
7490
/// @return Result of the ADAPT-VQE algorithm
7591
virtual result run(const cudaq::qkernel<void(cudaq::qvector<> &)> &initState,
7692
const spin_op &H, const std::vector<spin_op> &pool,
@@ -88,7 +104,22 @@ class adapt_impl : public extension_point<adapt_impl> {
88104
/// @param initialState Initial state preparation quantum kernel
89105
/// @param H Hamiltonian operator
90106
/// @param poolList Pool of operators
91-
/// @param options Additional options for the algorithm
107+
/// @param options Additional options for the algorithm. Supported Keys:
108+
/// - "max_iter" (int): Maximum number of iterations [default: 30]
109+
/// - "grad_norm_tolerance" (double): Convergence tolerance for gradient norm
110+
/// [default: 1e-5]
111+
/// - "grad_norm_diff_tolerance" (double): Tolerance for difference between
112+
/// gradient norms [default: 1e-5]
113+
/// - "threshold_energy" (double): Energy convergence threshold [default: 1e-6]
114+
/// - "initial_theta" (double): Initial value for theta parameter [default:
115+
/// 0.0]
116+
/// - "verbose" (bool): Enable detailed output logging [default: false]
117+
/// - "shots" (int): Number of measurement shots (-1 for exact simulation)
118+
/// [default: -1]
119+
/// - "dynamic_start" (string): Optimization mode for the theta parameters at
120+
/// each iteration.
121+
/// It can be either "warm", or "cold". [default: "cold"]
122+
/// - "tol" (double): Tolerance for optimization [default: 1e-12]
92123
/// @return Result of the ADAPT-VQE algorithm
93124
static inline adapt::result
94125
adapt_vqe(const cudaq::qkernel<void(cudaq::qvector<> &)> &initialState,
@@ -106,7 +137,22 @@ adapt_vqe(const cudaq::qkernel<void(cudaq::qvector<> &)> &initialState,
106137
/// @param H Hamiltonian operator
107138
/// @param poolList Pool of operators
108139
/// @param optimizer Custom optimization algorithm
109-
/// @param options Additional options for the algorithm
140+
/// @param options Additional options for the algorithm. Supported Keys:
141+
/// - "max_iter" (int): Maximum number of iterations [default: 30]
142+
/// - "grad_norm_tolerance" (double): Convergence tolerance for gradient norm
143+
/// [default: 1e-5]
144+
/// - "grad_norm_diff_tolerance" (double): Tolerance for difference between
145+
/// gradient norms [default: 1e-5]
146+
/// - "threshold_energy" (double): Energy convergence threshold [default: 1e-6]
147+
/// - "initial_theta" (double): Initial value for theta parameter [default:
148+
/// 0.0]
149+
/// - "verbose" (bool): Enable detailed output logging [default: false]
150+
/// - "shots" (int): Number of measurement shots (-1 for exact simulation)
151+
/// [default: -1]
152+
/// - "dynamic_start" (string): Optimization mode for the theta parameters at
153+
/// each iteration.
154+
/// It can be either "warm", or "cold". [default: "cold"]
155+
/// - "tol" (double): Tolerance for optimization [default: 1e-12]
110156
/// @return Result of the ADAPT-VQE algorithm
111157
static inline adapt::result
112158
adapt_vqe(const cudaq::qkernel<void(cudaq::qvector<> &)> &initialState,
@@ -125,7 +171,22 @@ adapt_vqe(const cudaq::qkernel<void(cudaq::qvector<> &)> &initialState,
125171
/// @param poolList Pool of operators
126172
/// @param optimizer Custom optimization algorithm
127173
/// @param gradient Gradient calculation method
128-
/// @param options Additional options for the algorithm
174+
/// @param options Additional options for the algorithm. Supported Keys:
175+
/// - "max_iter" (int): Maximum number of iterations [default: 30]
176+
/// - "grad_norm_tolerance" (double): Convergence tolerance for gradient norm
177+
/// [default: 1e-5]
178+
/// - "grad_norm_diff_tolerance" (double): Tolerance for difference between
179+
/// gradient norms [default: 1e-5]
180+
/// - "threshold_energy" (double): Energy convergence threshold [default: 1e-6]
181+
/// - "initial_theta" (double): Initial value for theta parameter [default:
182+
/// 0.0]
183+
/// - "verbose" (bool): Enable detailed output logging [default: false]
184+
/// - "shots" (int): Number of measurement shots (-1 for exact simulation)
185+
/// [default: -1]
186+
/// - "dynamic_start" (string): Optimization mode for the theta parameters at
187+
/// each iteration.
188+
/// It can be either "warm", or "cold". [default: "cold"]
189+
/// - "tol" (double): Tolerance for optimization [default: 1e-12]
129190
/// @return Result of the ADAPT-VQE algorithm
130191
static inline adapt::result
131192
adapt_vqe(const cudaq::qkernel<void(cudaq::qvector<> &)> &initialState,

libs/solvers/include/cudaq/solvers/operators/operator_pools/qaoa_operator_pool.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,33 @@
1212

1313
namespace cudaq::solvers {
1414

15-
/// @brief Test
15+
/// @brief QAOA operator pool is a class with generates a pool
16+
/// of QAOA operators for use in quantum algorithms, like Adapt-QAOA.
17+
/// @details This class extends the operator_pool interface
18+
/// therefore inherits the extension_point template, allowing for
19+
/// runtime extensibility.
1620
class qaoa_pool : public operator_pool {
1721
public:
22+
/// @brief Generate a vector of spin operators based on the provided
23+
/// configuration.
24+
/// @param config A heterogeneous map containing configuration parameters for
25+
/// operator generation.
26+
/// @return A vector of cudaq::spin_op objects representing the generated
27+
/// operator pool.
1828
std::vector<cudaq::spin_op>
1929
generate(const heterogeneous_map &config) const override;
30+
31+
/// @brief Call to macro for defining the creator function for the qaoa_pool
32+
/// extension
33+
/// @details This function is used by the extension point mechanism to create
34+
/// instances of the qaoa_pool class. The extension is registered with a name
2035
CUDAQ_EXTENSION_CUSTOM_CREATOR_FUNCTION_WITH_NAME(
2136
qaoa_pool, "qaoa", static std::unique_ptr<operator_pool> create() {
2237
return std::make_unique<qaoa_pool>();
2338
})
2439
};
40+
41+
/// @brief Register the qaoa_pool extension type with the CUDA-Q framework
2542
CUDAQ_REGISTER_TYPE(qaoa_pool)
2643

2744
} // namespace cudaq::solvers

libs/solvers/include/cudaq/solvers/operators/operator_pools/spin_complement_gsd.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,31 @@ namespace cudaq::solvers {
1515
// adapted from
1616
// https://github.com/mayhallgroup/adapt-vqe/blob/master/src/operator_pools.py
1717

18-
/// @brief Test
18+
/// @brief spin_complement_gsd operator pool is a class which generates a pool
19+
/// of operators with the spin complement ground state degeneracy method for use
20+
/// in quantum algorithms, like Adapt-VQE.
21+
/// @details This class extends the operator_pool interface
22+
/// therefore inherits extension_point template, allowing for
23+
/// runtime extensibility.
1924
class spin_complement_gsd : public operator_pool {
2025

2126
public:
27+
/// @brief Generate a vector of spin operators based on the provided
28+
/// configuration.
29+
/// @param config A heterogeneous map containing configuration parameters for
30+
/// operator generation.
31+
/// @return A vector of cudaq::spin_op objects representing the generated
32+
/// operator pool.
2233
std::vector<cudaq::spin_op>
2334
generate(const heterogeneous_map &config) const override;
35+
36+
/// @brief Call to macro for defining the creator function for the
37+
/// spin_complement_gsd extension
38+
/// @details This function is used by the extension point mechanism to create
39+
/// instances of the spin_complement_gsd class.
2440
CUDAQ_EXTENSION_CREATOR_FUNCTION(operator_pool, spin_complement_gsd)
2541
};
42+
/// @brief Register the spin_complement_gsd extension type with the CUDA-Q
43+
/// framework
2644
CUDAQ_REGISTER_TYPE(spin_complement_gsd)
2745
} // namespace cudaq::solvers

libs/solvers/include/cudaq/solvers/operators/operator_pools/uccsd_operator_pool.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@
1212

1313
namespace cudaq::solvers {
1414

15-
/// @brief Test
15+
/// @brief UCCSD operator pool is a class with generates a pool
16+
/// of UCCSD operators for use in quantum algorithms, like Adapt-VQE.
17+
/// @details This class extends the operator_pool interface
18+
/// therefore inherits the extension_point template, allowing for
19+
/// runtime extensibility.
1620
class uccsd : public operator_pool {
1721

1822
public:
23+
/// @brief Generate a vector of spin operators based on the provided
24+
/// configuration.
25+
/// @details The UCCSD operator pool is generated with an imaginary factor 'i
26+
/// in the coefficients of the operators, which simplifies the use for running
27+
/// Adapt-VQE.
28+
/// @param config A heterogeneous map containing configuration parameters for
29+
/// operator generation.
30+
/// @return A vector of cudaq::spin_op objects representing the generated
31+
/// operator pool.
1932
std::vector<cudaq::spin_op>
2033
generate(const heterogeneous_map &config) const override;
34+
35+
/// @brief Call to macro for defining the creator function for an extension
36+
/// @details This function is used by the extension point mechanism to create
37+
/// instances of the uccsd class.
2138
CUDAQ_EXTENSION_CREATOR_FUNCTION(operator_pool, uccsd)
2239
};
40+
/// @brief Register the uccsd extension type with the CUDA-Q framework
2341
CUDAQ_REGISTER_TYPE(uccsd)
2442

2543
} // namespace cudaq::solvers

libs/solvers/include/cudaq/solvers/vqe.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct vqe_result {
3737
/// @param optimizer Optimization algorithm to use
3838
/// @param gradient Gradient computation method
3939
/// @param initial_parameters Initial parameters for the optimization
40-
/// @param options Additional options for the VQE algorithm
40+
/// @param options Additional options for the VQE algorithm. Available options
41+
/// - "tol" (double): Tolerance for optimization [default: 1e-12]
4142
/// @return VQE result containing optimal energy, parameters, and iteration data
4243
template <typename QuantumKernel>
4344
requires std::invocable<QuantumKernel, std::vector<double>>

0 commit comments

Comments
 (0)