Skip to content

Commit

Permalink
Fix stim.TableauSimulator.cnot and friends crashing on target_rec t…
Browse files Browse the repository at this point in the history
…argets (#37)
  • Loading branch information
Strilanc authored Apr 16, 2021
1 parent 0b2b430 commit 5933aef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/simulators/tableau_simulator.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TempViewableData args_to_targets(TableauSimulator &self, const pybind11::args &a
try {
for (const auto &e : args) {
size_t q = e.cast<uint32_t>();
max_q = std::max(max_q, q);
max_q = std::max(max_q, q & TARGET_VALUE_MASK);
arguments.push_back(q);
}
} catch (const pybind11::cast_error &) {
Expand Down
16 changes: 16 additions & 0 deletions src/simulators/tableau_simulator_pybind_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,19 @@ def test_canonical_stabilizers():
stim.PauliString("-ZXY"),
stim.PauliString("+_ZX"),
]


def test_classical_control_cnot():
s = stim.TableauSimulator()

with pytest.raises(IndexError, match="beginning of time"):
s.cnot(stim.target_rec(-1), 0)

assert not s.measure(1)
s.cnot(stim.target_rec(-1), 0)
assert not s.measure(0)

s.x(1)
assert s.measure(1)
s.cnot(stim.target_rec(-1), 0)
assert s.measure(0)

0 comments on commit 5933aef

Please sign in to comment.