Skip to content

Fix pytest deprecation warnings. #852

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
Nov 29, 2023
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
7 changes: 4 additions & 3 deletions src/openfermion/hamiltonians/jellium.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# limitations under the License.
"""This module constructs Hamiltonians for the uniform electron gas."""

import math
from typing import Optional

import numpy
Expand Down Expand Up @@ -42,15 +43,15 @@ def wigner_seitz_length_scale(
if dimension % 2:
volume_per_particle = (
2
* numpy.math.factorial(half_dimension)
* math.factorial(half_dimension)
* (4 * numpy.pi) ** half_dimension
/ numpy.math.factorial(dimension)
/ math.factorial(dimension)
* wigner_seitz_radius**dimension
)
else:
volume_per_particle = (
numpy.pi**half_dimension
/ numpy.math.factorial(half_dimension)
/ math.factorial(half_dimension)
* wigner_seitz_radius**dimension
)

Expand Down
4 changes: 2 additions & 2 deletions src/openfermion/linalg/davidson_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import scipy.sparse
import scipy.sparse.linalg

from openfermion.ops.operators import QubitOperator
from openfermion.linalg.davidson import (
Davidson,
DavidsonOptions,
Expand All @@ -29,6 +28,7 @@
append_random_vectors,
orthonormalize,
)
from openfermion.ops.operators import QubitOperator


def generate_matrix(dimension):
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_invalid_dimension(self):


class DavidsonTest(unittest.TestCase):
""" "Tests for Davidson class with a real matrix."""
"""Tests for Davidson class with a real matrix."""

def setUp(self):
"""Sets up all variables needed for Davidson class."""
Expand Down
8 changes: 4 additions & 4 deletions src/openfermion/transforms/opconversions/bksf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import numpy

from openfermion.config import DATA_DIRECTORY
from openfermion.chem import MolecularData
from openfermion.config import DATA_DIRECTORY
from openfermion.linalg import eigenspectrum, get_sparse_operator
from openfermion.ops.operators import FermionOperator, QubitOperator
from openfermion.ops.representations import InteractionOperator
from openfermion.transforms.opconversions import bksf, get_fermion_operator, normal_ordered
from openfermion.transforms.opconversions.jordan_wigner import jordan_wigner, jordan_wigner_one_body
from openfermion.linalg import get_sparse_operator, eigenspectrum
from openfermion.utils import count_qubits


Expand Down Expand Up @@ -173,8 +173,8 @@ def test_bravyi_kitaev_fast_generate_fermions(self):
tot_23_fermions = numpy.dot(
two_fermion_state.conjugate().T, numpy.dot(number_operator_23_matrix, two_fermion_state)
)
self.assertTrue(2.0 - float(tot_fermions.real) < 1e-13)
self.assertTrue(2.0 - float(tot_23_fermions.real) < 1e-13)
self.assertTrue(2.0 - float(tot_fermions[0, 0].real) < 1e-13)
self.assertTrue(2.0 - float(tot_23_fermions[0, 0].real) < 1e-13)

def test_bravyi_kitaev_fast_excitation_terms(self):
# Testing on-site and excitation terms in Hamiltonian
Expand Down
9 changes: 5 additions & 4 deletions src/openfermion/utils/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# limitations under the License.

import itertools

import numpy
import scipy
import scipy.linalg
Expand Down Expand Up @@ -246,7 +247,7 @@ def orbital_id(self, grid_coordinates, spin=None):
for dimension, grid_coordinate in enumerate(grid_coordinates):
# Make sure coordinate is an integer in the correct bounds.
if isinstance(grid_coordinate, int) and grid_coordinate < self.length[dimension]:
tensor_factor += grid_coordinate * int(numpy.product(self.length[:dimension]))
tensor_factor += grid_coordinate * int(numpy.prod(self.length[:dimension]))
else:
# Raise for invalid model.
raise OrbitalSpecificationError('Invalid orbital coordinates provided.')
Expand All @@ -270,7 +271,7 @@ def grid_indices(self, qubit_id, spinless):
grid_indices (numpy.ndarray[int]):
The location of the qubit on the grid.
"""
if not (numpy.product(self.length) * (2 - spinless) > qubit_id >= 0):
if not (numpy.prod(self.length) * (2 - spinless) > qubit_id >= 0):
raise OrbitalSpecificationError('Invalid qubit_id provided.')

# Remove spin degree of freedom if it exists.
Expand All @@ -282,8 +283,8 @@ def grid_indices(self, qubit_id, spinless):
# Get grid indices.
grid_indices = []
for dimension in range(self.dimensions):
remainder = orbital_id % int(numpy.product(self.length[: dimension + 1]))
grid_index = remainder // int(numpy.product(self.length[:dimension]))
remainder = orbital_id % int(numpy.prod(self.length[: dimension + 1]))
grid_index = remainder // int(numpy.prod(self.length[:dimension]))
grid_indices += [grid_index]
return grid_indices

Expand Down