Skip to content

Commit 7b256a7

Browse files
bmhowe23justinlietz
authored andcommitted
Change default decoder float type to double (NVIDIA#31)
1 parent 6a6287c commit 7b256a7

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

libs/qec/include/cudaq/qec/decoder.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************-*- C++ -*-****
2-
* Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. *
2+
* Copyright (c) 2024 NVIDIA Corporation & Affiliates. *
33
* All rights reserved. *
44
* *
55
* This source code and the accompanying materials are made available under *
@@ -19,7 +19,7 @@ namespace cudaq::qec {
1919
#if defined(CUDAQX_QEC_FLOAT_TYPE)
2020
using float_t = CUDAQX_QEC_FLOAT_TYPE;
2121
#else
22-
using float_t = float;
22+
using float_t = double;
2323
#endif
2424

2525
/// @brief Decoder results
@@ -30,6 +30,17 @@ struct decoder_result {
3030
/// @brief Vector of length `block_size` with soft probabilities of errors in
3131
/// each index.
3232
std::vector<float_t> result;
33+
34+
// Manually define the equality operator
35+
bool operator==(const decoder_result &other) const {
36+
return std::tie(converged, result) ==
37+
std::tie(other.converged, other.result);
38+
}
39+
40+
// Manually define the inequality operator
41+
bool operator!=(const decoder_result &other) const {
42+
return !(*this == other);
43+
}
3344
};
3445

3546
/// @brief The `decoder` base class should be subclassed by specific decoder

libs/qec/lib/CMakeLists.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
# the terms of the Apache License 2.0 which accompanies this distribution. #
77
# ============================================================================ #
88

9+
set(LIBRARY_NAME cudaq-qec)
10+
911
add_compile_options(-Wno-attributes)
1012

1113
# FIXME?: This must be a shared library. Trying to build a static one will fail.
12-
add_library(cudaq-qec SHARED
14+
add_library(${LIBRARY_NAME} SHARED
1315
code.cpp
1416
stabilizer_utils.cpp
1517
decoder.cpp
@@ -20,22 +22,22 @@ add_library(cudaq-qec SHARED
2022
add_subdirectory(codes)
2123
add_subdirectory(device)
2224

23-
if (CUDAQX_QEC_USE_DOUBLE)
24-
target_compile_definitions(cudaq-qec PUBLIC -DCUDAQX_QEC_FLOAT_TYPE=double)
25+
if (CUDAQX_QEC_USE_FLOAT)
26+
target_compile_definitions(${LIBRARY_NAME} PUBLIC -DCUDAQX_QEC_FLOAT_TYPE=float)
2527
endif()
2628

27-
target_include_directories(cudaq-qec
29+
target_include_directories(${LIBRARY_NAME}
2830
PUBLIC
2931
$<BUILD_INTERFACE:${CUDAQX_QEC_INCLUDE_DIR}>
3032
$<INSTALL_INTERFACE:${CUDAQ_INCLUDE_DIR}>
3133
$<INSTALL_INTERFACE:include>
3234
)
3335

34-
target_link_options(cudaq-qec PUBLIC
36+
target_link_options(${LIBRARY_NAME} PUBLIC
3537
$<$<CXX_COMPILER_ID:GNU>:-Wl,--no-as-needed>
3638
)
3739

38-
target_link_libraries(cudaq-qec
40+
target_link_libraries(${LIBRARY_NAME}
3941
PUBLIC
4042
cudaqx-core
4143
cudaq::cudaq
@@ -44,33 +46,33 @@ target_link_libraries(cudaq-qec
4446
cudaq::cudaq-common
4547
)
4648

47-
set_target_properties(cudaq-qec PROPERTIES
49+
set_target_properties(${LIBRARY_NAME} PROPERTIES
4850
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
4951

5052
# RPATH configuration
5153
# ==============================================================================
5254

5355
if (NOT SKBUILD)
54-
set_target_properties(cudaq-qec PROPERTIES
56+
set_target_properties(${LIBRARY_NAME} PROPERTIES
5557
BUILD_RPATH "$ORIGIN"
5658
INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib"
5759
)
5860

5961
# Let CMake automatically add paths of linked libraries to the RPATH:
60-
set_target_properties(cudaq-qec PROPERTIES
62+
set_target_properties(${LIBRARY_NAME} PROPERTIES
6163
INSTALL_RPATH_USE_LINK_PATH TRUE)
6264
else()
6365
# CUDA-Q install its libraries in site-packages/lib (or dist-packages/lib)
6466
# Thus, we need the $ORIGIN/../lib
65-
set_target_properties(cudaq-qec PROPERTIES
67+
set_target_properties(${LIBRARY_NAME} PROPERTIES
6668
INSTALL_RPATH "$ORIGIN/../../lib"
6769
)
6870
endif()
6971

7072
# Install
7173
# ==============================================================================
7274

73-
install(TARGETS cudaq-qec
75+
install(TARGETS ${LIBRARY_NAME}
7476
COMPONENT qec-lib
7577
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
7678
)

0 commit comments

Comments
 (0)