Skip to content

Commit

Permalink
Merge branch 'main' into fix_auto_dem
Browse files Browse the repository at this point in the history
  • Loading branch information
inmzhang authored May 7, 2024
2 parents 3eaf798 + fcf0949 commit bf69829
Show file tree
Hide file tree
Showing 183 changed files with 1,953 additions and 1,303 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,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 @@ -272,8 +272,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 @@ -333,8 +333,8 @@ jobs:
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:
Expand Down
39 changes: 22 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,31 @@ 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,12 +68,12 @@ 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()

find_package(GTest QUIET)
Expand All @@ -89,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
4 changes: 2 additions & 2 deletions dev/regen_file_lists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ cd "$(git rev-parse --show-toplevel)"
# LC_ALL=C forces sorting to happen by byte value
find src | grep "\\.cc$" | grep -v "\\.\(test\|perf\|pybind\)\\.cc$" | grep -v "src/main\\.cc" | LC_ALL=C sort > "${FOLDER}/source_files_no_main"
find src | grep "\\.test\\.cc$" | LC_ALL=C sort > "${FOLDER}/test_files"
find src | grep "\\.perf\\.cc$" | LC_ALL=C sort > "${FOLDER}/benchmark_files"
find src | grep "\\.pybind\\.cc$" | LC_ALL=C sort > "${FOLDER}/python_api_files"
find src | grep "\\.perf\\.cc$" | LC_ALL=C sort > "${FOLDER}/perf_files"
find src | grep "\\.pybind\\.cc$" | LC_ALL=C sort > "${FOLDER}/pybind_files"

