Skip to content

Commit 3de569a

Browse files
authored
Do not separate substates when measurements are ignored (quantumlib#4816)
Density matrix separates qubit states after measurement when split_untanged_states=True. However when ignore_measurement_results=True, this should not happen, as the this changes the measurement into a dephase and does not make the state separable. For instance, when measuring a Bell state, the result should be 0.5 |00> + 0.5 |11>. However, separating those states (partial tracing each qubit) and re-kronning them gives 0.25 of each; i.e. it causes each qubit to be 0.5 |0> and 0.5 |1> independently. Therefore we need to avoid separating states after measurements if ignore_measurement_results=True. This PR fixes quantumlib#4817.
1 parent 1f3b502 commit 3de569a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cirq/sim/act_on_args_container.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ def _act_on_fallback_(
118118
protocols.act_on(action, op_args, act_on_qubits, allow_decompose=allow_decompose)
119119

120120
# Decouple any measurements or resets
121-
if self.split_untangled_states and isinstance(
122-
gate, (ops.MeasurementGate, ops.ResetChannel)
121+
if self.split_untangled_states and (
122+
isinstance(gate, ops.ResetChannel)
123+
or (isinstance(gate, ops.MeasurementGate) and not op_args.ignore_measurement_results)
123124
):
124125
for q in qubits:
125126
q_args, op_args = op_args.factor((q,), validate=False)

cirq/sim/density_matrix_simulator_test.py

+22
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,28 @@ def test_reset_one_qubit_does_not_affect_partial_trace_of_other_qubits(
571571
np.testing.assert_almost_equal(result.final_density_matrix, expected)
572572

573573

574+
def test_ignore_measurements_remains_entangled():
575+
q0, q1 = cirq.LineQubit.range(2)
576+
simulator1 = cirq.DensityMatrixSimulator(
577+
ignore_measurement_results=True, split_untangled_states=False
578+
)
579+
simulator2 = cirq.DensityMatrixSimulator(
580+
ignore_measurement_results=True, split_untangled_states=True
581+
)
582+
circuit = cirq.Circuit(
583+
cirq.H(q0),
584+
cirq.CX(q0, q1),
585+
cirq.measure(q0),
586+
)
587+
result1 = simulator1.simulate(circuit)
588+
result2 = simulator2.simulate(circuit)
589+
np.testing.assert_almost_equal(result2.final_density_matrix, result1.final_density_matrix)
590+
expected = np.zeros((4, 4))
591+
expected[0, 0] = 0.5
592+
expected[3, 3] = 0.5
593+
np.testing.assert_almost_equal(result2.final_density_matrix, expected)
594+
595+
574596
@pytest.mark.parametrize(
575597
'dtype,circuit',
576598
itertools.product(

0 commit comments

Comments
 (0)