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

GPUでのテスト修正 #194

Merged
merged 4 commits into from
Jan 10, 2025
Merged
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
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQ
endif()

# Debug options
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if (SCALUQ_USE_CUDA)
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g,-O3>)
else()
Comment on lines +138 to 140
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVCCで -fsanitize=address,undefined としてカンマを用いるとうまくパースできないようでした.
加えてそもそも CUDA と sanitizer の相性が悪いようなので,これ自体を除きます.別のチェッカーを導入してもいいかもしれません.

target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g -fsanitize=address$<COMMA>undefined,-O3>)
target_link_options(scaluq PUBLIC $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g,-O3>)
else()
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g -fsanitize=address$<COMMA>undefined,-O3>)
target_link_options(scaluq PUBLIC $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>)
endif()
endif()
endif()

Expand Down
3 changes: 2 additions & 1 deletion script/configure_dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -eux

CMAKE_C_COMPILER=${CMAKE_C_COMPILER:-"gcc"}
CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER:-"g++"}
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-"Release"}
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-"Debug"}

CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-/usr/local}

SCALUQ_USE_OMP=${SCALUQ_USE_OMP:-"ON"}
Expand Down
3 changes: 0 additions & 3 deletions src/gate/merge_gate.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消し忘れてました.ありがとうございます.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ std::pair<Gate<Fp>, Fp> merge_gate_dense_matrix(const Gate<Fp>& gate1, const Gat
gate2->target_qubit_list(),
gate2->control_qubit_mask() & ~common_control_mask,
merged_operand_vector);
std::cerr << matrix1 << std::endl;
std::cerr << matrix2 << std::endl;
auto matrix = matrix2 * matrix1;
std::cerr << matrix << std::endl;
return {gate::DenseMatrix<Fp>(
merged_operand_vector, matrix, internal::mask_to_vector(common_control_mask)),
0.};
Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_executable(scaluq_test EXCLUDE_FROM_ALL
circuit/param_circuit_test.cpp
gate/gate_test.cpp
gate/batched_gate_test.cpp
# gate/merge_test.cpp
gate/merge_test.cpp
gate/param_gate_test.cpp
operator/test_pauli_operator.cpp
Expand Down
22 changes: 11 additions & 11 deletions tests/state/state_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ using namespace scaluq;

TEST(StateVectorTest, HaarRandomStateNorm) {
{
const int n_tries = 20;
const int n_tries = 6;
for (int n = 1; n <= n_tries; n++) {
const auto state = StateVector<double>::Haar_random_state(n);
ASSERT_NEAR(state.get_squared_norm(), 1., eps<double>);
}
}
{
const int n_tries = 20;
const int n_tries = 6;
for (int n = 1; n <= n_tries; n++) {
const auto state = StateVector<float>::Haar_random_state(n);
ASSERT_NEAR(state.get_squared_norm(), 1., eps<float>);
Expand All @@ -27,7 +27,7 @@ TEST(StateVectorTest, HaarRandomStateNorm) {
}

TEST(StateVectorTest, OperationAtIndex) {
auto state = StateVector<double>::Haar_random_state(10);
auto state = StateVector<double>::Haar_random_state(6);
for (std::uint64_t i = 0; i < state.dim(); ++i) {
state.set_amplitude_at(i, 1);
ASSERT_NEAR(state.get_amplitude_at(i).real(), 1., eps<double>);
Expand Down Expand Up @@ -73,7 +73,7 @@ TEST(StateVectorTest, ComputationalBasisState) {
}

TEST(StateVectorTest, HaarRandomStateSameSeed) {
const std::uint64_t n = 10, m = 5;
const std::uint64_t n = 6, m = 5;
for (std::uint64_t i = 0; i < m; ++i) {
StateVector state1(StateVector<double>::Haar_random_state(n, i)),
state2(StateVector<double>::Haar_random_state(n, i));
Expand All @@ -82,7 +82,7 @@ TEST(StateVectorTest, HaarRandomStateSameSeed) {
}

TEST(StateVectorTest, HaarRandomStateWithoutSeed) {
const std::uint64_t n = 10, m = 5;
const std::uint64_t n = 6, m = 5;
for (std::uint64_t i = 0; i < m; ++i) {
StateVector state1(StateVector<double>::Haar_random_state(n)),
state2(StateVector<double>::Haar_random_state(n));
Expand All @@ -91,7 +91,7 @@ TEST(StateVectorTest, HaarRandomStateWithoutSeed) {
}

TEST(StateVectorTest, AddState) {
const std::uint64_t n = 10;
const std::uint64_t n = 6;
StateVector state1(StateVector<double>::Haar_random_state(n));
StateVector state2(StateVector<double>::Haar_random_state(n));
auto vec1 = state1.get_amplitudes();
Expand All @@ -108,7 +108,7 @@ TEST(StateVectorTest, AddState) {

TEST(StateVectorTest, AddStateWithCoef) {
const CComplex coef(2.5, 1.3);
const std::uint64_t n = 10;
const std::uint64_t n = 6;
StateVector state1(StateVector<double>::Haar_random_state(n));
StateVector state2(StateVector<double>::Haar_random_state(n));
auto vec1 = state1.get_amplitudes();
Expand All @@ -125,7 +125,7 @@ TEST(StateVectorTest, AddStateWithCoef) {
}

TEST(StateVectorTest, MultiplyCoef) {
const std::uint64_t n = 10;
const std::uint64_t n = 6;
const CComplex coef(0.5, 0.2);

StateVector state(StateVector<double>::Haar_random_state(n));
Expand All @@ -141,7 +141,7 @@ TEST(StateVectorTest, MultiplyCoef) {
}

TEST(StateVectorTest, GetZeroProbability) {
const std::uint64_t n = 10;
const std::uint64_t n = 6;
StateVector<double> state(n);
state.set_computational_basis(1);
for (std::uint64_t i = 2; i <= 10; ++i) {
Expand Down Expand Up @@ -213,7 +213,7 @@ TEST(StateVectorTest, GetMarginalProbability) {
}

TEST(StateVectorTest, SamplingSuperpositionState) {
const std::uint64_t n = 10;
const std::uint64_t n = 6;
const std::uint64_t nshot = 65536;
const std::uint64_t test_count = 10;
std::uint64_t pass_count = 0;
Expand Down Expand Up @@ -248,7 +248,7 @@ TEST(StateVectorTest, SamplingSuperpositionState) {
}

TEST(StateVectorTest, SamplingComputationalBasis) {
const std::uint64_t n = 10;
const std::uint64_t n = 7;
const std::uint64_t nshot = 1024;
StateVector<double> state(n);
state.set_computational_basis(100);
Expand Down
2 changes: 1 addition & 1 deletion tests/util/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ constexpr Fp eps_() {
else if constexpr (std::is_same_v<Fp, float>)
return 1e-4;
else
static_assert(internal::lazy_false_v<void>, "unknown GateImpl");
static_assert(internal::lazy_false_v<Fp>, "unknown GateImpl");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fpを遅延評価したいのでこうしました.nvccのときのみ引っかかるようです.

}
template <std::floating_point Fp>
constexpr Fp eps = eps_<Fp>();
Expand Down