1212from toqito .cones .integral_relative_entropy import _sandwich_parameters
1313from toqito .perms import swap_operator
1414
15- _CHANNEL_RELATIVE_ENTROPY_MOD = importlib .import_module (
16- "toqito.channel_metrics.channel_relative_entropy"
17- )
15+ _CHANNEL_RELATIVE_ENTROPY_MOD = importlib .import_module ("toqito.channel_metrics.channel_relative_entropy" )
1816
1917
2018def _dense (mat ):
@@ -91,9 +89,7 @@ def test_identical_channels_zero():
9189 """Identical channels should give zero in both bounds and mean modes."""
9290 choi = depolarizing (2 , 1 )
9391
94- lower , upper = channel_relative_entropy (
95- choi , choi , in_dim = 2 , epsilon_dec = 0.2 , mean = False
96- )
92+ lower , upper = channel_relative_entropy (choi , choi , in_dim = 2 , epsilon_dec = 0.2 , mean = False )
9793 avg = channel_relative_entropy (choi , choi , in_dim = 2 , epsilon_dec = 0.2 , mean = True )
9894
9995 assert lower == 0
@@ -252,9 +248,7 @@ def solve(self, **kwargs):
252248 monkeypatch .setattr (_CHANNEL_RELATIVE_ENTROPY_MOD .cvx , "Problem" , FakeProblem )
253249
254250 with pytest .raises (RuntimeError , match = "Lower-bound SDP failed" ):
255- channel_relative_entropy (
256- depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2
257- )
251+ channel_relative_entropy (depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2 )
258252
259253
260254def test_raises_when_upper_sdp_fails (monkeypatch ):
@@ -280,9 +274,7 @@ def solve(self, **kwargs):
280274 monkeypatch .setattr (_CHANNEL_RELATIVE_ENTROPY_MOD .cvx , "Problem" , FakeProblem )
281275
282276 with pytest .raises (RuntimeError , match = "Upper-bound SDP failed" ):
283- channel_relative_entropy (
284- depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2
285- )
277+ channel_relative_entropy (depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2 )
286278
287279
288280def test_warns_on_optimal_inaccurate_lower (monkeypatch ):
@@ -299,9 +291,7 @@ class FakeProblem:
299291 def __init__ (self , objective , constraints ):
300292 self .value = 1.0
301293 FakeProblem .created += 1
302- self .status = (
303- cvx .OPTIMAL_INACCURATE if FakeProblem .created == 1 else cvx .OPTIMAL
304- )
294+ self .status = cvx .OPTIMAL_INACCURATE if FakeProblem .created == 1 else cvx .OPTIMAL
305295
306296 def solve (self , ** kwargs ):
307297 pass
@@ -310,9 +300,7 @@ def solve(self, **kwargs):
310300 monkeypatch .setattr (_CHANNEL_RELATIVE_ENTROPY_MOD .cvx , "Problem" , FakeProblem )
311301
312302 with pytest .warns (UserWarning , match = "Lower-bound SDP returned OPTIMAL_INACCURATE" ):
313- channel_relative_entropy (
314- depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2
315- )
303+ channel_relative_entropy (depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2 )
316304
317305
318306def test_warns_on_optimal_inaccurate_upper (monkeypatch ):
@@ -329,9 +317,7 @@ class FakeProblem:
329317 def __init__ (self , objective , constraints ):
330318 self .value = 1.0
331319 FakeProblem .created += 1
332- self .status = (
333- cvx .OPTIMAL if FakeProblem .created == 1 else cvx .OPTIMAL_INACCURATE
334- )
320+ self .status = cvx .OPTIMAL if FakeProblem .created == 1 else cvx .OPTIMAL_INACCURATE
335321
336322 def solve (self , ** kwargs ):
337323 pass
@@ -340,9 +326,7 @@ def solve(self, **kwargs):
340326 monkeypatch .setattr (_CHANNEL_RELATIVE_ENTROPY_MOD .cvx , "Problem" , FakeProblem )
341327
342328 with pytest .warns (UserWarning , match = "Upper-bound SDP returned OPTIMAL_INACCURATE" ):
343- channel_relative_entropy (
344- depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2
345- )
329+ channel_relative_entropy (depolarizing (2 , 0.2 ), depolarizing (2 , 0.4 ), in_dim = 2 , epsilon_dec = 0.2 )
346330
347331
348332@pytest .mark .slow
@@ -363,11 +347,7 @@ def test_channel_relative_entropy_paper_example(param_p: float, expected_mean: f
363347 # N_deph(rho) = 0.4 rho + 0.6 sigma_z rho sigma_z
364348 # M_dep(rho) = (1 - 3p/4) rho + p/4 (X rho X + Y rho Y + Z rho Z)
365349 channel_1 = _dense (pauli_channel (np .array ([0.4 , 0.0 , 0.0 , 0.6 ])))
366- channel_2 = _dense (
367- pauli_channel (
368- np .array ([1 - 3 * param_p / 4 , param_p / 4 , param_p / 4 , param_p / 4 ])
369- )
370- )
350+ channel_2 = _dense (pauli_channel (np .array ([1 - 3 * param_p / 4 , param_p / 4 , param_p / 4 , param_p / 4 ])))
371351
372352 lower , upper = channel_relative_entropy (channel_1 , channel_2 , in_dim = 2 , mean = False )
373353 avg = (lower + upper ) / 2
0 commit comments