diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2057bc7e..d2e434fd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,7 +161,7 @@ jobs: - run: mv dist/* output/stim - run: mv glue/cirq/dist/* output/stimcirq - run: mv glue/sample/dist/* output/sinter - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: dist path: | @@ -205,7 +205,7 @@ jobs: steps: - uses: actions/checkout@v1 - run: cmake . - - run: make stim + - run: make stim -j 2 - run: echo -e "H 0 \n CNOT 0 1 \n M 0 1" | out/stim --sample build_bazel: runs-on: ubuntu-latest @@ -235,7 +235,7 @@ jobs: steps: - uses: actions/checkout@v1 - run: cmake . - - run: make libstim + - 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++ test.cc out/libstim.a -I src - run: ./a.out test @@ -255,7 +255,7 @@ jobs: steps: - uses: actions/checkout@v1 - run: cmake . -DSIMD_WIDTH=${{ matrix.simd_width }} - - run: make stim_benchmark + - run: make stim_benchmark -j 2 - run: out/stim_benchmark test: runs-on: ubuntu-latest @@ -272,7 +272,7 @@ jobs: make sudo make install - run: cmake . -DSIMD_WIDTH=${{ matrix.simd_width }} - - run: make stim_test + - run: make stim_test -j 2 - run: out/stim_test test_o3: runs-on: ubuntu-latest @@ -286,24 +286,22 @@ jobs: make sudo make install - run: cmake . -DSIMD_WIDTH=256 - - run: make stim_test_o3 + - run: make stim_test_o3 -j 2 - run: out/stim_test_o3 test_generated_docs_are_fresh: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - with: - python-version: '3.7' - architecture: 'x64' - - run: pip install -e . - - run: pip install pybind11==2.9.2 && python setup.py install # Workaround for https://github.com/pypa/setuptools/issues/230 + - uses: bazelbuild/setup-bazelisk@v1 + - run: bazel build :stim_dev_wheel + - run: pip install bazel-bin/stim-dev-py3-none-any.whl - run: diff <(python glue/python/generate_api_reference.py -dev) doc/python_api_reference_vDev.md - run: diff <(python glue/python/generate_stub_file.py -dev) glue/python/src/stim/__init__.pyi - run: diff <(python glue/python/generate_stub_file.py -dev) doc/stim.pyi - - run: diff <(stim help gates_markdown) doc/gates.md - - run: diff <(stim help formats_markdown) doc/result_formats.md - - run: diff <(stim help commands_markdown) doc/usage_command_line.md + - 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: python doc/stim.pyi test_generated_file_lists_are_fresh: runs-on: ubuntu-latest @@ -319,11 +317,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - with: - python-version: '3.6' - architecture: 'x64' - - run: pip install -e . - - run: pip install pybind11==2.9.2 && python setup.py install # Workaround for https://github.com/pypa/setuptools/issues/230 + - uses: bazelbuild/setup-bazelisk@v1 + - run: bazel build :stim_dev_wheel + - run: pip install bazel-bin/stim-dev-py3-none-any.whl - run: pip install pytest - run: pytest src - run: dev/doctest_proper.py --module stim @@ -332,11 +328,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - with: - python-version: '3.6' - architecture: 'x64' - - run: pip install -e . - - run: pip install pybind11==2.9.2 && python setup.py install # Workaround for https://github.com/pypa/setuptools/issues/230 + - uses: bazelbuild/setup-bazelisk@v1 + - run: bazel build :stim_dev_wheel + - run: pip install bazel-bin/stim-dev-py3-none-any.whl - run: pip install -e glue/cirq - run: pip install pytest - run: pytest glue/cirq @@ -346,11 +340,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - with: - python-version: '3.7' - architecture: 'x64' - - run: pip install -e . - - run: pip install pybind11==2.9.2 && python setup.py install # Workaround for https://github.com/pypa/setuptools/issues/230 + - uses: bazelbuild/setup-bazelisk@v1 + - run: bazel build :stim_dev_wheel + - run: pip install bazel-bin/stim-dev-py3-none-any.whl - run: pip install -e glue/sample - run: pip install pytest pymatching fusion-blossom~=0.1.4 - run: pytest glue/sample @@ -361,11 +353,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - with: - python-version: '3.6' - architecture: 'x64' - - run: pip install -e . - - run: pip install pybind11==2.9.2 && python setup.py install # Workaround for https://github.com/pypa/setuptools/issues/230 + - uses: bazelbuild/setup-bazelisk@v1 + - run: bazel build :stim_dev_wheel + - run: pip install bazel-bin/stim-dev-py3-none-any.whl - run: pip install -e glue/zx - run: pip install pytest - run: pytest glue/zx diff --git a/dev/regen_docs.sh b/dev/regen_docs.sh index 9b83caeff..089c66b08 100755 --- a/dev/regen_docs.sh +++ b/dev/regen_docs.sh @@ -12,6 +12,6 @@ cd "$(git rev-parse --show-toplevel)" python glue/python/generate_api_reference.py -dev > doc/python_api_reference_vDev.md python glue/python/generate_stub_file.py -dev > glue/python/src/stim/__init__.pyi python glue/python/generate_stub_file.py -dev > doc/stim.pyi -stim help gates_markdown > doc/gates.md -stim help formats_markdown > doc/result_formats.md -stim help commands_markdown > doc/usage_command_line.md +python -c "import stim; stim.main(command_line_args=['help', 'gates_markdown'])" > doc/gates.md +python -c "import stim; stim.main(command_line_args=['help', 'formats_markdown'])" > doc/result_formats.md +python -c "import stim; stim.main(command_line_args=['help', 'commands_markdown'])" > doc/usage_command_line.md diff --git a/dev/regen_file_lists.sh b/dev/regen_file_lists.sh index bdda897f6..79c58716f 100755 --- a/dev/regen_file_lists.sh +++ b/dev/regen_file_lists.sh @@ -11,8 +11,6 @@ else FOLDER=$1 fi -echo "generating file lists in $FOLDER" - # Get to this script's git repo root. cd "$( dirname "${BASH_SOURCE[0]}" )" cd "$(git rev-parse --show-toplevel)" diff --git a/glue/python/src/stim/__init__.py b/glue/python/src/stim/__init__.py index bdd0bad52..59aa1d7e5 100644 --- a/glue/python/src/stim/__init__.py +++ b/glue/python/src/stim/__init__.py @@ -8,10 +8,11 @@ import stim._detect_machine_architecture as _tmp _tmp = _tmp._UNSTABLE_detect_march() -if _tmp == 'avx2': - from stim._stim_avx2 import * - from stim._stim_avx2 import _UNSTABLE_raw_gate_data, _UNSTABLE_raw_format_data, __version__ -elif _tmp == 'sse2': +# NOTE: avx2 disabled until https://github.com/quantumlib/Stim/issues/432 is fixed +# if _tmp == 'avx2': +# from stim._stim_avx2 import * +# from stim._stim_avx2 import _UNSTABLE_raw_gate_data, _UNSTABLE_raw_format_data, __version__ +if _tmp == 'avx2' or _tmp == 'sse2': from stim._stim_sse2 import * from stim._stim_sse2 import _UNSTABLE_raw_gate_data, _UNSTABLE_raw_format_data, __version__ else: diff --git a/setup.py b/setup.py index ddbf6dcad..0b0a79df2 100644 --- a/setup.py +++ b/setup.py @@ -68,18 +68,20 @@ '-DSTIM_PYBIND11_MODULE_NAME=_stim_sse2', ], ) -stim_avx2 = Extension( - 'stim._stim_avx2', - sources=RELEVANT_SOURCE_FILES, - include_dirs=[pybind11.get_include(), "src"], - language='c++', - extra_compile_args=[ - *common_compile_args, - '-msse2', - '-mavx2', - '-DSTIM_PYBIND11_MODULE_NAME=_stim_avx2', - ], -) + +# NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed +# stim_avx2 = Extension( +# 'stim._stim_avx2', +# sources=RELEVANT_SOURCE_FILES, +# include_dirs=[pybind11.get_include(), "src"], +# language='c++', +# extra_compile_args=[ +# *common_compile_args, +# '-msse2', +# '-mavx2', +# '-DSTIM_PYBIND11_MODULE_NAME=_stim_avx2', +# ], +# ) with open('glue/python/README.md', encoding='UTF-8') as f: long_description = f.read() @@ -98,7 +100,8 @@ stim_detect_machine_architecture, stim_polyfill, stim_sse2, - stim_avx2, + # NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed + # stim_avx2, ], python_requires='>=3.6.0', packages=['stim'], diff --git a/src/stim/mem/monotonic_buffer.h b/src/stim/mem/monotonic_buffer.h index 750dc5772..c92548433 100644 --- a/src/stim/mem/monotonic_buffer.h +++ b/src/stim/mem/monotonic_buffer.h @@ -56,32 +56,41 @@ struct MonotonicBuffer { std::vector> old_areas; /// Constructs an empty monotonic buffer. - MonotonicBuffer() = default; + MonotonicBuffer() : tail(), cur(), old_areas() { + } /// Constructs an empty monotonic buffer with initial capacity for its current region. MonotonicBuffer(size_t reserve) { ensure_available(reserve); } - ~MonotonicBuffer() { - for (auto &v : old_areas) { - free(v.ptr_start); + void _soft_clear() { + cur.ptr_start = nullptr; + cur.ptr_end = nullptr; + tail.ptr_start = nullptr; + tail.ptr_end = nullptr; + old_areas.clear(); + } + void _hard_clear() { + for (auto old : old_areas) { + free(old.ptr_start); } - if (cur.ptr_start) { + if (cur.ptr_start != nullptr) { free(cur.ptr_start); } - old_areas.clear(); - cur.ptr_start = cur.ptr_end = tail.ptr_start = tail.ptr_end = nullptr; + } + ~MonotonicBuffer() { + _hard_clear(); } MonotonicBuffer(MonotonicBuffer &&other) noexcept : tail(other.tail), cur(other.cur), old_areas(std::move(other.old_areas)) { - other.cur.ptr_start = nullptr; - other.cur.ptr_end = nullptr; - other.tail.ptr_start = nullptr; - other.tail.ptr_end = nullptr; + other._soft_clear(); } MonotonicBuffer(const MonotonicBuffer &other) = delete; MonotonicBuffer &operator=(MonotonicBuffer &&other) noexcept { - (*this).~MonotonicBuffer(); - new (this) MonotonicBuffer(std::move(other)); + _hard_clear(); + cur = other.cur; + tail = other.tail; + old_areas = std::move(other.old_areas); + other._soft_clear(); return *this; } @@ -89,8 +98,8 @@ struct MonotonicBuffer { /// /// Happens to keep the current contiguous memory region and free old regions. void clear() { - for (auto &v : old_areas) { - free(v.ptr_start); + for (auto old : old_areas) { + free(old.ptr_start); } old_areas.clear(); tail.ptr_end = tail.ptr_start = cur.ptr_start; @@ -99,7 +108,7 @@ struct MonotonicBuffer { /// Returns the size of memory allocated and held by this monotonic buffer (in units of sizeof(T)). size_t total_allocated() const { size_t result = cur.size(); - for (auto &old : old_areas) { + for (auto old : old_areas) { result += old.size(); } return result;