diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6e41e75..991de55c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,510 +23,11 @@ on: branches: - main jobs: - build_dist: - runs-on: ${{ matrix.os_dist.os }} - strategy: - fail-fast: false - matrix: - os_dist: [ - {os: ubuntu-24.04, dist: cp310-manylinux_x86_64}, - {os: ubuntu-24.04, dist: cp311-manylinux_x86_64}, - {os: ubuntu-24.04, dist: cp312-manylinux_x86_64}, - {os: ubuntu-24.04, dist: cp313-manylinux_x86_64}, - {os: ubuntu-24.04, dist: cp314-manylinux_x86_64}, - - # manylinux_i686 disabled because scipy isn't prebuilt and fails to build. - # - # The actual error seen in github actions: - # - # numpy.distutils.system_info.NotFoundError: No BLAS/LAPACK - # libraries found. To build Scipy from sources, BLAS & LAPACK - # libraries need to be installed. - # - #{os: ubuntu-latest, dist: cp310-manylinux_i686}, - - # pypy manylinux builds disabled because scipy isn't prebuilt and fails to build. - # - # The actual error seen in github actions: - # - # numpy.distutils.system_info.NotFoundError: No BLAS/LAPACK - # libraries found. To build Scipy from sources, BLAS & LAPACK - # libraries need to be installed. - # - # {os: ubuntu-latest, dist: pp39-manylinux_x86_64}, - # {os: ubuntu-latest, dist: pp39-manylinux_i686}, - - # musllinux builds disabled because scipy isn't prebuilt and fails to build. - # - # The actual error seen in github actions: - # - # numpy.distutils.system_info.NotFoundError: No BLAS/LAPACK - # libraries found. To build Scipy from sources, BLAS & LAPACK - # libraries need to be installed. - # - # {os: ubuntu-latest, dist: cp310-musllinux_x86_64}, - # {os: ubuntu-latest, dist: cp310-musllinux_i686}, - - {os: macos-14, dist: cp310-macosx_x86_64, macosarch: x86_64}, - {os: macos-14, dist: cp311-macosx_x86_64, macosarch: x86_64}, - {os: macos-14, dist: cp312-macosx_x86_64, macosarch: x86_64}, - {os: macos-14, dist: cp313-macosx_x86_64, macosarch: x86_64}, - {os: macos-14, dist: cp314-macosx_x86_64, macosarch: x86_64}, - - {os: macos-14, dist: cp310-macosx_arm64, macosarch: arm64}, - {os: macos-14, dist: cp311-macosx_arm64, macosarch: arm64}, - {os: macos-14, dist: cp312-macosx_arm64, macosarch: arm64}, - {os: macos-14, dist: cp313-macosx_arm64, macosarch: arm64}, - {os: macos-14, dist: cp314-macosx_arm64, macosarch: arm64}, - - # pypy OSX builds disabled because numpy isn't prebuilt and fails to build. - # - # The actual error seen in github actions: - # - # RuntimeError: Found /usr/lib/libcblas.dylib, but that file is a - # symbolic link to the MacOS Accelerate framework, which is not - # supported by NumPy. You must configure the build to use a - # different optimized library, or disable the use of optimized - # BLAS and LAPACK by setting the environment variables - # NPY_BLAS_ORDER="" and NPY_LAPACK_ORDER="" before building NumPy. - # - # {os: macOS-10.15, dist: pp39-macosx_x86_64}, - - {os: windows-2025, dist: cp310-win_amd64}, - {os: windows-2025, dist: cp311-win_amd64}, - {os: windows-2025, dist: cp312-win_amd64}, - {os: windows-2025, dist: cp313-win_amd64}, - {os: windows-2025, dist: cp314-win_amd64}, - - # cp310-win32 disabled because numpy isn't prebuilt and fails to build. - # - # The actual error seen in github actions: - # - # CCompiler_spawn() got an unexpected keyword argument 'env' - # - # {os: windows-2025, dist: cp310-win32}, - ] - env: - CIBW_BUILD: "${{ matrix.os_dist.dist }}" - CIBW_ARCHS_MACOS: "${{ matrix.os_dist.macosarch }}" - CIBW_TEST_REQUIRES: cirq-core pytest - CIBW_TEST_COMMAND: pytest {project}/src {project}/glue/cirq && stim help - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - run: python dev/overwrite_dev_versions_with_date.py - - run: python -m pip install pybind11~=2.11.1 cibuildwheel~=3.3.1 setuptools wheel - - run: python -m cibuildwheel --print-build-identifiers - - run: python -m cibuildwheel --output-dir dist - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "dist-stim-${{ matrix.os_dist.os }}-${{ matrix.os_dist.dist }}-${{ matrix.os_dist.macosarch }}" - path: dist/* - build_sdist: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - run: python -m pip install setuptools pybind11~=2.11.1 - - run: python dev/overwrite_dev_versions_with_date.py - - run: mkdir output - - run: python setup.py sdist - - run: cd glue/cirq && python setup.py sdist - - run: cd glue/cirq && python setup.py bdist_wheel - - run: cd glue/sample && python setup.py sdist - - run: cd glue/sample && python setup.py bdist_wheel - - run: cd glue/stimflow && python setup.py sdist - - run: cd glue/stimflow && python setup.py bdist_wheel - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "dist-sinter" - path: glue/sample/dist/*.tar.gz - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "bdist-sinter" - path: glue/sample/dist/*.whl - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "dist-stimcirq" - path: glue/cirq/dist/*.tar.gz - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "bdist-stimcirq" - path: glue/cirq/dist/*.whl - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "dist-stimflow" - path: glue/stimflow/dist/*.tar.gz - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "bdist-stimflow" - path: glue/stimflow/dist/*.whl - - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 - with: - name: "dist-stim-sdist" - path: dist/*.tar.gz - check_sdist_installs_stim: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - run: python -m pip install pybind11~=2.11.1 cibuildwheel~=3.3.1 setuptools wheel - - run: python setup.py sdist - - run: pip install dist/*.tar.gz - check_sdist_installs_sinter: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - run: python -m pip install setuptools - - run: cd glue/sample && python setup.py sdist - - run: pip install glue/sample/dist/* - - run: python -c "import sinter" - check_sdist_installs_stimflow: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - run: python -m pip install setuptools - - run: cd glue/stimflow && python setup.py sdist - - run: pip install glue/stimflow/dist/* - - run: python -c "import stimflow" - merge_upload_artifacts: - needs: ["build_dist", "build_sdist"] - runs-on: ubuntu-24.04 - steps: - - name: Merge Artifacts - uses: actions/upload-artifact/merge@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4 - with: - name: dist-stim - pattern: dist-stim-* - upload_dev_release_to_pypi: - needs: ["merge_upload_artifacts"] - if: github.ref == 'refs/heads/main' - runs-on: ubuntu-24.04 - steps: - - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 - with: - name: dist-stim - path: dist-stim - - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 - with: - name: dist-stimcirq - path: dist-stimcirq - - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 - with: - name: dist-sinter - path: dist-sinter - - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 - with: - name: dist-stimflow - path: dist-stimflow - - uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1 - with: - user: __token__ - packages_dir: dist-stim - password: ${{ secrets.pypi_token_stim }} - - uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1 - with: - user: __token__ - packages_dir: dist-stimcirq - password: ${{ secrets.pypi_token_stimcirq }} - - uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1 - with: - user: __token__ - packages_dir: dist-sinter - password: ${{ secrets.pypi_token_sinter }} - - uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1 - with: - user: __token__ - packages_dir: dist-stimflow - password: ${{ secrets.pypi_token_stimflow }} - run_main: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1 - - run: cmake . - - 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-24.04 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - 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_stim_test: - runs-on: 'ubuntu-24.04' - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # 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@ef434b41eb33a70396fb336b1bae39c76d740c3d # v1 - with: - version: latest - platform: x64 - - run: cmake . -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++ - - run: cmake --build . --target stim_test - build_clang_stim: - runs-on: 'ubuntu-24.04' - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # 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@ef434b41eb33a70396fb336b1bae39c76d740c3d # v1 - with: - version: latest - platform: x64 - - run: cmake . -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++ - - run: cmake --build . --target stim - build_clang_stim_perf: - runs-on: 'ubuntu-24.04' - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # 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@ef434b41eb33a70396fb336b1bae39c76d740c3d # v1 - with: - version: latest - platform: x64 - - run: cmake . -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++ - - run: cmake --build . --target stim_perf - build_lib: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1 - - 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++20 test.cc out/libstim.a -I src - - run: ./a.out test - build_lib_install: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1 - - run: mkdir install_dir - - run: cmake . -DCMAKE_INSTALL_PREFIX=install_dir - - 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++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: + test_repro: runs-on: windows-2025 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1 - - uses: microsoft/setup-msbuild@c26a08ba26249b81327e26f6ef381897b6a8754d # v1.0.2 - - run: cmake . - - 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-24.04 - strategy: - matrix: - simd_width: [64, 128, 256] - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1 - - run: cmake . -DSIMD_WIDTH=${{ matrix.simd_width }} - - run: make stim_perf -j 2 - - run: out/stim_perf - test: - runs-on: ubuntu-24.04 - strategy: - matrix: - simd_width: [64, 128, 256] - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # 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=${{ matrix.simd_width }} - - run: make stim_test -j 2 - - run: out/stim_test - test_o3: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # 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 stim_test_o3 -j 2 - - run: out/stim_test_o3 - test_generated_docs_are_fresh: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - with: - bazelisk-cache: true - disk-cache: ${{ github.workflow }} - repository-cache: true - bazelisk-version: 1.x - - uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e # v1 - with: - node-version: 16.x - - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6 - with: - python-version: '3.13' - - run: bazel build :stim_dev_wheel - - run: pip install bazel-bin/stim-0.0.dev0-py3-none-any.whl - - run: diff <(python dev/gen_stim_api_reference.py -dev) doc/python_api_reference_vDev.md - - run: diff <(python dev/gen_stim_stub_file.py -dev) glue/python/src/stim/__init__.pyi - - run: diff <(python dev/gen_stim_stub_file.py -dev) doc/stim.pyi - - 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 rollup@3.21.2 uglify-js@3.17.4 - - 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 - - run: pip install -e glue/stimflow - - run: diff <(python glue/stimflow/tools/gen_api_reference.py -dev) glue/stimflow/doc/api.md - test_generated_file_lists_are_fresh: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - run: dev/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-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - 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 - - run: pytest src - - run: dev/doctest_proper.py --module stim - test_stimcirq: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - 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 - - run: pip install pytest - - run: pytest glue/cirq - - run: dev/doctest_proper.py --module stimcirq --import cirq sympy - test_stimflow: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - 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/stimflow - - run: pip install pytest - - run: pytest glue/stimflow - - run: dev/doctest_proper.py --module stimflow --suppress_examples_warning_for stimflow.str_svg stimflow.str_html stimflow.Viewable3dModelGLTF - test_sinter: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - 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 - - run: pip install pytest pymatching fusion-blossom~=0.1.4 mwpf~=0.1.5 - - run: pytest glue/sample - - run: dev/doctest_proper.py --module sinter - - run: sinter help - test_stimzx: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 - - uses: bazel-contrib/setup-bazel@e403ad507104847c3539436f64a9e9eecc73eeec # 0.8.5 - 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 - - run: pip install pytest - - run: pytest glue/zx - - run: dev/doctest_proper.py --module stimzx - test_stimjs: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14 - with: - version: 4.0.1 - actions-cache-folder: 'emsdk-cache' - - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4 - with: - node-version: 18.x - - run: npm install - - run: bash glue/javascript/build_wasm.sh - - run: node puppeteer_run_tests.js - test_crumble: - runs-on: ubuntu-24.04 steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - - uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3 - with: - node-version: 16 - - run: node glue/crumble/run_tests_headless.js + - uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3 + - run: pip install stim~=1.17.dev pytest + - run: pytest --verbose --capture=no mock.py + - run: pytest --verbose --capture=no src diff --git a/glue/stimflow/src/stimflow/_chunk/_chunk_builder_test.py b/glue/stimflow/src/stimflow/_chunk/_chunk_builder_test.py index 968a1e16..7b5c7779 100644 --- a/glue/stimflow/src/stimflow/_chunk/_chunk_builder_test.py +++ b/glue/stimflow/src/stimflow/_chunk/_chunk_builder_test.py @@ -311,3 +311,31 @@ def test_partial_observable_include_memory_experiment(): assert np.count_nonzero(dets) == 0 assert 200 <= np.count_nonzero(obs[:, 0]) <= 300 # Some measurements included in partial X obs assert np.count_nonzero(obs[:, 1]) == 0 # No measurements included in partial Z obs + + +def test_auto_obs(): + builder = stimflow.ChunkBuilder(allowed_qubits=[0, 1]) + builder.append("R", [0]) + builder.add_flow( + start="auto", + end=stimflow.PauliMap({0: 'Z', 1: 'Z'}, obs_name='test'), + ) + builder.add_flow( + start=stimflow.PauliMap({1: 'Z'}, obs_name='test2'), + end="auto", + ) + chunk = builder.finish_chunk() + chunk.verify() + + assert chunk.flows == ( + stimflow.Flow( + start=stimflow.PauliMap({1: 'Z'}, obs_name='test'), + end=stimflow.PauliMap({0: 'Z', 1: 'Z'}, obs_name='test'), + center=0.5, + ), + stimflow.Flow( + start=stimflow.PauliMap({1: 'Z'}, obs_name='test2'), + end=stimflow.PauliMap({1: 'Z'}, obs_name='test2'), + center=1, + ), + ) diff --git a/glue/stimflow/src/stimflow/_chunk/_flow_util.py b/glue/stimflow/src/stimflow/_chunk/_flow_util.py index 96bb3f83..8032066d 100644 --- a/glue/stimflow/src/stimflow/_chunk/_flow_util.py +++ b/glue/stimflow/src/stimflow/_chunk/_flow_util.py @@ -29,7 +29,7 @@ def _solve_auto_flow_starts( except ValueError: failure_out.append(flow) continue - start = PauliMap({i2q[q]: "_XYZ"[stim_start[q]] for q in stim_start.pauli_indices()}) + start = PauliMap({i2q[q]: "_XYZ"[stim_start[q]] for q in stim_start.pauli_indices()}, obs_name=flow.end.obs_name) new_flows.append(flow.with_edits(start=start)) return new_flows @@ -43,7 +43,7 @@ def _solve_auto_flow_ends( failure_out: list[Flow], ) -> list[Flow]: - num_qubits = circuit.num_qubits + num_qubits = max(q2i.values(), default=-1) + 1 i2q = {i: q for q, i in q2i.items()} new_flows = [] @@ -54,7 +54,7 @@ def _solve_auto_flow_ends( except ValueError: failure_out.append(flow) continue - end = PauliMap({i2q[q]: "_XYZ"[stim_end[q]] for q in stim_end.pauli_indices()}) + end = PauliMap({i2q[q]: "_XYZ"[stim_end[q]] for q in stim_end.pauli_indices()}, obs_name=flow.start.obs_name) new_flows.append(flow.with_edits(end=end)) return new_flows diff --git a/glue/stimflow/src/stimflow/_chunk/_stabilizer_code.py b/glue/stimflow/src/stimflow/_chunk/_stabilizer_code.py index 8f10bf8b..bde5e965 100644 --- a/glue/stimflow/src/stimflow/_chunk/_stabilizer_code.py +++ b/glue/stimflow/src/stimflow/_chunk/_stabilizer_code.py @@ -269,7 +269,7 @@ def x_basis_subset(self) -> StabilizerCode: def z_basis_subset(self) -> StabilizerCode: return StabilizerCode( - stabilizers=self.stabilizers.with_only_x_tiles(), + stabilizers=self.stabilizers.with_only_z_tiles(), logicals=self.list_pure_basis_observables("Z"), ) diff --git a/glue/stimflow/src/stimflow/_core/_flow.py b/glue/stimflow/src/stimflow/_core/_flow.py index d29443ed..6beda72f 100644 --- a/glue/stimflow/src/stimflow/_core/_flow.py +++ b/glue/stimflow/src/stimflow/_core/_flow.py @@ -209,14 +209,21 @@ def __str__(self) -> str: return result def __repr__(self): - return ( - f"stimflow.Flow(start={self.start!r}, " - f"end={self.end!r}, " - f"measurement_indices={self.measurement_indices!r}, " - f"flags={self.flags!r}, " - f"center={self.center!r}, " - f"sign={self.sign!r}" - ) + lines = ["stimflow.Flow("] + if self.start: + lines.append(f"start={self.start!r},") + if self.end: + lines.append(f"end={self.end!r},") + if self.measurement_indices: + lines.append(f"measurement_indices={self.measurement_indices!r},") + if self.flags: + lines.append(f"flags={self.flags!r},") + if self.center is not None: + lines.append(f"center={self.center!r},") + if self.sign is not None: + lines.append(f"sign={self.sign!r},") + lines.append(")") + return '\n'.join(lines) def with_xz_flipped(self) -> Flow: return self.with_edits(start=self.start.with_xz_flipped(), end=self.end.with_xz_flipped()) diff --git a/mock.py b/mock.py new file mode 100644 index 00000000..174dd830 --- /dev/null +++ b/mock.py @@ -0,0 +1,26 @@ +import sys + +import stim +import numpy as np + + +def test_x(): + print("TEST PROGRESSION: START", file=sys.stderr) + circuit = stim.Circuit( + """ + H 0 1 + CX 0 2 1 3 + MPP X0*X1 Y0*Y1 Z0*Z1 + """ + ) + print("TEST PROGRESSION: A", file=sys.stderr) + aa = circuit.reference_sample() + print("TEST PROGRESSION: B", file=sys.stderr) + bb = circuit.reference_sample() + print("TEST PROGRESSION: C", file=sys.stderr) + np.testing.assert_array_equal(aa, bb) + print("TEST PROGRESSION: D", file=sys.stderr) + + +if __name__ == '__main__': + test_x() diff --git a/src/stim/circuit/circuit_pybind_test.py b/src/stim/circuit/circuit_pybind_test.py index be2c0544..c61282f5 100644 --- a/src/stim/circuit/circuit_pybind_test.py +++ b/src/stim/circuit/circuit_pybind_test.py @@ -13,6 +13,7 @@ # limitations under the License. import io import pathlib +import sys import tempfile from typing import cast @@ -1497,14 +1498,18 @@ def test_num_ticks(): def test_reference_sample(): + print("TEST PROGRESSION: A", file=sys.stderr) circuit = stim.Circuit( """ H 0 CNOT 0 1 """ ) + print("TEST PROGRESSION: B", file=sys.stderr) ref = circuit.reference_sample() + print("TEST PROGRESSION: C", file=sys.stderr) assert len(ref) == 0 + print("TEST PROGRESSION: D", file=sys.stderr) circuit = stim.Circuit( """ H 0 1 @@ -1512,16 +1517,27 @@ def test_reference_sample(): MPP X0*X1 Y0*Y1 Z0*Z1 """ ) + print("TEST PROGRESSION: E", file=sys.stderr) np.testing.assert_array_equal(circuit.reference_sample(), circuit.reference_sample()) + print("TEST PROGRESSION: F", file=sys.stderr) assert np.sum(circuit.reference_sample()) % 2 == 1 + print("TEST PROGRESSION: G", file=sys.stderr) circuit.append("X", (i for i in range(0, 100, 2))) + print("TEST PROGRESSION: H", file=sys.stderr) circuit.append("M", (i for i in range(100))) + print("TEST PROGRESSION: I", file=sys.stderr) ref_sample = circuit.reference_sample(bit_packed=True) + print("TEST PROGRESSION: J", file=sys.stderr) unpacked = np.unpackbits(ref_sample, bitorder="little") + print("TEST PROGRESSION: K", file=sys.stderr) expected = circuit.reference_sample(bit_packed=False) + print("TEST PROGRESSION: L", file=sys.stderr) expected_padded = np.zeros_like(unpacked) + print("TEST PROGRESSION: M", file=sys.stderr) expected_padded[:len(expected)] = expected + print("TEST PROGRESSION: N", file=sys.stderr) np.testing.assert_array_equal(unpacked, expected_padded) + print("TEST PROGRESSION: O", file=sys.stderr) def test_max_mix_depolarization_is_allowed_in_dem_conversion_without_args(): diff --git a/src/stim/simulators/frame_simulator_pybind_test.py b/src/stim/simulators/frame_simulator_pybind_test.py index 4beddc4c..6b59a227 100644 --- a/src/stim/simulators/frame_simulator_pybind_test.py +++ b/src/stim/simulators/frame_simulator_pybind_test.py @@ -587,8 +587,6 @@ def test_generate_bernoulli_samples(): assert np.all(v == 0) sim.generate_bernoulli_samples(256 - 101, p=1, bit_packed=True, out=v[1:-11]) - for k in v: - print(k) assert np.all(v[1:-12] == 0xFF) assert v[-12] == 7 assert np.all(v[-11:] == 0)