Skip to content

Commit

Permalink
Disable avx2 python extension due to colab crash (#433)
Browse files Browse the repository at this point in the history
- This is a precaution because presumably other people have environments like colab's. Ideally I would understand why the crash is happening, but currently I don't.
- Make various tweaks and improvements to CI

Related issue: #432
  • Loading branch information
Strilanc authored Nov 19, 2022
1 parent ee7dc78 commit caf2a72
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 72 deletions.
58 changes: 24 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions dev/regen_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions dev/regen_file_lists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
9 changes: 5 additions & 4 deletions glue/python/src/stim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 16 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'],
Expand Down
41 changes: 25 additions & 16 deletions src/stim/mem/monotonic_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,50 @@ struct MonotonicBuffer {
std::vector<PointerRange<T>> 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;
}

/// Invalidates all previous data and resets the class into a clean state.
///
/// 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;
Expand All @@ -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;
Expand Down

0 comments on commit caf2a72

Please sign in to comment.