Skip to content

Commit

Permalink
Merge branch 'main' into qutanum
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc authored Jul 26, 2024
2 parents cdda750 + fd8c955 commit 46c32d1
Show file tree
Hide file tree
Showing 482 changed files with 37,170 additions and 10,108 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.2.0
71 changes: 53 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
{os: ubuntu-latest, dist: cp39-manylinux_x86_64},
{os: ubuntu-latest, dist: cp310-manylinux_x86_64},
{os: ubuntu-latest, dist: cp311-manylinux_x86_64},
{os: ubuntu-latest, dist: cp312-manylinux_x86_64},

{os: ubuntu-latest, dist: cp36-manylinux_i686},
{os: ubuntu-latest, dist: cp37-manylinux_i686},
Expand Down Expand Up @@ -92,11 +93,13 @@ jobs:
{os: macos-latest, dist: cp39-macosx_x86_64, macosarch: x86_64},
{os: macos-latest, dist: cp310-macosx_x86_64, macosarch: x86_64},
{os: macos-latest, dist: cp311-macosx_x86_64, macosarch: x86_64},
{os: macos-latest, dist: cp312-macosx_x86_64, macosarch: x86_64},

{os: macos-latest, dist: cp38-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp39-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp310-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp311-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp312-macosx_arm64, macosarch: arm64},

# pypy OSX builds disabled because numpy isn't prebuilt and fails to build.
#
Expand All @@ -119,6 +122,7 @@ jobs:
{os: windows-2019, dist: cp39-win_amd64},
{os: windows-2019, dist: cp310-win_amd64},
{os: windows-2019, dist: cp311-win_amd64},
{os: windows-2019, dist: cp312-win_amd64},

