Skip to content

Commit

Permalink
Initial version of Chromobius, at time of arXiv preprint
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Dec 14, 2023
0 parents commit bb976be
Show file tree
Hide file tree
Showing 291 changed files with 151,159 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
Language: Cpp
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 120
AlignAfterOpenBracket: AlwaysBreak
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortLambdasOnASingleLine: None
BinPackArguments: false
BinPackParameters: false

IncludeCategories:
- Regex: '^<.*>$'
Priority: 1
- Regex: '^"gtest/.*"$'
Priority: 2
- Regex: '^".*"$'
Priority: 3
...
177 changes: 177 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: ci
on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
jobs:
build_dist:
runs-on: ${{ matrix.os_dist.os }}
strategy:
fail-fast: false
matrix:
os_dist: [
{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: 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: cp310-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp311-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp312-macosx_arm64, macosarch: arm64},

# Currently disabled because in CI it gives "DLL load failed" errors I don't understand when testing the wheel.
# {os: windows-latest, dist: cp310-win_amd64},
# {os: windows-latest, dist: cp311-win_amd64},
# {os: windows-latest, dist: cp312-win_amd64},
]
env:
MACOSX_DEPLOYMENT_TARGET: "10.15"
CIBW_BUILD: "${{ matrix.os_dist.dist }}"
CIBW_ARCHS_MACOS: "${{ matrix.os_dist.macosarch }}"
CIBW_TEST_REQUIRES: pytest stim sinter pygltflib
CIBW_TEST_COMMAND: pytest {project}/src
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: python tools/overwrite_dev_versions_with_date.py
- run: mkdir -p output/stim
- run: mkdir -p output/stimcirq
- run: mkdir -p output/sinter
- run: python -m pip install pybind11~=2.11.1 cibuildwheel~=2.16.2 setuptools
- run: python -m cibuildwheel --print-build-identifiers
- run: python -m cibuildwheel --output-dir output/chromobius
- run: python setup.py sdist
- run: mv dist/* output/chromobius
- uses: actions/upload-artifact@v3
with:
name: dist
path: |
./output/chromobius/*
check_sdist_installs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: python -m pip install pybind11~=2.11.1 cibuildwheel~=2.16.2 setuptools
- run: python setup.py sdist
- run: pip install dist/*.tar.gz
run_main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: cmake .
- run: make chromobius -j 2
- run: out/chromobius --help
build_bazel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: bazelbuild/setup-bazelisk@v1
- run: bazel build :all
- run: bazel test :chromobius_test
build_clang:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- run: |
cd ..
git clone https://github.com/google/googletest.git -b release-1.12.1
mkdir googletest/build && cd googletest/build
cmake .. -DBUILD_GMOCK=OFF
make
sudo make install
- uses: egor-tensin/setup-clang@v1
with:
version: latest
platform: x64
- run: cmake . -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++
- run: cmake --build . --target chromobius chromobius_test chromobius_perf
- run: out/chromobius --help
perf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: cmake .
- run: make chromobius_perf -j 2
- run: out/chromobius_perf
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
cd ..
git clone https://github.com/google/googletest.git -b release-1.12.1
mkdir googletest/build && cd googletest/build
cmake .. -DBUILD_GMOCK=OFF
make
sudo make install
- run: cmake .
- run: make chromobius_test -j 2
- run: out/chromobius_test
test_o3:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
cd ..
git clone https://github.com/google/googletest.git -b release-1.12.1
mkdir googletest/build && cd googletest/build
cmake .. -DBUILD_GMOCK=OFF
make
sudo make install
- run: cmake . -DSIMD_WIDTH=256
- run: make chromobius_test_o3 -j 2
- run: out/chromobius_test_o3
test_generated_docs_are_fresh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: bazelbuild/setup-bazelisk@v1
- run: bazel build :chromobius_dev_wheel
- run: pip install bazel-bin/chromobius-0.0.dev0-py3-none-any.whl
- run: diff <(python tools/gen_chromobius_api_reference.py -dev) doc/chromobius_api_reference.md
- run: diff <(python tools/gen_chromobius_stub_file.py -dev) doc/chromobius.pyi
- run: python doc/chromobius.pyi
test_generated_file_lists_are_fresh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: tools/regen_file_lists.sh /tmp
- 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
- run: bazel build :chromobius_dev_wheel
- run: pip install bazel-bin/chromobius-0.0.dev0-py3-none-any.whl
- run: pip install pytest stim sinter pygltflib
- run: pytest src
- run: tools/doctest_proper.py --module chromobius
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.idea
.pytest_cache
out
__pycache__
cmake-build-debug
.cmake
CMakeFiles
CMakeCache.txt
.ninja_deps
.ninja_log
Testing
_deps
build.ninja
cmake_install.cmake
perf.data
perf.data.old
lib
bazel-bin
bazel-out
bazel-testlogs
bazel-*
python_build_chromobius
chromobius.egg-info
.clwb
wheelhouse
build
package_data
.eggs
dist
MODULE.bazel
MODULE.bazel.lock
127 changes: 127 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package(default_visibility = ["//visibility:public"])

load("@rules_python//python:packaging.bzl", "py_wheel")

SOURCE_FILES_NO_MAIN = glob(
[
"src/**/*.cc",
"src/**/*.h",
"src/**/*.inl",
],
exclude = glob([
"src/**/*.test.cc",
"src/**/*.test.h",
"src/**/*.perf.cc",
"src/**/*.perf.h",
"src/**/*.pybind.cc",
"src/**/*.pybind.h",
"src/**/main.cc",
]),
)

TEST_FILES = glob(
[
"src/**/*.test.cc",
"src/**/*.test.h",
],
)

PERF_FILES = glob(
[
"src/**/*.perf.cc",
"src/**/*.perf.h",
],
)

PYBIND_FILES = glob(
[
"src/**/*.pybind.cc",
"src/**/*.pybind.h",
],
)

cc_binary(
name = "chromobius",
srcs = SOURCE_FILES_NO_MAIN + glob(["src/**/main.cc"]),
copts = [
"-std=c++20",
"-O3",
"-DNDEBUG",
],
includes = ["src/"],
deps = [
"@pymatching//:libpymatching",
"@stim//:stim_lib",
],
)

cc_binary(
name = "chromobius_perf",
srcs = SOURCE_FILES_NO_MAIN + PERF_FILES,
copts = [
"-O3",
"-std=c++20",
"-DNDEBUG",
],
data = glob(["test_data/**"]),
includes = ["src/"],
deps = [
"@pymatching//:libpymatching",
"@stim//:stim_lib",
],
)

cc_test(
name = "chromobius_test",
srcs = SOURCE_FILES_NO_MAIN + TEST_FILES,
copts = [
"-std=c++20",
],
data = glob(["test_data/**"]),
includes = ["src/"],
deps = [
"@gtest",
"@gtest//:gtest_main",
"@pymatching//:libpymatching",
"@stim//:stim_lib",
],
)

cc_binary(
name = "chromobius.so",
srcs = SOURCE_FILES_NO_MAIN + PYBIND_FILES,
copts = [
"-O3",
"-std=c++20",
"-fvisibility=hidden",
"-DNDEBUG",
],
includes = ["src/"],
linkshared = 1,
deps = [
"@pybind11",
"@pymatching//:libpymatching",
"@stim//:stim_lib",
],
)

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

py_wheel(
name = "chromobius_dev_wheel",
distribution = "chromobius",
requires = [
"numpy",
"stim",
],
version = "0.0.dev0",
deps = [
":chromobius.so",
":chromobius_wheel_files",
],
)
Loading

0 comments on commit bb976be

Please sign in to comment.