Skip to content

Commit

Permalink
Add a test to ensure reset does not collapse density matrix (#4682)
Browse files Browse the repository at this point in the history
I was going to update ResetGate to be simpler and more reusable, by having act_on do a measuremnt and then applying a PlusGate corresponding to remaining qudit steps. This passed all existing tests. However I later realized that measuring a qubit could collapse entangled qubits as well, breaking density matrix representation. 

Here is a test that will break with the above implementation, to make sure nobody else tries the same.
  • Loading branch information
daxfohl authored Nov 17, 2021
1 parent 1ea6061 commit 46cb62f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cirq-core/cirq/sim/density_matrix_simulator_test.py
Original file line number Diff line number Diff line change
@@ -527,6 +527,25 @@ def test_simulate_qudits(dtype: Type[np.number], split: bool):
assert len(result.measurements) == 0


@pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
@pytest.mark.parametrize('split', [True, False])
def test_reset_one_qubit_does_not_affect_partial_trace_of_other_qubits(
dtype: Type[np.number], split: bool
):
q0, q1 = cirq.LineQubit.range(2)
simulator = cirq.DensityMatrixSimulator(dtype=dtype, split_untangled_states=split)
circuit = cirq.Circuit(
cirq.H(q0),
cirq.CX(q0, q1),
cirq.reset(q0),
)
result = simulator.simulate(circuit)
expected = np.zeros((4, 4), dtype=dtype)
expected[0, 0] = 0.5
expected[1, 1] = 0.5
np.testing.assert_almost_equal(result.final_density_matrix, expected)


@pytest.mark.parametrize(
'dtype,circuit',
itertools.product(

0 comments on commit 46cb62f

Please sign in to comment.