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] Adding missing operations in operators #2407

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions docs/sphinx/targets/cpp/infleqtion.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// Compile and run with:
// ```
// nvq++ --target infleqtion infleqtion.cpp -o out.x && ./out.x
// nvq++ --target `infleqtion` `infleqtion`.cpp -o out.x && ./out.x
// ```
// This will submit the job to the Infleqtion's ideal simulator,
// cq_sqale_simulator (default). Alternatively, we can enable hardware noise
// model simulation by specifying `noise-sim` to the flag `--infleqtion-method`,
// This will submit the job to the `Infleqtion's` ideal simulator,
// `cq`_`sqale`_simulator (default). Alternatively, we can enable hardware noise
// model simulation by specifying `noise-sim` to the flag --`infleqtion`-method,
// e.g.,
// ```
// nvq++ --target infleqtion --infleqtion-machine cq_sqale_qpu
// --infleqtion-method noise-sim infleqtion.cpp -o out.x && ./out.x
// nvq++ --target `infleqtion` --`infleqtion`-machine `cq`_`sqale`_qpu
// --`infleqtion`-method noise-sim `infleqtion`.cpp -o out.x && ./out.x
// ```
// where "noise-sim" instructs Superstaq to perform a noisy emulation of the
// where "noise-sim" instructs `Superstaq` to perform a noisy emulation of the
// QPU. An ideal dry-run execution on the QPU may be performed by passing
// `dry-run` to the `--infleqtion-method` flag, e.g.,
// `dry-run` to the --`infleqtion`-method flag, e.g.,
// ```
// nvq++ --target infleqtion --infleqtion-machine cq_sqale_qpu
// --infleqtion-method dry-run infleqtion.cpp -o out.x && ./out.x
// nvq++ --target `infleqtion` --`infleqtion`-machine `cq`_`sqale`_qpu
// --`infleqtion`-method dry-run `infleqtion`.cpp -o out.x && ./out.x
// ```
// Note: If targeting ideal cloud simulation, `--infleqtion-machine
// cq_sqale_simulator` is optional since it is the default configuration if not
// provided.
// Note: If targeting ideal cloud simulation, --`infleqtion`-machine
// `cq`_`sqale`_simulator is optional since it is the default configuration if
// not provided.

#include <cudaq.h>
#include <fstream>

// Define a simple quantum kernel to execute on Infleqtion backends.
// Define a simple quantum kernel to execute on `infleqtion` backends.
struct ghz {
// Maximally entangled state between 5 qubits.
auto operator()() __qpu__ {
Expand All @@ -38,7 +38,7 @@ struct ghz {
};

int main() {
// Submit to infleqtion asynchronously (e.g., continue executing
// Submit to `infleqtion` asynchronously (e.g., continue executing
// code in the file until the job has been returned).
auto future = cudaq::sample_async(ghz{});
// ... classical code to execute in the meantime ...
Expand All @@ -58,7 +58,7 @@ int main() {
auto async_counts = readIn.get();
async_counts.dump();

// OR: Submit to infleqtion synchronously (e.g., wait for the job
// OR: Submit to `infleqtion` synchronously (e.g., wait for the job
// result to be returned before proceeding).
auto counts = cudaq::sample(ghz{});
counts.dump();
Expand Down
6 changes: 3 additions & 3 deletions runtime/cudaq/algorithms/observe.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ concept ObserveCallValid =
/// @param shots number of shots to run for the given kernel, or -1 if not
/// applicable.
/// @param noise noise model to use for the sample operation
/// @param 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
/// @param 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;
Expand Down
11 changes: 11 additions & 0 deletions runtime/cudaq/dynamics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/****************************************************************-*- C++ -*-****
* Copyright (c) 2022 - 2024 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/dynamics/operators.h"
55 changes: 55 additions & 0 deletions runtime/cudaq/dynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ============================================================================ #
# Copyright (c) 2022 - 2024 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. #
# ============================================================================ #

if(NOT CUDENSITYMAT_ROOT)
SET(CUDENSITYMAT_ROOT "$ENV{CUQUANTUM_INSTALL_PREFIX}")
endif()

set(LIBRARY_NAME cudaq-operators)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ctad-maybe-unsupported")
set(INTERFACE_POSITION_INDEPENDENT_CODE ON)

# FIXME: add boost_integrator.cpp rungakutta_integrator.cpp back to fix compile errors
set(CUDAQ_OPS_SRC
scalar_operator.cpp elementary_operator.cpp product_operator.cpp operator_sum.cpp operator_helpers.cpp matrix_arithmetics.cpp
)

add_library(${LIBRARY_NAME} SHARED ${CUDAQ_OPS_SRC})
set_property(GLOBAL APPEND PROPERTY CUDAQ_RUNTIME_LIBS ${LIBRARY_NAME})
target_include_directories(${LIBRARY_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/runtime>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/tpls/eigen>
$<BUILD_INTERFACE:/usr/local/cuda-11.8/targets/x86_64-linux/include>
${CUDENSITYMAT_ROOT}/include
${CUDAToolkit_INCLUDE_DIRS}
$<INSTALL_INTERFACE:include>
PRIVATE .)

set(OPERATOR_DEPENDENCIES "")
list(APPEND OPERATOR_DEPENDENCIES fmt::fmt-header-only)
add_openmp_configurations(${LIBRARY_NAME} OPERATOR_DEPENDENCIES)

find_library(CUDENSITYMAT_LIB REQUIRED
NAMES cudensitymat
HINTS
${CUDENSITYMAT_ROOT}/lib
)

get_filename_component(CUDENSITYMAT_LIB_DIR ${CUDENSITYMAT_LIB} DIRECTORY)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${CUDENSITYMAT_LIB_DIR}")

target_link_libraries(${LIBRARY_NAME} PRIVATE ${OPERATOR_DEPENDENCIES})
target_link_libraries(${LIBRARY_NAME} PRIVATE ${CUDENSITYMAT_LIB})

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

install(EXPORT cudaq-operator-targets
FILE CUDAQSpinTargets.cmake
NAMESPACE cudaq::
DESTINATION lib/cmake/cudaq)
Loading
Loading