Skip to content

Commit c30ae4e

Browse files
committed
.
1 parent c1374b3 commit c30ae4e

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

cirq-core/cirq/protocols/kraus_protocol_test.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,23 @@ def test_has_kraus_when_decomposed(decomposed_cls) -> None:
175175

176176

177177
def test_strat_kraus_from_apply_channel_returns_none():
178-
from cirq.protocols.kraus_protocol import _strat_kraus_from_apply_channel
179-
180-
class ApplyChannelReturnsNone:
181-
def _apply_channel_(self, *args, **kwargs):
182-
return None
178+
# Remove _kraus_ and _apply_channel_ methods
179+
class NoApplyChannelReset(cirq.ResetChannel):
180+
def _kraus_(self):
181+
return NotImplemented
183182

184-
def _num_qubits_(self):
185-
return 1 # Needed for qid_shape
183+
def _apply_channel_(self, args):
184+
return NotImplemented
186185

187-
assert _strat_kraus_from_apply_channel(ApplyChannelReturnsNone()) is None
186+
gate_no_apply = NoApplyChannelReset()
187+
with pytest.raises(
188+
TypeError,
189+
match="does have a _kraus_, _mixture_ or _unitary_ method, but it returned NotImplemented",
190+
):
191+
cirq.kraus(gate_no_apply)
188192

189193

190194
def test_kraus_fallback_to_apply_channel_bitflipchannel_real() -> None:
191-
"""Test fallback using the real cirq.BitFlipChannel and compare to a custom channel."""
192195
p = 0.5
193196
expected_kraus = cirq.kraus(cirq.BitFlipChannel(p))
194197

@@ -212,8 +215,6 @@ def _apply_channel_(self, args: cirq.ApplyChannelArgs):
212215

213216

214217
def test_reset_channel_kraus_apply_channel_consistency():
215-
"""Test that ResetChannel's _kraus_ and _apply_channel_ produce the same channel,
216-
even if one is missing."""
217218
Reset = cirq.ResetChannel
218219
# Original gate
219220
gate = Reset()
@@ -228,13 +229,3 @@ def _kraus_(self):
228229
gate_no_kraus = NoKrausReset()
229230
# Should still match the original superoperator
230231
np.testing.assert_allclose(cirq.kraus(gate), cirq.kraus(gate_no_kraus), atol=1e-8)
231-
232-
# Remove _apply_channel_ method
233-
class NoApplyChannelReset(Reset):
234-
def _apply_channel_(self, args):
235-
return NotImplemented
236-
237-
gate_no_apply = NoApplyChannelReset()
238-
cirq.testing.assert_consistent_channel(gate_no_apply)
239-
# Should still match the original superoperator
240-
np.testing.assert_allclose(cirq.kraus(gate), cirq.kraus(gate_no_apply), atol=1e-8)

0 commit comments

Comments
 (0)