Skip to content

Commit

Permalink
Version 1.12.1
Browse files Browse the repository at this point in the history
- Fix `HERALDED_PAULI_CHANNEL_1` targeting the wrong qubits
    - Was targeting by target offset instead of target value
- Add python 3.12 wheels
  • Loading branch information
Strilanc committed Dec 1, 2023
1 parent 1179fc3 commit 275baeb
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 37 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
{os: ubuntu-latest, dist: cp39-manylinux_x86_64},
{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: ubuntu-latest, dist: cp36-manylinux_i686},
{os: ubuntu-latest, dist: cp37-manylinux_i686},
Expand Down Expand Up @@ -92,11 +93,13 @@ jobs:
{os: macos-latest, dist: cp39-macosx_x86_64, macosarch: 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: cp38-macosx_arm64, macosarch: arm64},
{os: macos-latest, dist: cp39-macosx_arm64, macosarch: arm64},
{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},

# pypy OSX builds disabled because numpy isn't prebuilt and fails to build.
#
Expand All @@ -119,6 +122,7 @@ jobs:
{os: windows-2019, dist: cp39-win_amd64},
{os: windows-2019, dist: cp310-win_amd64},
{os: windows-2019, dist: cp311-win_amd64},
{os: windows-2019, dist: cp312-win_amd64},

{os: windows-2019, dist: cp36-win32},
{os: windows-2019, dist: cp37-win32},
Expand Down Expand Up @@ -152,7 +156,7 @@ jobs:
- run: mkdir -p output/stim
- run: mkdir -p output/stimcirq
- run: mkdir -p output/sinter
- run: python -m pip install pybind11==2.9.2 cibuildwheel==2.11.1
- run: python -m pip install pybind11~=2.11.1 cibuildwheel~=2.16.2 setuptools wheel
- run: python -m cibuildwheel --print-build-identifiers
- run: python -m cibuildwheel --output-dir output/stim
- run: python setup.py sdist
Expand All @@ -173,7 +177,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: python -m pip install pybind11==2.9.2
- run: python -m pip install pybind11~=2.11.1 cibuildwheel~=2.16.2 setuptools wheel
- run: python setup.py sdist
- run: pip install dist/*.tar.gz
upload_dev_release_to_pypi:
Expand Down
2 changes: 1 addition & 1 deletion doc/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"1.12.0\n"
"1.12.1\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion glue/cirq/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
with open('README.md', encoding='UTF-8') as f:
long_description = f.read()

__version__ = '1.12.0'
__version__ = '1.12.1'

setup(
name='stimcirq',
Expand Down
2 changes: 1 addition & 1 deletion glue/cirq/stimcirq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.12.0'
__version__ = '1.12.1'
from ._cirq_to_stim import cirq_circuit_to_stim_circuit
from ._cx_swap_gate import CXSwapGate
from ._det_annotation import DetAnnotation
Expand Down
2 changes: 1 addition & 1 deletion glue/sample/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
with open('requirements.txt', encoding='UTF-8') as f:
requirements = f.read().splitlines()

__version__ = '1.12.0'
__version__ = '1.12.1'

setup(
name='sinter',
Expand Down
2 changes: 1 addition & 1 deletion glue/sample/src/sinter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.12.0'
__version__ = '1.12.1'

from sinter._anon_task_stats import (
AnonTaskStats,
Expand Down
2 changes: 1 addition & 1 deletion glue/zx/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
with open('README.md', encoding='UTF-8') as f:
long_description = f.read()

__version__ = '1.12.0'
__version__ = '1.12.1'

setup(
name='stimzx',
Expand Down
2 changes: 1 addition & 1 deletion glue/zx/stimzx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.12.0'
__version__ = '1.12.1'
from ._external_stabilizer import (
ExternalStabilizer,
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
HEADER_FILES = glob.glob("src/**/*.h", recursive=True) + glob.glob("src/**/*.inl", recursive=True)
RELEVANT_SOURCE_FILES = sorted(set(ALL_SOURCE_FILES) - set(TEST_FILES + PERF_FILES + MAIN_FILES + MUX_SOURCE_FILES))

__version__ = '1.12.0'
__version__ = '1.12.1'

