@@ -1030,17 +1030,17 @@ def test_expectation_from_state_vector_entangled_states():
1030
1030
x0x1 = cirq .PauliString (x0x1_pauli_map )
1031
1031
q_map = {q0 : 0 , q1 : 1 }
1032
1032
wf1 = np .array ([0 , 1 , 1 , 0 ], dtype = complex ) / np .sqrt (2 )
1033
- for state in [wf1 , wf1 .reshape (2 , 2 )]:
1033
+ for state in [wf1 , wf1 .reshape (( 2 , 2 ) )]:
1034
1034
np .testing .assert_allclose (z0z1 .expectation_from_state_vector (state , q_map ), - 1 )
1035
1035
np .testing .assert_allclose (x0x1 .expectation_from_state_vector (state , q_map ), 1 )
1036
1036
1037
1037
wf2 = np .array ([1 , 0 , 0 , 1 ], dtype = complex ) / np .sqrt (2 )
1038
- for state in [wf2 , wf2 .reshape (2 , 2 )]:
1038
+ for state in [wf2 , wf2 .reshape (( 2 , 2 ) )]:
1039
1039
np .testing .assert_allclose (z0z1 .expectation_from_state_vector (state , q_map ), 1 )
1040
1040
np .testing .assert_allclose (x0x1 .expectation_from_state_vector (state , q_map ), 1 )
1041
1041
1042
1042
wf3 = np .array ([1 , 1 , 1 , 1 ], dtype = complex ) / 2
1043
- for state in [wf3 , wf3 .reshape (2 , 2 )]:
1043
+ for state in [wf3 , wf3 .reshape (( 2 , 2 ) )]:
1044
1044
np .testing .assert_allclose (z0z1 .expectation_from_state_vector (state , q_map ), 0 )
1045
1045
np .testing .assert_allclose (x0x1 .expectation_from_state_vector (state , q_map ), 1 )
1046
1046
@@ -1049,7 +1049,7 @@ def test_expectation_from_state_vector_qubit_map():
1049
1049
q0 , q1 , q2 = _make_qubits (3 )
1050
1050
z = cirq .PauliString ({q0 : cirq .Z })
1051
1051
wf = np .array ([0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 ], dtype = complex ) / np .sqrt (2 )
1052
- for state in [wf , wf .reshape (2 , 2 , 2 )]:
1052
+ for state in [wf , wf .reshape (( 2 , 2 , 2 ) )]:
1053
1053
np .testing .assert_allclose (
1054
1054
z .expectation_from_state_vector (state , {q0 : 0 , q1 : 1 , q2 : 2 }), 1 , atol = 1e-8
1055
1055
)
@@ -1124,7 +1124,7 @@ def test_expectation_from_density_matrix_invalid_input():
1124
1124
q0 , q1 , q2 , q3 = _make_qubits (4 )
1125
1125
ps = cirq .PauliString ({q0 : cirq .X , q1 : cirq .Y })
1126
1126
wf = cirq .testing .random_superposition (4 )
1127
- rho = np .kron (wf .conjugate ().T , wf ).reshape (4 , 4 )
1127
+ rho = np .kron (wf .conjugate ().T , wf ).reshape (( 4 , 4 ) )
1128
1128
q_map = {q0 : 0 , q1 : 1 }
1129
1129
1130
1130
im_ps = (1j + 1 ) * ps
@@ -1238,20 +1238,20 @@ def test_expectation_from_density_matrix_entangled_states():
1238
1238
q_map = {q0 : 0 , q1 : 1 }
1239
1239
1240
1240
wf1 = np .array ([0 , 1 , 1 , 0 ], dtype = complex ) / np .sqrt (2 )
1241
- rho1 = np .kron (wf1 , wf1 ).reshape (4 , 4 )
1242
- for state in [rho1 , rho1 .reshape (2 , 2 , 2 , 2 )]:
1241
+ rho1 = np .kron (wf1 , wf1 ).reshape (( 4 , 4 ) )
1242
+ for state in [rho1 , rho1 .reshape (( 2 , 2 , 2 , 2 ) )]:
1243
1243
np .testing .assert_allclose (z0z1 .expectation_from_density_matrix (state , q_map ), - 1 )
1244
1244
np .testing .assert_allclose (x0x1 .expectation_from_density_matrix (state , q_map ), 1 )
1245
1245
1246
1246
wf2 = np .array ([1 , 0 , 0 , 1 ], dtype = complex ) / np .sqrt (2 )
1247
- rho2 = np .kron (wf2 , wf2 ).reshape (4 , 4 )
1248
- for state in [rho2 , rho2 .reshape (2 , 2 , 2 , 2 )]:
1247
+ rho2 = np .kron (wf2 , wf2 ).reshape (( 4 , 4 ) )
1248
+ for state in [rho2 , rho2 .reshape (( 2 , 2 , 2 , 2 ) )]:
1249
1249
np .testing .assert_allclose (z0z1 .expectation_from_density_matrix (state , q_map ), 1 )
1250
1250
np .testing .assert_allclose (x0x1 .expectation_from_density_matrix (state , q_map ), 1 )
1251
1251
1252
1252
wf3 = np .array ([1 , 1 , 1 , 1 ], dtype = complex ) / 2
1253
- rho3 = np .kron (wf3 , wf3 ).reshape (4 , 4 )
1254
- for state in [rho3 , rho3 .reshape (2 , 2 , 2 , 2 )]:
1253
+ rho3 = np .kron (wf3 , wf3 ).reshape (( 4 , 4 ) )
1254
+ for state in [rho3 , rho3 .reshape (( 2 , 2 , 2 , 2 ) )]:
1255
1255
np .testing .assert_allclose (z0z1 .expectation_from_density_matrix (state , q_map ), 0 )
1256
1256
np .testing .assert_allclose (x0x1 .expectation_from_density_matrix (state , q_map ), 1 )
1257
1257
@@ -1260,9 +1260,9 @@ def test_expectation_from_density_matrix_qubit_map():
1260
1260
q0 , q1 , q2 = _make_qubits (3 )
1261
1261
z = cirq .PauliString ({q0 : cirq .Z })
1262
1262
wf = np .array ([0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 ], dtype = complex ) / np .sqrt (2 )
1263
- rho = np .kron (wf , wf ).reshape (8 , 8 )
1263
+ rho = np .kron (wf , wf ).reshape (( 8 , 8 ) )
1264
1264
1265
- for state in [rho , rho .reshape (2 , 2 , 2 , 2 , 2 , 2 )]:
1265
+ for state in [rho , rho .reshape (( 2 , 2 , 2 , 2 , 2 , 2 ) )]:
1266
1266
np .testing .assert_allclose (
1267
1267
z .expectation_from_density_matrix (state , {q0 : 0 , q1 : 1 , q2 : 2 }), 1
1268
1268
)
0 commit comments