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

Set precision cmake #182

Merged
merged 44 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a60c483
split include/src [WIP]
Oct 30, 2024
7aab74e
restore --gpus all
KowerKoint Nov 1, 2024
218f0bb
state_vector compile
KowerKoint Nov 1, 2024
86fad40
add installation
KowerKoint Nov 1, 2024
f3b56d8
[WIP] transfering
KowerKoint Nov 8, 2024
71f6d52
transfer most of functions
Nov 13, 2024
271c908
reflect commit 4d65f3d
Nov 13, 2024
d53e3dc
enable pip install
KowerKoint Nov 15, 2024
deb9c49
Github Actions other-project build test
KowerKoint Nov 15, 2024
ce75305
specify CMAKE_C**_COMPILER for example_project
KowerKoint Nov 15, 2024
965e9a3
fix typo
KowerKoint Nov 15, 2024
c9f8ba0
Python typename on double
KowerKoint Nov 15, 2024
752e069
remove float name from type
KowerKoint Nov 15, 2024
a9399ce
nvcc is not in sudo PATH
KowerKoint Nov 15, 2024
8938d40
setup python
KowerKoint Nov 15, 2024
2ec5e6e
eps_f = 1e-6 -> 1e-5
KowerKoint Nov 15, 2024
342ece5
remove mypy check from test
KowerKoint Nov 15, 2024
82df9d9
transfer Circuit
KowerKoint Nov 15, 2024
5fa9b86
float declare Circuit
KowerKoint Nov 15, 2024
7d81c58
modify example_project
KowerKoint Nov 15, 2024
2ec154c
eps_f = 1e-5 -> 1e-4
KowerKoint Nov 15, 2024
dd92103
find_package(CUDATookit)
KowerKoint Nov 15, 2024
a89d68b
find_package(CUDATookit)
KowerKoint Nov 15, 2024
1641b90
CMAKE_INSTALL_PREFIX, update README
KowerKoint Nov 15, 2024
eecb99d
merge_gate for new cmake
Nov 20, 2024
239438d
[WIP] tempretize python bindings
Nov 20, 2024
9aad61b
python precision
KowerKoint Nov 22, 2024
ae1c48b
fix CI python script
KowerKoint Nov 22, 2024
b049a04
cuda path for sudo
KowerKoint Nov 22, 2024
3143078
cuda 12.2.0 -> 12.6.2
KowerKoint Nov 22, 2024
b28bde7
READMEの要件を追加
KowerKoint Nov 22, 2024
114fcb6
12.6.2->12.6.1
KowerKoint Nov 22, 2024
ec83f31
upgrade cuda-toolkit job
KowerKoint Nov 22, 2024
2eabac4
Merge pull request #183 from qulacs/149-merge-2
KowerKoint Nov 22, 2024
214c972
Merge pull request #185 from qulacs/upgrade-cuda-version
KowerKoint Nov 27, 2024
81b37fe
sudo env
Nov 27, 2024
87f7453
remove extra quate
Nov 27, 2024
96ecce7
add description about precision on README
Dec 6, 2024
e23eb27
fix CNot, Toffoli, CCNot alias
Dec 6, 2024
ccd574e
revert and fix CX
Dec 6, 2024
b348a0d
std::float64_t -> double
Dec 6, 2024
2f4ea1e
Merge branch 'set-precision-cmake' into python-precision
KowerKoint Dec 6, 2024
3ea7568
Merge pull request #184 from qulacs/python-precision
KowerKoint Dec 13, 2024
c2a2461
Merge branch 'set-precision' into set-precision-cmake
Dec 13, 2024
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
6 changes: 3 additions & 3 deletions .devcontainer/gpu/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"python.terminal.activateEnvironment": false,
// CAVEAT: you need to restart after building scaluq to take effect.
"C_Cpp.default.includePath": [
"scaluq",
"include",
"/usr/local/include/kokkos",
"build/_deps/eigen_fetch-src",
"build/_deps/googletest_fetch-src/googletest/include",
"build/_deps/eigen-src",
"build/_deps/googletest-src/googletest/include",
"~/.local/lib/python3.10/site-packages/nanobind/include",
"/usr/include/python3.10"
],
Expand Down
160 changes: 160 additions & 0 deletions .github/workflows/install.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ninja installでシステムに追加したscaluqライブラリが他のプロジェクトで使えるかどうかをテストする項目を追加しました。
また、pip installもシステムにインストールするという括りでこっちのワークフローに移動しました。

Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: Install to System

on:
push:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"
pull_request:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"