if sys.platform.startswith('win'):
common_compile_args = [
Expand Down
9 changes: 5 additions & 4 deletions src/stim/simulators/frame_simulator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,17 @@ void FrameSimulator<W>::do_HERALDED_PAULI_CHANNEL_1(const CircuitInstruction &in
RareErrorIterator::for_samples(t, nt * batch_size, rng, [&](size_t s) {
auto shot = s % batch_size;
auto target = s / batch_size;
auto qubit = inst.targets[target].qubit_value();
m_record.storage[m_record.stored + target][shot] = 1;

double p = dist(rng) * t;
if (p < hx) {
x_table[target][shot] ^= 1;
x_table[qubit][shot] ^= 1;
} else if (p < hx + hz) {
z_table[target][shot] ^= 1;
z_table[qubit][shot] ^= 1;
} else if (p < hx + hz + hy) {
x_table[target][shot] ^= 1;
z_table[target][shot] ^= 1;
x_table[qubit][shot] ^= 1;
z_table[qubit][shot] ^= 1;
}
});

Expand Down
66 changes: 66 additions & 0 deletions src/stim/simulators/frame_simulator.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1610,3 +1610,69 @@ TEST_EACH_WORD_SIZE_W(FrameSimulator, heralded_pauli_channel_1_statistics, {
EXPECT_NEAR(bins[6] / (double)n, 0.25, 0.04);
EXPECT_NEAR(bins[7] / (double)n, 0.15, 0.04);
})

TEST_EACH_WORD_SIZE_W(FrameSimulator, heralded_erase_statistics_offset_by_2, {
auto circuit = Circuit(R"CIRCUIT(
MXX 2 3
MZZ 2 3
HERALDED_ERASE(0.1) 2
MXX 2 3
MZZ 2 3
DETECTOR rec[-1] rec[-4]
DETECTOR rec[-2] rec[-5]
DETECTOR rec[-3]
)CIRCUIT");
size_t n;
std::array<size_t, 8> bins{};
FrameSimulator<W> sim(
circuit.compute_stats(), FrameSimulatorMode::STORE_DETECTIONS_TO_MEMORY, 1024, INDEPENDENT_TEST_RNG());
for (n = 0; n < 1024 * 256; n += 1024) {
sim.reset_all();
sim.do_circuit(circuit);
auto sample = sim.det_record.storage.transposed();
for (size_t k = 0; k < 1024; k++) {
bins[sample[k].u8[0]]++;
}
}
EXPECT_NEAR(bins[0] / (double)n, 0.9, 0.05);
EXPECT_EQ(bins[1], 0);
EXPECT_EQ(bins[2], 0);
EXPECT_EQ(bins[3], 0);
EXPECT_NEAR(bins[4] / (double)n, 0.025, 0.02);
EXPECT_NEAR(bins[5] / (double)n, 0.025, 0.02);
EXPECT_NEAR(bins[6] / (double)n, 0.025, 0.02);
EXPECT_NEAR(bins[7] / (double)n, 0.025, 0.02);
})

TEST_EACH_WORD_SIZE_W(FrameSimulator, heralded_pauli_channel_1_statistics_offset_by_2, {
auto circuit = Circuit(R"CIRCUIT(
MXX 2 3
MZZ 2 3
HERALDED_PAULI_CHANNEL_1(0.05, 0.10, 0.15, 0.25) 2
MXX 2 3
MZZ 2 3
DETECTOR rec[-1] rec[-4]
DETECTOR rec[-2] rec[-5]
DETECTOR rec[-3]
)CIRCUIT");
size_t n;
std::array<size_t, 8> bins{};
FrameSimulator<W> sim(
circuit.compute_stats(), FrameSimulatorMode::STORE_DETECTIONS_TO_MEMORY, 1024, INDEPENDENT_TEST_RNG());
for (n = 0; n < 1024 * 256; n += 1024) {
sim.reset_all();
sim.do_circuit(circuit);
auto sample = sim.det_record.storage.transposed();
for (size_t k = 0; k < 1024; k++) {
bins[sample[k].u8[0]]++;
}
}
EXPECT_NEAR(bins[0] / (double)n, 0.45, 0.05);
EXPECT_EQ(bins[1], 0);
EXPECT_EQ(bins[2], 0);
EXPECT_EQ(bins[3], 0);
EXPECT_NEAR(bins[4] / (double)n, 0.05, 0.04);
EXPECT_NEAR(bins[5] / (double)n, 0.10, 0.04);
EXPECT_NEAR(bins[6] / (double)n, 0.25, 0.04);
EXPECT_NEAR(bins[7] / (double)n, 0.15, 0.04);
})
34 changes: 11 additions & 23 deletions src/stim/simulators/frame_simulator_pybind_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,6 @@ def test_peek_pauli_flips():
assert 250 < v4[0] < 450


def test_surface_code():
circuit = stim.Circuit.generated(
"surface_code:rotated_memory_x",
distance=3,
rounds=5,
before_round_data_depolarization=1e-2,
before_measure_flip_probability=1e-2,
after_reset_flip_probability=1e-2,
after_clifford_depolarization=1e-2,
)

# Find the index of the final MR layer.
mr_layer = len(circuit) - 1
while circuit[mr_layer].name != 'MR':
mr_layer -= 1
circuit_before_mr = circuit[:mr_layer]

sim = stim.FlipSimulator(batch_size=256, disable_stabilizer_randomization=True)
sim.do(circuit_before_mr)
for b in sim.peek_pauli_flips():
print(list(b))


def test_set_pauli_flip():
sim = stim.FlipSimulator(
batch_size=2,
Expand Down Expand Up @@ -238,3 +215,14 @@ def test_set_pauli_flip():
stim.PauliString('____X'),
stim.PauliString('XZ___'),
]


def test_repro_heralded_pauli_channel_1_bug():
circuit = stim.Circuit("""
R 0 1
HERALDED_PAULI_CHANNEL_1(0.2, 0.2, 0, 0) 1
M 0
""")
result = circuit.compile_sampler().sample(1024)
assert np.sum(result[:, 0]) > 0
assert np.sum(result[:, 1]) == 0

0 comments on commit 275baeb

Please sign in to comment.