Skip to content

Commit

Permalink
Use add_qcor_compile_and_exe_test for the multi-threading examples.
Browse files Browse the repository at this point in the history
Remove deuteron_threaded.cpp from ctest

Signed-off-by: Akihiro Hayashi <ahayashi@gatech.edu>
  • Loading branch information
ahayashi committed Jul 21, 2021
1 parent 35c1260 commit 3861741
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ add_qcor_compile_and_exe_test(qrt_qpu_arith_adder arithmetic/simple.cpp)
add_qcor_compile_and_exe_test(qrt_qpu_arith_integer_add arithmetic/integer_add.cpp)

# Multi-threading tests
add_test(NAME qrt_simple-objective-function-async COMMAND ${CMAKE_BINARY_DIR}/qcor -c ${CMAKE_CURRENT_SOURCE_DIR}/simple/simple-objective-function-async.cpp)
add_test(NAME qrt_simple-objective-function-threaded COMMAND ${CMAKE_BINARY_DIR}/qcor -c ${CMAKE_CURRENT_SOURCE_DIR}/simple/simple-objective-function-threaded.cpp)
add_test(NAME qrt_bell-threaded COMMAND ${CMAKE_BINARY_DIR}/qcor -c ${CMAKE_CURRENT_SOURCE_DIR}/simple/bell_threaded.cpp)
add_qcor_compile_and_exe_test(qrt_simple-objective-function-async simple/simple-objective-function-async.cpp)
add_qcor_compile_and_exe_test(qrt_simple-objective-function-threaded simple/simple-objective-function-threaded.cpp)
add_qcor_compile_and_exe_test(qrt_bell-threaded simple/bell_threaded.cpp)
add_qcor_compile_and_exe_test(qrt_qpu_lambda_bell_threaded qpu_lambda/lambda_test_bell_threaded.cpp)
add_qcor_compile_and_exe_test(qrt_qpu_lambda_deuteron_threaded qpu_lambda/deuteron_threaded.cpp)
add_qcor_compile_and_exe_test(qrt_qpu_lambda_deuteron_vqe_threaded qpu_lambda/deuteron_vqe_threaded.cpp)
add_qcor_compile_and_exe_test(qrt_qpu_lambda_deuteron_vqe_objfunc_threaded qpu_lambda/deuteron_vqe_obj_func_threaded.cpp)

Expand Down
11 changes: 5 additions & 6 deletions examples/qpu_lambda/deuteron_vqe_threaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ void foo() {
CX(q[1], q[0]);
});

OptFunction opt_function(
[&](std::vector<double> x) { return ansatz.observe(H, qalloc(2), x[0]); },
1);

OptFunction opt_function_vec(
ObjectiveFunction opt_function_vec(
[&](std::vector<double> x) {
return ansatz_take_vec.observe(H, qalloc(2), x);
},
1);

// Show off optimize from ObjectiveFunction rvalue
auto optimizer = createOptimizer("nlopt");
auto [ground_energy, opt_params] = optimizer->optimize(opt_function);
auto [ground_energy, opt_params] = optimizer->optimize(ObjectiveFunction(
[&](std::vector<double> x) { return ansatz.observe(H, qalloc(2), x[0]); },
1));
print("Energy: ", ground_energy);
qcor_expect(std::abs(ground_energy + 1.74886) < 0.1);

Expand Down

0 comments on commit 3861741

Please sign in to comment.