jobs:
library:
name: Install Library
strategy:
matrix:
os: ["linux", "macos"]
architecture: ["x86_64", "arm64"]
device: ["cpu", "cuda"]
python-version: ["3.10"]
exclude:
- os: "macos"
device: "cuda"
# currently ARM runner is not supported
- os: "linux"
architecture: "arm64"
include:
- os: "linux"
architecture: "x86_64"
runs-on: "ubuntu-22.04"
- os: "macos"
architecture: "x86_64"
runs-on: "macos-13"
- os: "macos"
architecture: "arm64"
runs-on: "macos-14"
runs-on: ${{ matrix.runs-on }}
env:
CMAKE_C_COMPILER: ${{ matrix.runs-on == 'macos-13' && '/usr/local/opt/ccache/libexec/gcc-14'|| matrix.runs-on == 'macos-14' && '/opt/homebrew/opt/ccache/libexec/gcc-14' || '/usr/lib/ccache/gcc' }}
CMAKE_CXX_COMPILER: ${{ matrix.runs-on == 'macos-13' && '/usr/local/opt/ccache/libexec/g++-14'|| matrix.runs-on == 'macos-14' && '/opt/homebrew/opt/ccache/libexec/g++-14' || '/usr/lib/ccache/g++' }}
SCALUQ_USE_CUDA: ${{ matrix.device == 'cuda' && 'ON' || 'OFF' }}
SCALUQ_CUDA_ARCH: "PASCAL61"
steps:
- uses: actions/checkout@v4

- name: Install Ninja
if: ${{ matrix.os == 'linux' }}
run: sudo apt update && sudo apt install ninja-build

- name: Install Ninja
if: ${{ matrix.os == 'macos' }}
run: brew install ninja

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: "${{ github.job }}-${{ matrix.os }}-${{ matrix.architecture }}-${{ matrix.device }}"
verbose: 2

- name: Install CUDA toolkit
if: ${{ matrix.device == 'cuda' }}
uses: Jimver/[email protected]
with:
cuda: "12.2.0"
method: "network"

- name: Show installed Compiler version
run: |
[ $SCALUQ_USE_CUDA = 'ON' ] && nvcc --version
ccache --version
$CMAKE_C_COMPILER --version
$CMAKE_CXX_COMPILER --version
cmake --version
ninja --version

- name: Configure
run: ./script/configure

- name: Install to system
run: sudo ninja -C build install

- name: Build and Run other project
run: |
cd example_project/
cmake -B build/ -D "CMAKE_C_COMPILER=$CMAKE_C_COMPILER" -D "CMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER"
make -C build
if [ "$SCALUQ_USE_CUDA" != 'ON']; then
build/main
fi

python:
name: Install Python package
strategy:
matrix:
os: ["linux", "macos"]
architecture: ["x86_64", "arm64"]
device: ["cpu", "cuda"]
python-version: ["3.10"]
exclude:
- os: "macos"
device: "cuda"
# currently ARM runner is not supported
- os: "linux"
architecture: "arm64"
include:
- os: "linux"
architecture: "x86_64"
runs-on: "ubuntu-22.04"
- os: "macos"
architecture: "x86_64"
runs-on: "macos-13"
- os: "macos"
architecture: "arm64"
runs-on: "macos-14"
runs-on: ${{ matrix.runs-on }}
env:
CMAKE_C_COMPILER: ${{ matrix.runs-on == 'macos-13' && '/usr/local/opt/ccache/libexec/gcc-14'|| matrix.runs-on == 'macos-14' && '/opt/homebrew/opt/ccache/libexec/gcc-14' || '/usr/lib/ccache/gcc' }}
CMAKE_CXX_COMPILER: ${{ matrix.runs-on == 'macos-13' && '/usr/local/opt/ccache/libexec/g++-14'|| matrix.runs-on == 'macos-14' && '/opt/homebrew/opt/ccache/libexec/g++-14' || '/usr/lib/ccache/g++' }}
SCALUQ_USE_CUDA: ${{ matrix.device == 'cuda' && 'ON' || 'OFF' }}
SCALUQ_CUDA_ARCH: "PASCAL61"
steps:
- uses: actions/checkout@v4

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: "${{ github.job }}-${{ matrix.os }}-${{ matrix.architecture }}-${{ matrix.device }}"
verbose: 2

- name: Install CUDA toolkit
if: ${{ matrix.device == 'cuda' }}
uses: Jimver/[email protected]
with:
cuda: "12.2.0"
method: "network"

- name: Show installed Compiler version
run: |
[ $SCALUQ_USE_CUDA = 'ON' ] && nvcc --version
ccache --version
$CMAKE_C_COMPILER --version
$CMAKE_CXX_COMPILER --version

- name: Install mypy
run: pip install mypy

- name: Install to system
run: pip install .