{os: windows-2019, dist: cp36-win32},
{os: windows-2019, dist: cp37-win32},
Expand Down Expand Up @@ -152,7 +156,7 @@ jobs:
- run: mkdir -p output/stim
- run: mkdir -p output/stimcirq
- run: mkdir -p output/sinter
- run: python -m pip install pybind11==2.9.2 cibuildwheel==2.11.1
- run: python -m pip install pybind11~=2.11.1 cibuildwheel~=2.16.2 setuptools wheel
- run: python -m cibuildwheel --print-build-identifiers
- run: python -m cibuildwheel --output-dir output/stim
- run: python setup.py sdist
Expand All @@ -173,7 +177,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: python -m pip install pybind11==2.9.2
- run: python -m pip install pybind11~=2.11.1 cibuildwheel~=2.16.2 setuptools wheel
- run: python setup.py sdist
- run: pip install dist/*.tar.gz
upload_dev_release_to_pypi:
Expand Down Expand Up @@ -211,7 +215,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: bazelbuild/setup-bazelisk@v1
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
bazelisk-version: 1.x
- run: bazel build :all
- run: bazel test :stim_test
build_clang:
Expand All @@ -238,7 +247,7 @@ jobs:
- run: cmake .
- run: make libstim -j 2
- run: echo -e '#include "stim.h"\nint main(int argc,const char **argv) {return !stim::find_bool_argument("test", argc, argv);}' > test.cc
- run: g++ -std=c++17 test.cc out/libstim.a -I src
- run: g++ -std=c++20 test.cc out/libstim.a -I src
- run: ./a.out test
build_lib_install:
runs-on: ubuntu-latest
Expand All @@ -249,7 +258,7 @@ jobs:
- run: make -j 2
- run: make install
- run: echo -e '#include "stim.h"\nint main(int argc,const char **argv) {return !stim::find_bool_argument("test", argc, argv);}' > test.cc
- run: g++ -std=c++17 test.cc install_dir/lib/libstim.a -I install_dir/include
- run: g++ -std=c++20 test.cc install_dir/lib/libstim.a -I install_dir/include
- run: ./a.out test
- run: echo -e "H 0 \n CNOT 0 1 \n M 0 1" | install_dir/bin/stim --sample
benchmark_windows:
Expand All @@ -258,8 +267,8 @@ jobs:
- uses: actions/checkout@v1
- uses: microsoft/[email protected]
- run: cmake .
- run: MSBuild.exe stim_benchmark.vcxproj /p:Configuration=Release /p:OutDir=msbuild_out /p:O=2
- run: msbuild_out/stim_benchmark.exe
- run: MSBuild.exe stim_perf.vcxproj /p:Configuration=Release /p:OutDir=msbuild_out /p:O=2
- run: msbuild_out/stim_perf.exe
benchmark:
runs-on: ubuntu-latest
strategy:
Expand All @@ -268,8 +277,8 @@ jobs:
steps:
- uses: actions/checkout@v1
- run: cmake . -DSIMD_WIDTH=${{ matrix.simd_width }}
- run: make stim_benchmark -j 2
- run: out/stim_benchmark
- run: make stim_perf -j 2
- run: out/stim_perf
test:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -306,7 +315,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: bazelbuild/setup-bazelisk@v1
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
bazelisk-version: 1.x
- uses: actions/setup-node@v1
with:
node-version: 16.x
Expand All @@ -318,26 +332,32 @@ jobs:
- run: diff <(python -c "import stim; stim.main(command_line_args=['help', 'gates_markdown'])") doc/gates.md
- run: diff <(python -c "import stim; stim.main(command_line_args=['help', 'formats_markdown'])") doc/result_formats.md
- run: diff <(python -c "import stim; stim.main(command_line_args=['help', 'commands_markdown'])") doc/usage_command_line.md
- run: diff <(dev/gen_known_gates_for_js.sh) glue/crumble/test/generated_gate_name_list.test.js
- run: python doc/stim.pyi
- run: npm install -g [email protected] [email protected]
- run: diff <(dev/regen_crumble_to_cpp_string_write_to_stdout.sh) src/stim/diagram/crumble_data.cc
- run: diff <(dev/compile_crumble_into_cpp_string_file.sh) src/stim/diagram/crumble_data.cc
- run: pip install -e glue/sample
- run: diff <(python dev/gen_sinter_api_reference.py -dev) doc/sinter_api.md
test_generated_file_lists_are_fresh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: dev/regen_file_lists.sh /tmp
- run: diff /tmp/benchmark_files file_lists/benchmark_files
- run: diff /tmp/python_api_files file_lists/python_api_files
- run: diff /tmp/perf_files file_lists/perf_files
- run: diff /tmp/pybind_files file_lists/pybind_files
- run: diff /tmp/source_files_no_main file_lists/source_files_no_main
- run: diff /tmp/test_files file_lists/test_files
test_pybind:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: bazelbuild/setup-bazelisk@v1
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
bazelisk-version: 1.x
- run: bazel build :stim_dev_wheel
- run: pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl
- run: pip install pytest
Expand All @@ -348,7 +368,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: bazelbuild/setup-bazelisk@v1
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
bazelisk-version: 1.x
- run: bazel build :stim_dev_wheel
- run: pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl
- run: pip install -e glue/cirq
Expand All @@ -360,7 +385,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: bazelbuild/setup-bazelisk@v1
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
bazelisk-version: 1.x
- run: bazel build :stim_dev_wheel
- run: pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl
- run: pip install -e glue/sample
Expand All @@ -373,7 +403,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: bazelbuild/setup-bazelisk@v1
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
bazelisk-version: 1.x
- run: bazel build :stim_dev_wheel
- run: pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl
- run: pip install -e glue/zx
Expand All @@ -384,7 +419,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: mymindstorm/setup-emsdk@v9
- uses: mymindstorm/setup-emsdk@v14
with:
version: 2.0.18
actions-cache-folder: 'emsdk-cache'
Expand Down
28 changes: 19 additions & 9 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cc_library(
name = "stim_lib",
srcs = SOURCE_FILES_NO_MAIN,
copts = [
"-std=c++17",
"-std=c++20",
],
includes = ["src/"],
)
Expand All @@ -53,7 +53,7 @@ cc_binary(
name = "stim",
srcs = SOURCE_FILES_NO_MAIN + glob(["src/**/main.cc"]),
copts = [
"-std=c++17",
"-std=c++20",
"-march=native",
"-O3",
],
Expand All @@ -64,7 +64,7 @@ cc_binary(
name = "stim_benchmark",
srcs = SOURCE_FILES_NO_MAIN + PERF_FILES,
copts = [
"-std=c++17",
"-std=c++20",
"-march=native",
"-O3",
],
Expand All @@ -75,14 +75,14 @@ cc_test(
name = "stim_test",
srcs = SOURCE_FILES_NO_MAIN + TEST_FILES,
copts = [
"-std=c++17",
"-std=c++20",
"-march=native",
],
data = glob(["testdata/**"]),
includes = ["src/"],
deps = [
"@gtest",
"@gtest//:gtest_main",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)

Expand All @@ -91,21 +91,31 @@ cc_binary(
srcs = SOURCE_FILES_NO_MAIN + PYBIND_FILES,
copts = [
"-O3",
"-std=c++17",
"-std=c++20",
"-fvisibility=hidden",
"-march=native",
"-DSTIM_PYBIND11_MODULE_NAME=stim",
"-DVERSION_INFO=0.0.dev0",
],
includes = ["src/"],
linkshared = 1,
deps = ["@pybind11"],
deps = ["@pybind11//:pybind11"],
)

genrule(
name = "stim_wheel_files",
srcs = ["doc/stim.pyi"],
outs = ["stim.pyi"],
cmd = "cp $(location doc/stim.pyi) $@",
)

py_wheel(
name = "stim_dev_wheel",
distribution = "stim",
requires = ["numpy"],
version = "0.0.dev0",
deps = [":stim.so"],
deps = [
":stim.so",
":stim_wheel_files",
],
)
42 changes: 23 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,37 @@
cmake_minimum_required(VERSION 3.13)
project(stim)
include_directories(src)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY out)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY out)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY out)