# Regenerate 'stim.h' to include all relevant headers.
{
Expand Down
14 changes: 7 additions & 7 deletions doc/developer_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ These notes generally assume you are on a Linux system.
- [running performance benchmarks](#perf)
- [with cmake](#perf.cmake)
- [with bazel](#perf.bazel)
- [interpreting output from `stim_benchmark`](#perf.output)
- [interpreting output from `stim_perf`](#perf.output)
- [profiling with gcc and perf](#perf.profile)
- [creating a python dev environment](#venv)
- [running python unit tests](#test.pytest)
Expand Down Expand Up @@ -348,19 +348,19 @@ bazel test stim_test

```bash
cmake .
make stim_benchmark
./out/stim_benchmark
make stim_perf
./out/stim_perf
```

## <a name="perf.cmake"></a>Running performance benchmarks with bazel

```bash
bazel run stim_benchmark
bazel run stim_perf
```

## <a name="perf.output"></a>Interpreting output from `stim_benchmark`
## <a name="perf.output"></a>Interpreting output from `stim_perf`

When you run `stim_benchmark` you will see output like:
When you run `stim_perf` you will see output like:

```
[....................*....................] 460 ns (vs 450 ns) ( 21 GBits/s) simd_bits_randomize_10K
Expand All @@ -377,7 +377,7 @@ Each tick away from the center `|` is 1 decibel slower or faster (i.e. each `<`
Basically, if you see `[......*<<<<<<<<<<<<<|....................]` then something is *seriously* wrong, because the
code is running 25x slower than expected.

The benchmark binary supports a `--only=BENCHMARK_NAME` filter flag.
The `stim_perf` binary supports a `--only=BENCHMARK_NAME` filter flag.
Multiple filters can be specified by separating them with commas `--only=A,B`.
Ending a filter with a `*` turns it into a prefix filter `--only=sim_*`.

Expand Down
5 changes: 2 additions & 3 deletions file_lists/benchmark_files → file_lists/perf_files
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
src/stim/benchmark_main.perf.cc
src/stim/benchmark_util.perf.cc
src/stim/circuit/circuit.perf.cc
src/stim/gates/gates.perf.cc
src/stim/io/measure_record_reader.perf.cc
src/stim/main.perf.cc
src/stim/main_namespaced.perf.cc
src/stim/mem/simd_bit_table.perf.cc
src/stim/mem/simd_bits.perf.cc
src/stim/mem/simd_word.perf.cc
src/stim/mem/sparse_xor_vec.perf.cc
src/stim/probability_util.perf.cc
src/stim/search/graphlike/algo.perf.cc
src/stim/simulators/dem_sampler.perf.cc
src/stim/simulators/error_analyzer.perf.cc
Expand All @@ -19,4 +17,5 @@ src/stim/stabilizers/pauli_string_iter.perf.cc
src/stim/stabilizers/tableau.perf.cc
src/stim/stabilizers/tableau_iter.perf.cc
src/stim/util_bot/error_decomp.perf.cc
src/stim/util_bot/probability_util.perf.cc
src/stim/util_top/stabilizers_to_tableau.perf.cc
File renamed without changes.
7 changes: 4 additions & 3 deletions file_lists/source_files_no_main
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
src/stim.cc
src/stim/arg_parse.cc
src/stim/circuit/circuit.cc
src/stim/circuit/circuit_instruction.cc
src/stim/circuit/gate_decomposition.cc
Expand Down Expand Up @@ -66,7 +65,6 @@ src/stim/mem/bit_ref.cc
src/stim/mem/simd_util.cc
src/stim/mem/simd_word.cc
src/stim/mem/sparse_xor_vec.cc
src/stim/probability_util.cc
src/stim/search/graphlike/algo.cc
src/stim/search/graphlike/edge.cc
src/stim/search/graphlike/graph.cc
Expand All @@ -84,14 +82,17 @@ src/stim/simulators/force_streaming.cc
src/stim/simulators/graph_simulator.cc
src/stim/simulators/matched_error.cc
src/stim/simulators/sparse_rev_frame_tracker.cc
src/stim/simulators/transform_without_feedback.cc
src/stim/simulators/vector_simulator.cc
src/stim/stabilizers/flex_pauli_string.cc
src/stim/util_bot/arg_parse.cc
src/stim/util_bot/error_decomp.cc
src/stim/util_bot/probability_util.cc
src/stim/util_top/circuit_inverse_qec.cc
src/stim/util_top/circuit_inverse_unitary.cc
src/stim/util_top/circuit_to_detecting_regions.cc
src/stim/util_top/circuit_vs_amplitudes.cc
src/stim/util_top/export_crumble_url.cc
src/stim/util_top/export_qasm.cc
src/stim/util_top/export_quirk_url.cc
src/stim/util_top/simplified_circuit.cc
src/stim/util_top/transform_without_feedback.cc
13 changes: 7 additions & 6 deletions file_lists/test_files
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
src/stim.test.cc
src/stim/arg_parse.test.cc
src/stim/circuit/circuit.test.cc
src/stim/circuit/gate_decomposition.test.cc
src/stim/circuit/gate_target.test.cc
Expand Down Expand Up @@ -45,7 +44,6 @@ src/stim/mem/simd_bits_range_ref.test.cc
src/stim/mem/simd_util.test.cc
src/stim/mem/simd_word.test.cc
src/stim/mem/sparse_xor_vec.test.cc
src/stim/probability_util.test.cc
src/stim/search/graphlike/algo.test.cc
src/stim/search/graphlike/edge.test.cc
src/stim/search/graphlike/graph.test.cc
Expand All @@ -57,7 +55,6 @@ src/stim/search/hyper/graph.test.cc
src/stim/search/hyper/node.test.cc
src/stim/search/hyper/search_state.test.cc
src/stim/search/sat/wcnf.test.cc
src/stim/simulators/count_determined_measurements.test.cc
src/stim/simulators/dem_sampler.test.cc
src/stim/simulators/error_analyzer.test.cc
src/stim/simulators/error_matcher.test.cc
Expand All @@ -68,7 +65,6 @@ src/stim/simulators/matched_error.test.cc
src/stim/simulators/measurements_to_detection_events.test.cc
src/stim/simulators/sparse_rev_frame_tracker.test.cc
src/stim/simulators/tableau_simulator.test.cc
src/stim/simulators/transform_without_feedback.test.cc
src/stim/simulators/vector_simulator.test.cc
src/stim/stabilizers/flex_pauli_string.test.cc
src/stim/stabilizers/flow.test.cc
Expand All @@ -77,19 +73,24 @@ src/stim/stabilizers/pauli_string_iter.test.cc
src/stim/stabilizers/pauli_string_ref.test.cc
src/stim/stabilizers/tableau.test.cc
src/stim/stabilizers/tableau_iter.test.cc
src/stim/str_util.test.cc
src/stim/test_util.test.cc
src/stim/util_bot/arg_parse.test.cc
src/stim/util_bot/error_decomp.test.cc
src/stim/util_bot/probability_util.test.cc
src/stim/util_bot/str_util.test.cc
src/stim/util_bot/test_util.test.cc
src/stim/util_bot/twiddle.test.cc
src/stim/util_top/circuit_inverse_qec.test.cc
src/stim/util_top/circuit_inverse_unitary.test.cc
src/stim/util_top/circuit_to_detecting_regions.test.cc
src/stim/util_top/circuit_vs_amplitudes.test.cc
src/stim/util_top/circuit_vs_tableau.test.cc
src/stim/util_top/count_determined_measurements.test.cc
src/stim/util_top/export_crumble_url.test.cc
src/stim/util_top/export_qasm.test.cc
src/stim/util_top/export_quirk_url.test.cc
src/stim/util_top/has_flow.test.cc
src/stim/util_top/simplified_circuit.test.cc
src/stim/util_top/stabilizers_to_tableau.test.cc
src/stim/util_top/stabilizers_vs_amplitudes.test.cc
src/stim/util_top/transform_without_feedback.test.cc
src/stim_included_twice.test.cc
2 changes: 1 addition & 1 deletion glue/javascript/common.js.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <emscripten/val.h>

#include "stim/probability_util.h"
#include "stim/util_bot/probability_util.h"

template <typename T>
emscripten::val vec_to_js_array(const std::vector<T> &items) {
Expand Down
31 changes: 22 additions & 9 deletions glue/python/src/stim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

import stim._detect_machine_architecture as _tmp


_tmp = _tmp._UNSTABLE_detect_march()
# 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_format_data, __version__
if _tmp == 'avx2' or _tmp == 'sse2':
from stim._stim_sse2 import *
from stim._stim_sse2 import _UNSTABLE_raw_format_data, __version__
else:
from stim._stim_polyfill import *
try:
# NOTE: avx2 disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# if _tmp == 'avx2':
# from stim._stim_avx2 import _UNSTABLE_raw_format_data, __version__
# from stim._stim_avx2 import *
if _tmp == 'avx2' or _tmp == 'sse2':
from stim._stim_sse2 import _UNSTABLE_raw_format_data, __version__
from stim._stim_sse2 import *
else:
from stim._stim_polyfill import _UNSTABLE_raw_format_data, __version__
from stim._stim_polyfill import *
except ModuleNotFoundError:
from stim._stim_polyfill import _UNSTABLE_raw_format_data, __version__
from stim._stim_polyfill import *

del _tmp


Expand All @@ -26,10 +32,12 @@ def _pytest_pycharm_pybind_repr_bug_workaround(cls):
cls.__repr__ = lambda e: f(e)
cls.__repr__.__doc__ = f.__doc__
_pytest_pycharm_pybind_repr_bug_workaround(Circuit)
_pytest_pycharm_pybind_repr_bug_workaround(CircuitErrorLocation)
_pytest_pycharm_pybind_repr_bug_workaround(CircuitErrorLocationStackFrame)
_pytest_pycharm_pybind_repr_bug_workaround(CircuitInstruction)
_pytest_pycharm_pybind_repr_bug_workaround(CircuitRepeatBlock)
_pytest_pycharm_pybind_repr_bug_workaround(CircuitTargetsInsideInstruction)
_pytest_pycharm_pybind_repr_bug_workaround(CompiledDemSampler)
_pytest_pycharm_pybind_repr_bug_workaround(CompiledDetectorSampler)
_pytest_pycharm_pybind_repr_bug_workaround(CompiledMeasurementSampler)
_pytest_pycharm_pybind_repr_bug_workaround(CompiledMeasurementsToDetectionEventsConverter)
Expand All @@ -39,10 +47,15 @@ def _pytest_pycharm_pybind_repr_bug_workaround(cls):
_pytest_pycharm_pybind_repr_bug_workaround(DemTargetWithCoords)
_pytest_pycharm_pybind_repr_bug_workaround(DetectorErrorModel)
_pytest_pycharm_pybind_repr_bug_workaround(ExplainedError)
_pytest_pycharm_pybind_repr_bug_workaround(FlipSimulator)
_pytest_pycharm_pybind_repr_bug_workaround(FlippedMeasurement)
_pytest_pycharm_pybind_repr_bug_workaround(Flow)
_pytest_pycharm_pybind_repr_bug_workaround(GateData)
_pytest_pycharm_pybind_repr_bug_workaround(GateTarget)
_pytest_pycharm_pybind_repr_bug_workaround(GateTargetWithCoords)
_pytest_pycharm_pybind_repr_bug_workaround(PauliString)
_pytest_pycharm_pybind_repr_bug_workaround(PauliStringIterator)
_pytest_pycharm_pybind_repr_bug_workaround(Tableau)
_pytest_pycharm_pybind_repr_bug_workaround(TableauIterator)
_pytest_pycharm_pybind_repr_bug_workaround(TableauSimulator)
del _pytest_pycharm_pybind_repr_bug_workaround
23 changes: 14 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
import sys
import platform

from setuptools import setup, Extension
import glob
Expand All @@ -27,7 +27,7 @@

__version__ = '1.14.dev0'

if sys.platform.startswith('win'):
if platform.system().startswith('Win'):
common_compile_args = [
'/std:c++20',
'/O2',
Expand Down Expand Up @@ -97,6 +97,17 @@
with open('glue/python/README.md', encoding='UTF-8') as f:
long_description = f.read()

def _get_extensions():
archs=["x86", "i686", "i386", "amd64"]
if any(_ext in platform.processor().lower() for _ext in archs):
# NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# stim_avx2,
return [stim_detect_machine_architecture, stim_polyfill,
# stim_avx2,
stim_sse2]
else:
return [stim_detect_machine_architecture, stim_polyfill]

setup(
name='stim',
version=__version__,
Expand All @@ -107,13 +118,7 @@
description='A fast library for analyzing with quantum stabilizer circuits.',
long_description=long_description,
long_description_content_type='text/markdown',
ext_modules=[
stim_detect_machine_architecture,
stim_polyfill,
stim_sse2,
# NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# stim_avx2,
],
ext_modules=_get_extensions(),
python_requires='>=3.6.0',
packages=['stim'],
package_dir={'stim': 'glue/python/src/stim'},
Expand Down
Loading

0 comments on commit bf69829

Please sign in to comment.