@@ -175,20 +175,23 @@ def test_has_kraus_when_decomposed(decomposed_cls) -> None:
175
175
176
176
177
177
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
183
182
184
- def _num_qubits_ (self ):
185
- return 1 # Needed for qid_shape
183
+ def _apply_channel_ (self , args ):
184
+ return NotImplemented
186
185
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 )
188
192
189
193
190
194
def test_kraus_fallback_to_apply_channel_bitflipchannel_real () -> None :
191
- """Test fallback using the real cirq.BitFlipChannel and compare to a custom channel."""
192
195
p = 0.5
193
196
expected_kraus = cirq .kraus (cirq .BitFlipChannel (p ))
194
197
@@ -212,8 +215,6 @@ def _apply_channel_(self, args: cirq.ApplyChannelArgs):
212
215
213
216
214
217
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."""
217
218
Reset = cirq .ResetChannel
218
219
# Original gate
219
220
gate = Reset ()
@@ -228,13 +229,3 @@ def _kraus_(self):
228
229
gate_no_kraus = NoKrausReset ()
229
230
# Should still match the original superoperator
230
231
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