# Convert desired SIMD_WIDTH into machine architecture flags.
if(NOT(SIMD_WIDTH))
set(MACHINE_FLAG "-march=native")
elseif(SIMD_WIDTH EQUAL 256)
set(MACHINE_FLAG "-mavx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 128)
set(MACHINE_FLAG "-mno-avx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 64)
set(MACHINE_FLAG "-mno-avx2" "-mno-sse2")

if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|I386|ARM64)$")
if(NOT(SIMD_WIDTH))
set(MACHINE_FLAG "-march=native")
elseif(SIMD_WIDTH EQUAL 256)
set(MACHINE_FLAG "-mavx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 128)
set(MACHINE_FLAG "-mno-avx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 64)
set(MACHINE_FLAG "-mno-avx2" "-mno-sse2")
endif()
else ()
set(MACHINE_FLAG "")
endif()

# make changes to file_lists trigger a reconfigure
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS file_lists/source_files_no_main)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS file_lists/test_files)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS file_lists/benchmark_files)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS file_lists/python_api_files)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS file_lists/perf_files)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS file_lists/pybind_files)

file(STRINGS file_lists/source_files_no_main SOURCE_FILES_NO_MAIN)
file(STRINGS file_lists/test_files TEST_FILES)
file(STRINGS file_lists/benchmark_files BENCHMARK_FILES)
file(STRINGS file_lists/python_api_files PYTHON_API_FILES)
file(STRINGS file_lists/perf_files PERF_FILES)
file(STRINGS file_lists/pybind_files PYBIND_FILES)

add_executable(stim src/main.cc ${SOURCE_FILES_NO_MAIN})
if(NOT(MSVC))
Expand All @@ -63,14 +68,13 @@ endif()
install(TARGETS libstim LIBRARY DESTINATION)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/" DESTINATION "include" FILES_MATCHING PATTERN "*.h" PATTERN "*.inl")

add_executable(stim_benchmark ${SOURCE_FILES_NO_MAIN} ${BENCHMARK_FILES})
add_executable(stim_perf ${SOURCE_FILES_NO_MAIN} ${PERF_FILES})
if(NOT(MSVC))
target_compile_options(stim_benchmark PRIVATE -Wall -Wpedantic -O3 -fno-strict-aliasing ${MACHINE_FLAG})
target_link_options(stim_benchmark PRIVATE)
target_compile_options(stim_perf PRIVATE -Wall -Wpedantic -O3 -fno-strict-aliasing ${MACHINE_FLAG})
target_link_options(stim_perf PRIVATE)
else()
target_compile_options(stim_benchmark PRIVATE ${MACHINE_FLAG})
target_compile_options(stim_perf PRIVATE ${MACHINE_FLAG})
endif()
install(TARGETS stim_benchmark RUNTIME DESTINATION bin)

find_package(GTest QUIET)
if(${GTest_FOUND})
Expand All @@ -90,7 +94,7 @@ endif()
find_package(Python COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG)
if (${pybind11_FOUND} AND ${Python_FOUND})
pybind11_add_module(stim_python_bindings ${PYTHON_API_FILES} ${SOURCE_FILES_NO_MAIN})
pybind11_add_module(stim_python_bindings ${PYBIND_FILES} ${SOURCE_FILES_NO_MAIN})
set_target_properties(stim_python_bindings PROPERTIES OUTPUT_NAME stim)
add_compile_definitions(STIM_PYBIND11_MODULE_NAME=stim)
if(NOT(MSVC))
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "pybind11_bazel", version = "2.11.1")
Loading

0 comments on commit 46c32d1

Please sign in to comment.