Skip to content

Commit

Permalink
Merge pull request #194 from qulacs/fix-gpu-test
Browse files Browse the repository at this point in the history
GPUでのテスト修正
  • Loading branch information
gandalfr-KY authored Jan 10, 2025
2 parents c2ed057 + a96e4c4 commit 1b3320b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
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()
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
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");
}
template <std::floating_point Fp>
constexpr Fp eps = eps_<Fp>();
Expand Down

0 comments on commit 1b3320b

Please sign in to comment.