Skip to content

Fix tests and deprectations #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/randomized_benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import qutip as qt
from numpy import ndarray
from numpy.random import permutation
from scipy import io, optimize
from scipy import io, optimize, integrate

# %%

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


def find_inverse(U: ndarray, cliffords: Sequence[ff.PulseSequence]) -> ndarray:
Expand Down
2 changes: 1 addition & 1 deletion filter_functions/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def CPMG(z, n):

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


def UDD(z, n):
Expand Down
2 changes: 1 addition & 1 deletion filter_functions/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __new__(cls, basis_array: Sequence, traceless: Optional[bool] = None,
pass

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

Expand Down
3 changes: 2 additions & 1 deletion filter_functions/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ def plot_bloch_vector_evolution(
b.axes.add_collection3d(lc, zdir='z', zs=segments[:, :, 2])

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

Expand Down
5 changes: 4 additions & 1 deletion filter_functions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def parse_operators(opers: Sequence[Operator], err_loc: str) -> List[ndarray]:
elif hasattr(oper, 'full'):
# qutip.Qobj
parsed_opers.append(oper.full())
elif hasattr(oper, 'to_array'):
# qutip.Dia object
parsed_opers.append(oper.to_array())
elif hasattr(oper, 'todense'):
# sparse object
parsed_opers.append(oper.todense())
Expand Down Expand Up @@ -843,7 +846,7 @@ def integrate(f: ndarray, x: Optional[ndarray] = None, dx: float = 1.0) -> Union

See Also
--------
numpy.trapz
scipy.integrate.trapezoid

"""
dx = np.diff(x) if x is not None else dx
Expand Down
6 changes: 3 additions & 3 deletions tests/test_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _get_integrals_first_order(d, E, eigval, dt, t0):
EdE = np.add.outer(E, dE)
integrand = np.exp(1j*np.multiply.outer(EdE, tspace - t0))

integral_numeric = integrate.trapz(integrand, tspace)
integral_numeric = integrate.trapezoid(integrand, tspace)
integral = numeric._first_order_integral(E, eigval, dt, exp_buf, int_buf)
return integral, integral_numeric

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

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

integral_numeric = integrate.trapz(integrand, tspace)
integral_numeric = integrate.trapezoid(integrand, tspace)
integral = numeric._second_order_integral(E, eigval, dt, int_buf, frc_bufs, dE_bufs,
exp_buf, msk_bufs)
return integral, integral_numeric
Expand Down
8 changes: 4 additions & 4 deletions tests/test_superoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def partial_transpose(A):
self.assertArrayEqual(CP, _CP)
self.assertTrue(np.all(CP))
if U_sup.ndim == 2:
self.assertIsInstance(CP, (bool, np.bool8))
self.assertIsInstance(CP, (bool, np.bool_))
else:
self.assertEqual(CP.shape[0], U_sup.shape[0])
# Only one nonzero eigenvalue
Expand All @@ -143,7 +143,7 @@ def partial_transpose(A):
CP = superoperator.liouville_is_CP(U_sup, pulse.basis)

self.assertTrue(np.all(CP))
self.assertIsInstance(CP, (bool, np.bool8))
self.assertIsInstance(CP, (bool, np.bool_))

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

self.assertTrue(np.all(cCP))
if K_sup.ndim == 2:
self.assertIsInstance(cCP, (bool, np.bool8))
self.assertIsInstance(cCP, (bool, np.bool_))
else:
self.assertEqual(cCP.shape[0], K_sup.shape[0])
5 changes: 3 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""
import numpy as np
import pytest
from scipy import integrate

from filter_functions import PulseSequence, util
from tests import testutil
Expand Down Expand Up @@ -415,11 +416,11 @@ def test_mdot(self):
def test_integrate(self):
f = rng.standard_normal(32)
x = rng.random(32)
self.assertEqual(util.integrate(f, x), np.trapz(f, x))
self.assertEqual(util.integrate(f, x), integrate.trapezoid(f, x))

f = rng.standard_normal((2, 32)).astype(complex)
x = rng.random(32)
self.assertArrayEqual(util.integrate(f, x), np.trapz(f, x))
self.assertArrayEqual(util.integrate(f, x), integrate.trapezoid(f, x))

f = rng.standard_normal(32)
x = np.linspace(0, 1, 32)
Expand Down
Loading