diff --git a/dev_tools/conf/.pylintrc b/dev_tools/conf/.pylintrc index 2edf4ac51..1ae9da80b 100644 --- a/dev_tools/conf/.pylintrc +++ b/dev_tools/conf/.pylintrc @@ -19,9 +19,7 @@ [MAIN] -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. +# Analyse import fallback blocks. analyse-fallback-blocks=no # Clear in-memory caches upon conclusion of linting. Useful if running pylint @@ -1027,4 +1025,4 @@ init-import=yes # List of qualified module names which can have objects that can redefine # builtins. -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io +redefining-builtins-modules=builtins,io diff --git a/src/openfermion/chem/molecular_data.py b/src/openfermion/chem/molecular_data.py index d0867592f..64dc376b6 100644 --- a/src/openfermion/chem/molecular_data.py +++ b/src/openfermion/chem/molecular_data.py @@ -396,7 +396,7 @@ def spinorb_from_spatial(one_body_integrals, two_body_integrals): return one_body_coefficients, two_body_coefficients -class MolecularData(object): +class MolecularData: """Class for storing molecule data from a fixed basis set at a fixed geometry that is obtained from classical electronic structure packages. Not every field is filled in every calculation. All data @@ -859,7 +859,7 @@ def load(self): # Load charge: self.charge = int(f["charge"][...]) # Load description: - self.description = f["description"][...].tobytes().decode('utf-8').rstrip(u'\x00') + self.description = f["description"][...].tobytes().decode('utf-8').rstrip('\x00') # Load name: self.name = f["name"][...].tobytes().decode('utf-8') # Load n_atoms: diff --git a/src/openfermion/contrib/representability/_dualbasis.py b/src/openfermion/contrib/representability/_dualbasis.py index 1375ef88d..1369388e3 100644 --- a/src/openfermion/contrib/representability/_dualbasis.py +++ b/src/openfermion/contrib/representability/_dualbasis.py @@ -2,7 +2,7 @@ import copy -class DualBasisElement(object): +class DualBasisElement: """ This object is named after the algebraic dual space or dual vector space @@ -154,7 +154,7 @@ def __add__(self, other): raise TypeError("DualBasisElement can be added to same type or DualBasis") -class DualBasis(object): +class DualBasis: def __init__(self, elements: Optional[Union[None, List[DualBasisElement]]] = None): """ A collection of DualBasisElements diff --git a/src/openfermion/contrib/representability/_multitensor.py b/src/openfermion/contrib/representability/_multitensor.py index e63b0805b..f819c8637 100644 --- a/src/openfermion/contrib/representability/_multitensor.py +++ b/src/openfermion/contrib/representability/_multitensor.py @@ -3,7 +3,7 @@ from openfermion.contrib.representability._dualbasis import DualBasisElement, DualBasis -class TMap(object): +class TMap: def __init__(self, tensors): """ provide a map of tensor name to tensors @@ -22,7 +22,7 @@ def __iter__(self): yield tt -class MultiTensor(object): +class MultiTensor: def __init__(self, tensors, dual_basis=DualBasis()): """ A collection of tensor objects with maps from name to tensor diff --git a/src/openfermion/contrib/representability/_namedtensor.py b/src/openfermion/contrib/representability/_namedtensor.py index ab4db7da3..f4fe977ab 100644 --- a/src/openfermion/contrib/representability/_namedtensor.py +++ b/src/openfermion/contrib/representability/_namedtensor.py @@ -4,7 +4,7 @@ from openfermion.contrib.representability._bijections import Bijection, index_index_basis -class Tensor(object): +class Tensor: """ Instantiation of named tensor """ diff --git a/src/openfermion/hamiltonians/special_operators_test.py b/src/openfermion/hamiltonians/special_operators_test.py index d4ebbf999..ba528fcd8 100644 --- a/src/openfermion/hamiltonians/special_operators_test.py +++ b/src/openfermion/hamiltonians/special_operators_test.py @@ -173,7 +173,7 @@ def test_init(self): # Test 'c' operator op1 = majorana_operator((2, 0)) op2 = majorana_operator('c2') - op3 = majorana_operator(u'c2') + op3 = majorana_operator('c2') correct = FermionOperator('2^') + FermionOperator('2') self.assertEqual(op1, op2) self.assertEqual(op1, op3) diff --git a/src/openfermion/linalg/davidson.py b/src/openfermion/linalg/davidson.py index 71c087637..3918c0a51 100644 --- a/src/openfermion/linalg/davidson.py +++ b/src/openfermion/linalg/davidson.py @@ -31,7 +31,7 @@ class DavidsonError(Exception): pass -class DavidsonOptions(object): +class DavidsonOptions: """Davidson algorithm iteration options.""" def __init__(self, max_subspace=100, max_iterations=300, eps=1e-6, real_only=False): @@ -68,7 +68,7 @@ def set_dimension(self, dimension): self.max_subspace = min(self.max_subspace, dimension + 1) -class Davidson(object): +class Davidson: """Davidson algorithm to get the n states with smallest eigenvalues.""" def __init__(self, linear_operator, linear_operator_diagonal, options=None): @@ -350,7 +350,7 @@ def __init__(self, qubit_operator, n_qubits=None, options=None): n_qubits(int): Number of qubits. options(DavidsonOptions): Iteration options. """ - super(QubitDavidson, self).__init__( + super().__init__( generate_linear_qubit_operator(qubit_operator, n_qubits, options), get_linear_qubit_operator_diagonal(qubit_operator, n_qubits), options=options, @@ -366,9 +366,7 @@ def __init__(self, sparse_matrix, options=None): sparse_matrix(scipy.sparse.spmatrix): A sparse matrix in scipy. options(DavidsonOptions): Iteration options. """ - super(SparseDavidson, self).__init__( - sparse_matrix, sparse_matrix.diagonal(), options=options - ) + super().__init__(sparse_matrix, sparse_matrix.diagonal(), options=options) def generate_random_vectors(row, col, real_only=False): diff --git a/src/openfermion/linalg/linear_qubit_operator.py b/src/openfermion/linalg/linear_qubit_operator.py index 0dfef6cd3..5a62b87bc 100644 --- a/src/openfermion/linalg/linear_qubit_operator.py +++ b/src/openfermion/linalg/linear_qubit_operator.py @@ -23,7 +23,7 @@ from openfermion.utils.operator_utils import count_qubits -class LinearQubitOperatorOptions(object): +class LinearQubitOperatorOptions: """Options for LinearQubitOperator.""" def __init__(self, processes=10, pool=None): @@ -94,7 +94,7 @@ def __init__(self, qubit_operator, n_qubits=None): ) n_hilbert = 2**n_qubits - super(LinearQubitOperator, self).__init__(shape=(n_hilbert, n_hilbert), dtype=complex) + super().__init__(shape=(n_hilbert, n_hilbert), dtype=complex) self.qubit_operator = qubit_operator self.n_qubits = n_qubits @@ -156,9 +156,7 @@ def __init__(self, qubit_operator, n_qubits=None, options=None): """ n_qubits = n_qubits or count_qubits(qubit_operator) n_hilbert = 2**n_qubits - super(ParallelLinearQubitOperator, self).__init__( - shape=(n_hilbert, n_hilbert), dtype=complex - ) + super().__init__(shape=(n_hilbert, n_hilbert), dtype=complex) self.qubit_operator = qubit_operator self.n_qubits = n_qubits diff --git a/src/openfermion/ops/operators/binary_code.py b/src/openfermion/ops/operators/binary_code.py index 479607280..14eb48764 100644 --- a/src/openfermion/ops/operators/binary_code.py +++ b/src/openfermion/ops/operators/binary_code.py @@ -73,7 +73,7 @@ class BinaryCodeError(Exception): pass -class BinaryCode(object): +class BinaryCode: r"""The BinaryCode class provides a representation of an encoding-decoding pair for binary vectors of different lengths, where the decoding is allowed to be non-linear. diff --git a/src/openfermion/ops/operators/binary_polynomial.py b/src/openfermion/ops/operators/binary_polynomial.py index 672c464f8..795a7b4d9 100644 --- a/src/openfermion/ops/operators/binary_polynomial.py +++ b/src/openfermion/ops/operators/binary_polynomial.py @@ -23,7 +23,7 @@ class BinaryPolynomialError(Exception): pass -class BinaryPolynomial(object): +class BinaryPolynomial: r"""The BinaryPolynomial class provides an analytic representation of non-linear binary functions. An instance of this class describes a term of binary variables (variables of the values {0,1}, indexed diff --git a/src/openfermion/ops/operators/binary_polynomial_test.py b/src/openfermion/ops/operators/binary_polynomial_test.py index cef602bfa..62dafab5d 100644 --- a/src/openfermion/ops/operators/binary_polynomial_test.py +++ b/src/openfermion/ops/operators/binary_polynomial_test.py @@ -36,7 +36,7 @@ def test_init_string(self): self.assertEqual(operator1.terms, [(1,)]) operator1 = BinaryPolynomial('9 w1 w2 + 5') self.assertEqual(str(operator1), '[W1 W2] + [1]') - operator1 = BinaryPolynomial(u'9 w1 w2 + 5') + operator1 = BinaryPolynomial('9 w1 w2 + 5') self.assertEqual(str(operator1), '[W1 W2] + [1]') def test_none_init(self): diff --git a/src/openfermion/ops/operators/symbolic_operator_test.py b/src/openfermion/ops/operators/symbolic_operator_test.py index 0f084b3eb..5e128b858 100644 --- a/src/openfermion/ops/operators/symbolic_operator_test.py +++ b/src/openfermion/ops/operators/symbolic_operator_test.py @@ -155,7 +155,7 @@ def test_many_body_order(self): op1 = DummyOperator1('0^ 3 5^ 6') op2 = op1 + DummyOperator1('8^ 3') - op3 = op2 + DummyOperator1(u'1^ 2 3^ 4 5 ') + op3 = op2 + DummyOperator1('1^ 2 3^ 4 5 ') op4 = DummyOperator2('X0 X1 Y3') op5 = op4 - DummyOperator2('Z0') diff --git a/src/openfermion/ops/representations/doci_hamiltonian.py b/src/openfermion/ops/representations/doci_hamiltonian.py index 8d4fa329b..1587aeb6c 100644 --- a/src/openfermion/ops/representations/doci_hamiltonian.py +++ b/src/openfermion/ops/representations/doci_hamiltonian.py @@ -86,7 +86,7 @@ def __init__(self, constant, hc, hr1, hr2): hr2: The coefficients of ($h^{(r2)}_{p, q}$). This is an n_qubits x n_qubits array of floats. """ - super(DOCIHamiltonian, self).__init__(None) + super().__init__(None) self._n_qubits = hc.shape[0] self._constant = constant diff --git a/src/openfermion/ops/representations/interaction_operator.py b/src/openfermion/ops/representations/interaction_operator.py index 883b83f80..e5330e7bf 100644 --- a/src/openfermion/ops/representations/interaction_operator.py +++ b/src/openfermion/ops/representations/interaction_operator.py @@ -65,9 +65,7 @@ def __init__(self, constant, one_body_tensor, two_body_tensor): n_qubits numpy array of floats. """ # Make sure nonzero elements are only for normal ordered terms. - super(InteractionOperator, self).__init__( - {(): constant, (1, 0): one_body_tensor, (1, 1, 0, 0): two_body_tensor} - ) + super().__init__({(): constant, (1, 0): one_body_tensor, (1, 1, 0, 0): two_body_tensor}) @property def one_body_tensor(self): diff --git a/src/openfermion/ops/representations/interaction_rdm.py b/src/openfermion/ops/representations/interaction_rdm.py index d4b061c3e..b7446a579 100644 --- a/src/openfermion/ops/representations/interaction_rdm.py +++ b/src/openfermion/ops/representations/interaction_rdm.py @@ -39,9 +39,7 @@ def __init__(self, one_body_tensor, two_body_tensor): two_body_tensor: Expectation values . """ - super(InteractionRDM, self).__init__( - {(1, 0): one_body_tensor, (1, 1, 0, 0): two_body_tensor} - ) + super().__init__({(1, 0): one_body_tensor, (1, 1, 0, 0): two_body_tensor}) @property def one_body_tensor(self): diff --git a/src/openfermion/ops/representations/polynomial_tensor.py b/src/openfermion/ops/representations/polynomial_tensor.py index 26484ec6d..9b3f20b47 100644 --- a/src/openfermion/ops/representations/polynomial_tensor.py +++ b/src/openfermion/ops/representations/polynomial_tensor.py @@ -92,7 +92,7 @@ def general_basis_change(general_tensor, rotation_matrix, key): return transformed_general_tensor -class PolynomialTensor(object): +class PolynomialTensor: r"""Class for storing tensor representations of operators that correspond with multilinear polynomials in the fermionic ladder operators. For instance, in a quadratic Hamiltonian (degree 2 polynomial) which diff --git a/src/openfermion/ops/representations/quadratic_hamiltonian.py b/src/openfermion/ops/representations/quadratic_hamiltonian.py index 00a72b3ff..d481d32c3 100644 --- a/src/openfermion/ops/representations/quadratic_hamiltonian.py +++ b/src/openfermion/ops/representations/quadratic_hamiltonian.py @@ -79,11 +79,9 @@ def __init__( # Initialize the PolynomialTensor if antisymmetric_part is None: - super(QuadraticHamiltonian, self).__init__( - {(): constant, (1, 0): combined_hermitian_part} - ) + super().__init__({(): constant, (1, 0): combined_hermitian_part}) else: - super(QuadraticHamiltonian, self).__init__( + super().__init__( { (): constant, (1, 0): combined_hermitian_part, diff --git a/src/openfermion/resource_estimates/integrals/M_250_beta_16_eta_10.h5 b/src/openfermion/resource_estimates/integrals/M_250_beta_16_eta_10.h5 index 10867c310..4b4dd2675 100644 Binary files a/src/openfermion/resource_estimates/integrals/M_250_beta_16_eta_10.h5 and b/src/openfermion/resource_estimates/integrals/M_250_beta_16_eta_10.h5 differ diff --git a/src/openfermion/resource_estimates/integrals/eri_reiher.h5 b/src/openfermion/resource_estimates/integrals/eri_reiher.h5 index 1af236091..1682746cf 100644 Binary files a/src/openfermion/resource_estimates/integrals/eri_reiher.h5 and b/src/openfermion/resource_estimates/integrals/eri_reiher.h5 differ diff --git a/src/openfermion/resource_estimates/pbc/thc/factorizations/kmeans.py b/src/openfermion/resource_estimates/pbc/thc/factorizations/kmeans.py index 223fe278c..743ad2a91 100644 --- a/src/openfermion/resource_estimates/pbc/thc/factorizations/kmeans.py +++ b/src/openfermion/resource_estimates/pbc/thc/factorizations/kmeans.py @@ -20,7 +20,7 @@ """ -class KMeansCVT(object): +class KMeansCVT: def __init__(self, grid: npt.NDArray, max_iteration: int = 100, threshold: float = 1e-6): """Initialize k-means solver to find interpolating points for ISDF. diff --git a/src/openfermion/resource_estimates/utils.py b/src/openfermion/resource_estimates/utils.py index 3a0b84db4..5f1d191d9 100644 --- a/src/openfermion/resource_estimates/utils.py +++ b/src/openfermion/resource_estimates/utils.py @@ -137,7 +137,7 @@ def power_two(m: int) -> int: return 0 -class RunSilent(object): +class RunSilent: """Context manager to prevent function writing to stdout/stderr e.g. for noisy_function(), wrap it like so diff --git a/src/openfermion/testing/testing_utils.py b/src/openfermion/testing/testing_utils.py index f98c1588e..54a39d917 100644 --- a/src/openfermion/testing/testing_utils.py +++ b/src/openfermion/testing/testing_utils.py @@ -219,7 +219,7 @@ def random_quadratic_hamiltonian( return QuadraticHamiltonian(hermitian_mat, antisymmetric_mat, constant, chemical_potential) -class EqualsTester(object): +class EqualsTester: """Tests equality against user-provided disjoint equivalence groups.""" def __init__(self, test_case): @@ -315,7 +315,7 @@ def make_equality_pair(self, factory): self.add_equality_group(factory(), factory()) -class _ClassUnknownToSubjects(object): +class _ClassUnknownToSubjects: """Equality methods should be able to deal with the unexpected.""" def __eq__(self, other): diff --git a/src/openfermion/testing/testing_utils_test.py b/src/openfermion/testing/testing_utils_test.py index 938958dbf..737ae779e 100644 --- a/src/openfermion/testing/testing_utils_test.py +++ b/src/openfermion/testing/testing_utils_test.py @@ -103,7 +103,7 @@ def test_add_equality_group_not_disjoint(self): eq.add_equality_group(1) def test_add_equality_group_bad_hash(self): - class KeyHash(object): + class KeyHash: def __init__(self, k, h): self._k = k self._h = h @@ -124,7 +124,7 @@ def __hash__(self): eq.add_equality_group(KeyHash('c', 2), KeyHash('c', 3)) def test_add_equality_group_exception_hash(self): - class FailHash(object): + class FailHash: def __hash__(self): raise ValueError('injected failure') @@ -135,7 +135,7 @@ def __hash__(self): def test_can_fail_when_forgot_type_check(self): eq = EqualsTester(self) - class NoTypeCheckEqualImplementation(object): + class NoTypeCheckEqualImplementation: def __init__(self): self.x = 1 @@ -151,7 +151,7 @@ def __ne__(self, other): def test_fails_hash_is_default_and_inconsistent(self): eq = EqualsTester(self) - class DefaultHashImplementation(object): + class DefaultHashImplementation: __hash__ = object.__hash__ def __init__(self): @@ -171,7 +171,7 @@ def __ne__(self, other): def test_fails_when_ne_is_inconsistent(self): eq = EqualsTester(self) - class InconsistentNeImplementation(object): + class InconsistentNeImplementation: def __init__(self): self.x = 1 @@ -187,7 +187,7 @@ def __ne__(self, other): def test_fails_when_not_reflexive(self): eq = EqualsTester(self) - class NotReflexiveImplementation(object): + class NotReflexiveImplementation: def __init__(self): self.x = 1 @@ -200,7 +200,7 @@ def __eq__(self, other): def test_fails_when_not_commutative(self): eq = EqualsTester(self) - class NotCommutativeImplementation(object): + class NotCommutativeImplementation: def __init__(self, x): self.x = x diff --git a/src/openfermion/utils/operator_utils.py b/src/openfermion/utils/operator_utils.py index 10d5a67aa..8e55e35cd 100644 --- a/src/openfermion/utils/operator_utils.py +++ b/src/openfermion/utils/operator_utils.py @@ -11,7 +11,6 @@ # limitations under the License. """This module provides generic tools for classes in ops/""" -from builtins import map, zip import marshal import os