Skip to content

Commit

Permalink
Merge pull request #2177 from Ericgig/bugs.np.1.25_fix
Browse files Browse the repository at this point in the history
Update for numpy 1.25 deprecations
  • Loading branch information
Ericgig committed Jun 20, 2023
2 parents 6ddf678 + e663a5b commit ec0fcc6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion qutip/core/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def tensor_contract(qobj, *pairs):
# We don't need to check for tensor idxs versus dims idxs here,
# as column- versus row-stacking will never move an index for the
# vectorized operator spaces all the way from the left to the right.
l_mtx_dims, r_mtx_dims = map(np.product, map(flatten, contracted_dims))
l_mtx_dims, r_mtx_dims = map(np.prod, map(flatten, contracted_dims))

# Reshape back into a 2D matrix.
qmtx = qtens.reshape((l_mtx_dims, r_mtx_dims))
Expand Down
6 changes: 2 additions & 4 deletions qutip/tests/core/test_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,10 @@ def test_QobjMultiplication():

# Allowed mul operations (scalar)
@pytest.mark.parametrize("scalar",
[2+2j, np.array(2+2j), np.array([2+2j])],
[2+2j, np.array(2+2j)],
ids=[
"python_number",
"scalar_like_array_shape_0",
"scalar_like_array_shape_1",
])
def test_QobjMulValidScalar(scalar):
"Tests multiplication of Qobj times scalar."
Expand Down Expand Up @@ -359,11 +358,10 @@ def test_QobjMulNotValidScalar(not_scalar):

# Allowed division operations (scalar)
@pytest.mark.parametrize("scalar",
[2+2j, np.array(2+2j), np.array([2+2j])],
[2+2j, np.array(2+2j)],
ids=[
"python_number",
"scalar_like_array_shape_0",
"scalar_like_array_shape_1",
])
def test_QobjDivisionValidScalar(scalar):
"Tests multiplication of Qobj times scalar."
Expand Down
4 changes: 2 additions & 2 deletions qutip/tests/solver/heom/test_bofin_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def mk_ados(self, bath_dims, max_depth):

def mk_rho_and_soln(self, ados, rho_dims):
n_ados = len(ados.labels)
ado_soln = np.random.rand(n_ados, *[np.product(d) for d in rho_dims])
ado_soln = np.random.rand(n_ados, *[np.prod(d) for d in rho_dims])
rho = Qobj(ado_soln[0, :], dims=rho_dims)
return rho, ado_soln

Expand Down Expand Up @@ -1289,7 +1289,7 @@ def mk_ados(self, bath_dims, max_depth):

def mk_rho_and_soln(self, ados, rho_dims):
n_ados = len(ados.labels)
ado_soln = np.random.rand(n_ados, *[np.product(d) for d in rho_dims])
ado_soln = np.random.rand(n_ados, *[np.prod(d) for d in rho_dims])
rho = Qobj(ado_soln[0, :], dims=rho_dims)
return rho, ado_soln

Expand Down
2 changes: 1 addition & 1 deletion qutip/tests/test_wigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_against_naive_implementation(self, xs, ys, g, size):
naive = np.empty(alphas.shape, dtype=np.float64)
for i, alpha in enumerate(alphas.flat):
coh = qutip.coherent(size, alpha, method='analytic').full()
naive.flat[i] = (coh.conj().T @ state_np @ coh).real
naive.flat[i] = (coh.conj().T @ state_np @ coh).real[0, 0]
naive *= (0.5*g)**2 / np.pi
np.testing.assert_allclose(naive, qutip.qfunc(state, xs, ys, g))
np.testing.assert_allclose(naive, qutip.QFunc(xs, ys, g)(state))
Expand Down

0 comments on commit ec0fcc6

Please sign in to comment.