Skip to content

Commit

Permalink
Merge branch 'main' into testing-server
Browse files Browse the repository at this point in the history
  • Loading branch information
bettinaheim authored Dec 10, 2024
2 parents f265276 + 917146d commit d987b5c
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx/applications/cpp/bernstein_vazirani.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::vector<bool> random_bits(int seed) {

template <int nrOfBits>
struct oracle {
auto operator()(std::vector<bool> bitvector, cudaq::qview<> qs,
auto operator()(std::vector<bool> &bitvector, cudaq::qview<> qs,
cudaq::qubit &aux) __qpu__ {

for (size_t i = 0; i < nrOfBits; i++) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Frontend/nvqpp/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2310,8 +2310,10 @@ bool QuakeBridgeVisitor::VisitCXXOperatorCallExpr(
// replace it with an indirect call to the func::ConstantOp.
auto indirect = popValue();
auto funcTy = cast<FunctionType>(indirect.getType());
auto convertedArgs =
convertKernelArgs(builder, loc, 0, args, funcTy.getInputs());
auto call = builder.create<func::CallIndirectOp>(
loc, funcTy.getResults(), indirect, args);
loc, funcTy.getResults(), indirect, convertedArgs);
if (call.getResults().empty())
return true;
return pushValue(call.getResult(0));
Expand Down
4 changes: 4 additions & 0 deletions runtime/common/ExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class ExecutionContext {
/// `sample_result`.
std::vector<char> invocationResultBuffer;

/// @brief The number of trajectories to be used for an expectation
/// calculation on simulation backends that support trajectory simulation.
std::optional<std::size_t> numberTrajectories;

/// @brief The Constructor, takes the name of the context
/// @param n The name of the context
ExecutionContext(const std::string n) : name(n) {}
Expand Down
3 changes: 1 addition & 2 deletions runtime/cudaq/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

add_subdirectory(gradients)
add_subdirectory(optimizers)
add_subdirectory(optimizers)
11 changes: 0 additions & 11 deletions runtime/cudaq/algorithms/gradients/CMakeLists.txt

This file was deleted.

20 changes: 16 additions & 4 deletions runtime/cudaq/algorithms/observe.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ concept ObserveCallValid =
/// \p shots is the number of shots to run for the given kernel. The default of
/// -1 means direct calculations for simulation backends. \p noise is the noise
/// model to use for the observe operation.
/// \p num_trajectories is the optional number of trajectories to be used when
/// computing the expectation values in the presence of noise. This parameter is
/// only applied to simulation backends that support noisy
/// simulation of trajectories.
struct observe_options {
int shots = -1;
cudaq::noise_model noise;
std::optional<std::size_t> num_trajectories;
};

namespace details {
Expand All @@ -75,14 +80,17 @@ std::optional<observe_result>
runObservation(KernelFunctor &&k, cudaq::spin_op &h, quantum_platform &platform,
int shots, const std::string &kernelName, std::size_t qpu_id = 0,
details::future *futureResult = nullptr,
std::size_t batchIteration = 0,
std::size_t totalBatchIters = 0) {
std::size_t batchIteration = 0, std::size_t totalBatchIters = 0,
std::optional<std::size_t> numTrajectories = {}) {
auto ctx = std::make_unique<ExecutionContext>("observe", shots);
ctx->kernelName = kernelName;
ctx->spin = &h;
if (shots > 0)
ctx->shots = shots;

if (numTrajectories.has_value())
ctx->numberTrajectories = *numTrajectories;

ctx->batchIteration = batchIteration;
ctx->totalIterations = totalBatchIters;

Expand Down Expand Up @@ -469,7 +477,10 @@ observe_result observe(const observe_options &options, QuantumKernel &&kernel,
cudaq::invokeKernel(std::forward<QuantumKernel>(kernel),
std::forward<Args>(args)...);
},
H, platform, shots, kernelName)
H, platform, shots, kernelName, /*qpu_id=*/0,
/*futureResult=*/nullptr,
/*batchIteration=*/0,
/*totalBatchIters=*/0, options.num_trajectories)
.value();

platform.reset_noise();
Expand Down Expand Up @@ -690,7 +701,8 @@ std::vector<observe_result> observe(cudaq::observe_options &options,
[&kernel, &singleIterParameters...]() mutable {
kernel(std::forward<Args>(singleIterParameters)...);
},
H, platform, shots, kernelName, qpuId, nullptr, counter, N)
H, platform, shots, kernelName, qpuId, nullptr, counter, N,
options.num_trajectories)
.value();
return ret;
};
Expand Down
2 changes: 0 additions & 2 deletions runtime/cudaq/algorithms/optimizers/ensmallen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ if (NOT APPLE)
target_link_options(${LIBRARY_NAME} PRIVATE -Wl,--exclude-libs,ALL)
endif()

install (FILES ensmallen.h DESTINATION include/cudaq/algorithms/optimizers/)

install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-ensmallen-targets DESTINATION lib)
install(EXPORT cudaq-ensmallen-targets
FILE CUDAQEnsmallenTargets.cmake
Expand Down
2 changes: 0 additions & 2 deletions runtime/cudaq/algorithms/optimizers/nlopt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ target_include_directories(${LIBRARY_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/runtime)
target_include_directories(${LIBRARY_NAME} SYSTEM PRIVATE nlopt-src/ nlopt-src/src/api)
target_link_libraries(${LIBRARY_NAME} PRIVATE nlopt)

install (FILES nlopt.h DESTINATION include/cudaq/algorithms/optimizers/)

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

install(EXPORT cudaq-nlopt-targets
Expand Down
3 changes: 1 addition & 2 deletions runtime/cudaq/algorithms/vqe.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ optimization_result vqe(std::size_t shots, QuantumKernel &&kernel,

return optimizer.optimize(n_params, [&](const std::vector<double> &x,
std::vector<double> &grad_vec) {
observe_options options{static_cast<int>(shots), cudaq::noise_model{}};
double e = cudaq::observe(options, kernel, H, x, args...);
double e = cudaq::observe(shots, kernel, H, x, args...);
return e;
});
}
Expand Down
1 change: 0 additions & 1 deletion runtime/cudaq/platform/default/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target_link_libraries(${LIBRARY_NAME}
PRIVATE
fmt::fmt-header-only cudaq CUDAQTargetConfigUtil)

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

Expand Down
1 change: 0 additions & 1 deletion runtime/cudaq/platform/default/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ target_link_libraries(cudaq-rest-qpu

install(TARGETS cudaq-rest-qpu DESTINATION lib)

install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-rest-qpu-targets DESTINATION lib)
3 changes: 1 addition & 2 deletions runtime/cudaq/platform/fermioniq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ target_link_libraries(${LIBRARY_NAME}
cudaq-platform-default)

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

# install(EXPORT cudaq-fermioniq-qpu-targets
# FILE CUDAQQPUFermioniqTargets.cmake
Expand All @@ -37,4 +36,4 @@ install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-fermioniq-qpu-targets DESTINATION l

add_target_config(fermioniq)

add_subdirectory(helpers)
add_subdirectory(helpers)
2 changes: 0 additions & 2 deletions runtime/cudaq/platform/mqpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,5 @@ if (CUDA_FOUND AND CUSTATEVEC_ROOT)
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
install(TARGETS ${LIBRARY_NAME}
EXPORT cudaq-platform-mqpu-targets DESTINATION lib)
add_target_config(remote-mqpu)
add_target_config(nvqc)
1 change: 0 additions & 1 deletion runtime/cudaq/platform/mqpu/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ target_link_libraries(cudaq-remote-simulator-qpu PUBLIC

install(TARGETS cudaq-remote-simulator-qpu DESTINATION lib)

install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-remote-simulator-qpu-targets DESTINATION lib)
1 change: 0 additions & 1 deletion runtime/cudaq/platform/orca/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ target_link_libraries(${LIBRARY_NAME}
cudaq-platform-default)

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

add_target_config(orca)
1 change: 0 additions & 1 deletion runtime/cudaq/platform/quera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ target_link_libraries(${LIBRARY_NAME}
cudaq-platform-default)

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

add_target_config(quera)

0 comments on commit d987b5c

Please sign in to comment.