Skip to content

Commit 3f3a416

Browse files
authored
Merge pull request #92 from qutech/bugfix/tests
Fix tests and deprectations
2 parents 455f162 + 14c9980 commit 3f3a416

File tree

8 files changed

+20
-15
lines changed

8 files changed

+20
-15
lines changed

examples/randomized_benchmarking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import qutip as qt
3333
from numpy import ndarray
3434
from numpy.random import permutation
35-
from scipy import io, optimize
35+
from scipy import io, optimize, integrate
3636

3737
# %%
3838

@@ -46,7 +46,7 @@ def state_infidelity(pulse: ff.PulseSequence, S: ndarray, omega: ndarray,
4646
"""Compute state infidelity for input state eigenstate of pauli *ind*"""
4747
R = pulse.get_control_matrix(omega)
4848
F = np.einsum('jko->jo', ff.util.abs2(R[:, np.delete([0, 1, 2, 3], ind)]))
49-
return np.trapz(F*S, omega)/(2*np.pi*pulse.d)
49+
return integrate.trapezoid(F*S, omega)/(2*np.pi*pulse.d)
5050

5151

5252
def find_inverse(U: ndarray, cliffords: Sequence[ff.PulseSequence]) -> ndarray:

filter_functions/analytic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def CPMG(z, n):
8080

8181
def CDD(z, g):
8282
return 2**(2*g + 1)*np.sin(z/2**(g + 1))**2 *\
83-
np.product([np.sin(z/2**(k + 1))**2 for k in range(1, g+1)], axis=0)
83+
np.prod([np.sin(z/2**(k + 1))**2 for k in range(1, g+1)], axis=0)
8484

8585

8686
def UDD(z, n):

filter_functions/basis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def __new__(cls, basis_array: Sequence, traceless: Optional[bool] = None,
174174
pass
175175

176176
basis = util.parse_operators(basis_array, 'basis_array')
177-
if basis.shape[0] > np.product(basis.shape[1:]):
177+
if basis.shape[0] > np.prod(basis.shape[1:]):
178178
raise ValueError('Given overcomplete set of basis matrices. '
179179
'Not linearly independent.')
180180

filter_functions/plotting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def plot_bloch_vector_evolution(
261261
b.axes.add_collection3d(lc, zdir='z', zs=segments[:, :, 2])
262262

263263
if add_cbar:
264-
default_cbar_kwargs = dict(shrink=2/3, pad=0.05, label=r'$t$ ($\tau$)', ticks=[0, 1])
264+
default_cbar_kwargs = dict(shrink=2/3, pad=0.05, label=r'$t$ ($\tau$)', ticks=[0, 1],
265+
ax=b.axes)
265266
cbar_kwargs = {**default_cbar_kwargs, **(cbar_kwargs or {})}
266267
b.fig.colorbar(cm.ScalarMappable(cmap=cmap), **cbar_kwargs)
267268

filter_functions/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ def parse_operators(opers: Sequence[Operator], err_loc: str) -> List[ndarray]:
227227
elif hasattr(oper, 'full'):
228228
# qutip.Qobj
229229
parsed_opers.append(oper.full())
230+
elif hasattr(oper, 'to_array'):
231+
# qutip.Dia object
232+
parsed_opers.append(oper.to_array())
230233
elif hasattr(oper, 'todense'):
231234
# sparse object
232235
parsed_opers.append(oper.todense())
@@ -843,7 +846,7 @@ def integrate(f: ndarray, x: Optional[ndarray] = None, dx: float = 1.0) -> Union
843846
844847
See Also
845848
--------
846-
numpy.trapz
849+
scipy.integrate.trapezoid
847850
848851
"""
849852
dx = np.diff(x) if x is not None else dx

tests/test_precision.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _get_integrals_first_order(d, E, eigval, dt, t0):
4141
EdE = np.add.outer(E, dE)
4242
integrand = np.exp(1j*np.multiply.outer(EdE, tspace - t0))
4343

44-
integral_numeric = integrate.trapz(integrand, tspace)
44+
integral_numeric = integrate.trapezoid(integrand, tspace)
4545
integral = numeric._first_order_integral(E, eigval, dt, exp_buf, int_buf)
4646
return integral, integral_numeric
4747

@@ -61,12 +61,12 @@ def _get_integrals_second_order(d, E, eigval, dt, t0):
6161

6262
ex = (np.multiply.outer(dE, tspace - t0)
6363
+ np.multiply.outer(E, tspace)[:, None, None])
64-
I1 = integrate.cumtrapz(util.cexp(ex), tspace, initial=0)
64+
I1 = integrate.cumulative_trapezoid(util.cexp(ex), tspace, initial=0)
6565
ex = (np.multiply.outer(dE, tspace - t0)
6666
- np.multiply.outer(E, tspace)[:, None, None])
6767
integrand = util.cexp(ex)[:, :, :, None, None] * I1[:, None, None]
6868

69-
integral_numeric = integrate.trapz(integrand, tspace)
69+
integral_numeric = integrate.trapezoid(integrand, tspace)
7070
integral = numeric._second_order_integral(E, eigval, dt, int_buf, frc_bufs, dE_bufs,
7171
exp_buf, msk_bufs)
7272
return integral, integral_numeric

tests/test_superoperator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def partial_transpose(A):
129129
self.assertArrayEqual(CP, _CP)
130130
self.assertTrue(np.all(CP))
131131
if U_sup.ndim == 2:
132-
self.assertIsInstance(CP, (bool, np.bool8))
132+
self.assertIsInstance(CP, (bool, np.bool_))
133133
else:
134134
self.assertEqual(CP.shape[0], U_sup.shape[0])
135135
# Only one nonzero eigenvalue
@@ -143,7 +143,7 @@ def partial_transpose(A):
143143
CP = superoperator.liouville_is_CP(U_sup, pulse.basis)
144144

145145
self.assertTrue(np.all(CP))
146-
self.assertIsInstance(CP, (bool, np.bool8))
146+
self.assertIsInstance(CP, (bool, np.bool_))
147147

148148
def test_liouville_is_cCP(self):
149149
for d in rng.integers(2, 9, (15,)):
@@ -165,7 +165,7 @@ def test_liouville_is_cCP(self):
165165
self.assertArrayEqual(cCP, _cCP)
166166
self.assertTrue(np.all(cCP))
167167
if H_sup.ndim == 2:
168-
self.assertIsInstance(cCP, (bool, np.bool8))
168+
self.assertIsInstance(cCP, (bool, np.bool_))
169169
else:
170170
self.assertEqual(cCP.shape[0], H_sup.shape[0])
171171
self.assertArrayAlmostEqual(D, 0, atol=1e-14)
@@ -182,6 +182,6 @@ def test_liouville_is_cCP(self):
182182

183183
self.assertTrue(np.all(cCP))
184184
if K_sup.ndim == 2:
185-
self.assertIsInstance(cCP, (bool, np.bool8))
185+
self.assertIsInstance(cCP, (bool, np.bool_))
186186
else:
187187
self.assertEqual(cCP.shape[0], K_sup.shape[0])

tests/test_util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""
2424
import numpy as np
2525
import pytest
26+
from scipy import integrate
2627

2728
from filter_functions import PulseSequence, util
2829
from tests import testutil
@@ -415,11 +416,11 @@ def test_mdot(self):
415416
def test_integrate(self):
416417
f = rng.standard_normal(32)
417418
x = rng.random(32)
418-
self.assertEqual(util.integrate(f, x), np.trapz(f, x))
419+
self.assertEqual(util.integrate(f, x), integrate.trapezoid(f, x))
419420

420421
f = rng.standard_normal((2, 32)).astype(complex)
421422
x = rng.random(32)
422-
self.assertArrayEqual(util.integrate(f, x), np.trapz(f, x))
423+
self.assertArrayEqual(util.integrate(f, x), integrate.trapezoid(f, x))
423424

424425
f = rng.standard_normal(32)
425426
x = np.linspace(0, 1, 32)

0 commit comments

Comments
 (0)