diff --git a/.devcontainer/cpu/Dockerfile b/.devcontainer/cpu/Dockerfile index c9152abd..5a3d0b2d 100644 --- a/.devcontainer/cpu/Dockerfile +++ b/.devcontainer/cpu/Dockerfile @@ -16,9 +16,9 @@ ENV PYTHONPATH="${PROJECT_DIR}/build:${PYTHONPATH}" RUN apt-get update && \ apt-get install -y software-properties-common && \ apt-get update && \ - apt-get install -y gcc-10 g++-10 && \ - update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \ - update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 \ + apt-get install -y gcc-11 g++-11 && \ + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \ + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 \ && apt-get install -y --no-install-recommends \ clang-format \ git \ diff --git a/.devcontainer/gpu/Dockerfile b/.devcontainer/gpu/Dockerfile index 79a5e649..0fb38d02 100644 --- a/.devcontainer/gpu/Dockerfile +++ b/.devcontainer/gpu/Dockerfile @@ -10,23 +10,21 @@ ENV PYTHONPATH="${PROJECT_DIR}/build:${PYTHONPATH}" RUN apt-get update && \ apt-get install -y software-properties-common && \ + add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ apt-get update && \ - apt-get install -y gcc-10 g++-10 && \ - update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \ - update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 \ + apt-get install -y gcc-11 g++-11 && \ + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 && \ + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 \ # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131, which is done in Microsoft's devcontainer image. && apt-get purge -y imagemagick imagemagick-6-common \ && apt-get install -y --no-install-recommends \ ca-certificates \ clang-format \ - cmake \ curl \ git \ gdb \ libboost-dev \ libpython3-dev \ - manpages \ - man-db \ ninja-build \ python3 \ python3-distutils \ @@ -37,6 +35,13 @@ RUN apt-get update && \ RUN pip install -U pip \ && pip install black flake8 openfermion mypy pybind11-stubgen +RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-Linux-x86_64.sh -q -O /tmp/cmake-install.sh && \ + chmod u+x /tmp/cmake-install.sh && \ + mkdir /opt/cmake-3.28.0 && \ + /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.28.0 && \ + rm /tmp/cmake-install.sh && \ + ln -s /opt/cmake-3.28.0/bin/* /usr/local/bin + RUN git clone --recursive https://github.com/kokkos/kokkos.git /tmp/kokkos --depth 1 && \ mkdir /tmp/kokkos/build && \ cd /tmp/kokkos/build && \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 71193d4c..263a6691 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.21) project(qulacs) @@ -21,6 +21,39 @@ endif(NOT DEFINED QULACS_USE_TEST) message(STATUS "QULACS_USE_PYTHON = ${QULACS_USE_PYTHON}") message(STATUS "QULACS_USE_TEST = ${QULACS_USE_TEST}") +### Compile Warnings ### +if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \ + -Werror=missing-declarations -Werror=return-type -Wextra \ + -Wfloat-equal -Wimplicit-fallthrough=5 -Wlogical-op \ + -Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \ + -Wshadow -Wstrict-aliasing=2 -Wsuggest-attribute=noreturn -Wwrite-strings \ + -fdiagnostics-color=auto -fstrict-aliasing") + # -Werror=undef is eliminated due to conflict with boost +elseif ((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")) + set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \ + -Werror=missing-declarations -Werror=return-type -Wextra \ + -Wfloat-equal -Wimplicit-fallthrough \ + -Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \ + -Wshadow -Wstrict-aliasing=2 -Wwrite-strings \ + -fdiagnostics-color=auto -fstrict-aliasing") +endif() + +### Compiler options ### +if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + # Enable pthread + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + + # Enable openmp + if(QULACS_USE_OMP) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") + add_compile_definitions(OPENMP) + endif() +endif() + ### Kokkos options ### set(Kokkos_ENABLE_SERIAL Yes) if(QULACS_USE_OMP) @@ -28,6 +61,7 @@ if(QULACS_USE_OMP) endif(QULACS_USE_OMP) if(QULACS_USE_CUDA) set(Kokkos_ENABLE_CUDA Yes) + set(Kokkos_ARCH_VOLTA70 Yes) find_program(CUDA_NVCC_EXECUTABLE nvcc) if(CUDA_NVCC_EXECUTABLE) set(CMAKE_CUDA_COMPILER_WRAPPER ${CUDA_NVCC_EXECUTABLE}) @@ -42,7 +76,7 @@ endif(QULACS_USE_CUDA) FetchContent_Declare( kokkos_fetch GIT_REPOSITORY https://github.com/kokkos/kokkos - GIT_TAG 4.1.00 + GIT_TAG 4.2.00 ) FetchContent_GetProperties(kokkos_fetch) if(NOT kokkos_fetch_POPULATED) @@ -96,40 +130,6 @@ else() message(STATUS "Skip downloding googletest") endif(QULACS_USE_TEST) -### Compile Warnings ### -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") - set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \ - -Werror=missing-declarations -Werror=return-type -Wextra \ - -Wfloat-equal -Wimplicit-fallthrough=5 -Wlogical-op \ - -Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \ - -Wshadow -Wstrict-aliasing=2 -Wsuggest-attribute=noreturn -Wwrite-strings \ - -fdiagnostics-color=auto -fstrict-aliasing") - # -Werror=undef is eliminated due to conflict with boost -elseif ((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")) - set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \ - -Werror=missing-declarations -Werror=return-type -Wextra \ - -Wfloat-equal -Wimplicit-fallthrough \ - -Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \ - -Wshadow -Wstrict-aliasing=2 -Wwrite-strings \ - -fdiagnostics-color=auto -fstrict-aliasing") -endif() - -### Compiler options ### -if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")) - - add_compile_options("-std=c++20") - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - - # Enable pthread - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") - - # Enable openmp - if(QULACS_USE_OMP) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") - add_compile_definitions(OPENMP) - endif() -endif() - ### Add subdirectories ### add_subdirectory(qulacs) if(QULACS_USE_PYTHON) diff --git a/qulacs/state/state_vector.cpp b/qulacs/state/state_vector.cpp index ddd0b830..5488604e 100644 --- a/qulacs/state/state_vector.cpp +++ b/qulacs/state/state_vector.cpp @@ -37,7 +37,7 @@ double StateVector::compute_squared_norm() const { Kokkos::parallel_reduce( this->_dim, KOKKOS_CLASS_LAMBDA(const UINT& it, double& tmp) { - tmp += std::norm(this->_amplitudes[it]); + tmp += Kokkos::norm2(this->_amplitudes[it]); }, norm); return norm;