- name: Run / Test stub
if: ${{ matrix.device == 'cpu' }} # currently GPU runner is not supported
run: |
echo -e "from scaluq import StateVector, gate\nstate = StateVector(2)\nx = gate.X(0)\nx.update_quantum_state(state)\nprint(state.get_amplitudes())" > /tmp/sample.py
python3 /tmp/sample.py
mypy /tmp/sample.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
/doc/build/
/python/scaluq/_version.py
/kokkos-tools
/example_project/build/
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ if(NOT DEFINED SCALUQ_USE_CUDA)
set(SCALUQ_USE_CUDA OFF)
endif(NOT DEFINED SCALUQ_USE_CUDA)
if(NOT DEFINED SCALUQ_USE_TEST)
set(SCALUQ_USE_TEST ON)
set(SCALUQ_USE_TEST OFF)
endif(NOT DEFINED SCALUQ_USE_TEST)
if(NOT DEFINED SCALUQ_USE_EXE)
set(SCALUQ_USE_EXE ON)
set(SCALUQ_USE_EXE OFF)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

システムにインストールしたいだけの人を優先してデフォルト値を変更

endif(NOT DEFINED SCALUQ_USE_EXE)

message(STATUS "SKBUILD = ${SKBUILD}")
Expand Down Expand Up @@ -135,7 +135,7 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQ
endif()

### Add subdirectories ###
add_subdirectory(scaluq)
add_subdirectory(src)
if(SKBUILD)
add_subdirectory(python)
endif(SKBUILD)
Expand Down
15 changes: 15 additions & 0 deletions example_project/CMakeLists.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

scaluqを使った他のプロジェクトの設定例です

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.21)

project(example)

find_package(scaluq)
find_package(OpenMP)
add_executable(main main.cpp)
target_include_directories(main PUBLIC /usr/local/include/scaluq)
target_include_directories(main PUBLIC /usr/local/include/kokkos)
target_include_directories(main PUBLIC /usr/local/include/eigen3)
target_compile_features(main PUBLIC cxx_std_20)
target_compile_options(main PUBLIC -fopenmp)
target_compile_definitions(main PUBLIC OPENMP)
target_link_libraries(main PUBLIC scaluq::scaluq)

10 changes: 10 additions & 0 deletions example_project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <scaluq/state/state_vector.hpp>

int main() {
scaluq::initialize();
{
scaluq::StateVector<double> state(2);
std::cout << state << std::endl;
}
scaluq::finalize();
}
2 changes: 1 addition & 1 deletion exe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function(exe name)
if (SCALUQ_USE_TEST)
target_link_libraries(${name} PRIVATE GTest::gtest_main)
endif(SCALUQ_USE_TEST)
target_include_directories(${name} PRIVATE ${PROJECT_SOURCE_DIR}/scaluq)
target_include_directories(${name} PRIVATE ${PROJECT_SOURCE_DIR}/include)
endfunction()

# exe({file}) を追加すると、{file}.cpp をコンパイルして実行ファイルを build/exe/{file} として生成する
Expand Down
5 changes: 3 additions & 2 deletions exe/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
#include <functional>
#include <iostream>
#include <memory>
#include <scaluq/state/state_vector.hpp>
#include <sstream>
#include <stdexcept>
#include <type_traits>
#include <vector>

#include "gate/gate_factory.hpp"

using Fp = float;

int main() {
Expand All @@ -17,12 +16,14 @@ int main() {
std::uint64_t n_qubits = 3;
scaluq::StateVector<Fp> state(n_qubits);
state.load({0, 1, 2, 3, 4, 5, 6, 7});
/*
auto x_gate = scaluq::gate::X<Fp>(1, {0, 2});
x_gate->update_quantum_state(state);
auto sqrtx_gate = scaluq::gate::SqrtX<Fp>(1, {0});
sqrtx_gate->update_quantum_state(state);
auto sqrtxdag_gate = scaluq::gate::SqrtXdag<Fp>(0);
sqrtxdag_gate->update_quantum_state(state);
*/

std::cout << state << std::endl;
}
Expand Down
4 changes: 1 addition & 3 deletions scaluq/all.hpp → include/scaluq/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
#include "constant.hpp"
#include "gate/gate.hpp"
#include "gate/gate_factory.hpp"
#include "gate/merge_gate.hpp"
#include "gate/param_gate.hpp"
#include "gate/param_gate_factory.hpp"
#include "gate/update_ops.hpp"
#include "operator/apply_pauli.hpp"
#include "kokkos.hpp"
#include "operator/operator.hpp"
#include "operator/pauli_operator.hpp"
#include "state/state_vector.hpp"
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading