From fb84570befc9664f4819600423102c43110409b5 Mon Sep 17 00:00:00 2001 From: Christoph Groth <christoph.groth@cea.fr> Date: Wed, 21 May 2014 15:51:33 +0200 Subject: [PATCH] get rid of backslashes as far as possible (recommended by PEP 8) --- kwant/_system.pyx | 4 +- kwant/builder.py | 30 +++++++-------- kwant/graph/tests/test_core.py | 4 +- kwant/graph/tests/test_utils.py | 4 +- kwant/lattice.py | 31 ++++++++-------- kwant/linalg/lll.py | 4 +- kwant/linalg/mumps.py | 51 ++++++++++++-------------- kwant/linalg/tests/test_linalg.py | 7 ++-- kwant/physics/leads.py | 21 +++++------ kwant/physics/tests/test_leads.py | 8 ++-- kwant/plotter.py | 18 ++++----- kwant/rmt.py | 4 +- kwant/solvers/common.py | 61 +++++++++++++++---------------- kwant/solvers/tests/test_mumps.py | 4 +- kwant/tests/test_comprehensive.py | 3 +- kwant/tests/test_plotter.py | 4 +- 16 files changed, 126 insertions(+), 132 deletions(-) diff --git a/kwant/_system.pyx b/kwant/_system.pyx index ac82fd8e..7e31ed48 100644 --- a/kwant/_system.pyx +++ b/kwant/_system.pyx @@ -16,8 +16,8 @@ from kwant.graph.core cimport CGraph, gintArraySlice from kwant.graph.defs cimport gint from .graph.defs import gint_dtype -msg = 'Hopping from site {0} to site {1} does not match the ' \ - 'dimensions of onsite Hamiltonians of these sites.' +msg = ('Hopping from site {0} to site {1} does not match the ' + 'dimensions of onsite Hamiltonians of these sites.') @cython.boundscheck(False) def make_sparse(ham, args, CGraph gr, diag, diff --git a/kwant/builder.py b/kwant/builder.py index 82efecf1..44425ca0 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -850,8 +850,8 @@ class Builder(object): func = None for sh in self.expand(key): if func is None: - func = self._set_site if isinstance(sh, Site) \ - else self._set_hopping + func = (self._set_site if isinstance(sh, Site) + else self._set_hopping) func(sh, value) def _del_site(self, site): @@ -899,8 +899,8 @@ class Builder(object): func = None for sh in self.expand(key): if func is None: - func = self._del_site if isinstance(sh, Site) \ - else self._del_hopping + func = (self._del_site if isinstance(sh, Site) + else self._del_hopping) func(sh) def eradicate_dangling(self): @@ -1030,9 +1030,9 @@ class Builder(object): raise ValueError('Only builders with a 1D symmetry are allowed.') for hopping in lead_builder.hoppings(): if not -1 <= sym.which(hopping[1])[0] <= 1: - msg = 'Hopping {0} connects non-neighboring lead unit cells.' +\ - 'Only nearest-cell hoppings are allowed ' +\ - '(consider increasing the lead period).' + msg = ('Hopping {0} connects non-neighboring lead unit cells. ' + 'Only nearest-cell hoppings are allowed ' + '(consider increasing the lead period).') raise ValueError(msg.format(hopping)) if not H: raise ValueError('Lead to be attached contains no sites.') @@ -1046,8 +1046,8 @@ class Builder(object): if not lead_only_families: break else: - msg = 'Sites with site families {0} do not appear in the system, ' \ - 'hence the system does not interrupt the lead.' + msg = ('Sites with site families {0} do not appear in the system, ' + 'hence the system does not interrupt the lead.') raise ValueError(msg.format(tuple(lead_only_families))) all_doms = set() @@ -1098,8 +1098,8 @@ class Builder(object): elif new_dom < min_dom: raise ValueError('Builder does not interrupt the lead,' ' this lead cannot be attached.') - if site_new not in self \ - and sym.which(site_new)[0] != max_dom + 1: + if (site_new not in self + and sym.which(site_new)[0] != max_dom + 1): self[site_new] = lead_builder[site_new] added2.add(site_new) covered = True @@ -1184,8 +1184,8 @@ class Builder(object): interface = [id_by_site[isite] for isite in lead.interface] except KeyError, e: t, v, tb = sys.exc_info() - msg = "Lead {0} is attached to a site that does not " \ - "belong to the scattering region:\n {1}" + msg = ("Lead {0} is attached to a site that does not " + "belong to the scattering region:\n {1}") raise ValueError(msg.format(lead_nr, v)) lead_interfaces.append(np.array(interface)) @@ -1293,8 +1293,8 @@ class Builder(object): # to this one has been added already or will be added. fd = sym.which(head)[0] if fd != 1: - msg = 'Further-than-nearest-neighbor cells ' \ - 'are connected by hopping\n{0}.' + msg = ('Further-than-nearest-neighbor cells ' + 'are connected by hopping\n{0}.') raise ValueError(msg.format((tail, head))) continue if head_id >= cell_size: diff --git a/kwant/graph/tests/test_core.py b/kwant/graph/tests/test_core.py index 0aa49893..113f90ac 100644 --- a/kwant/graph/tests/test_core.py +++ b/kwant/graph/tests/test_core.py @@ -10,8 +10,8 @@ from StringIO import StringIO from itertools import izip_longest import numpy as np from nose.tools import assert_equal, assert_raises -from kwant.graph.core import \ - Graph, NodeDoesNotExistError, EdgeDoesNotExistError, DisabledFeatureError +from kwant.graph.core import (Graph, NodeDoesNotExistError, + EdgeDoesNotExistError, DisabledFeatureError) def test_empty(): graph = Graph() diff --git a/kwant/graph/tests/test_utils.py b/kwant/graph/tests/test_utils.py index eaad1f63..cdd468e1 100644 --- a/kwant/graph/tests/test_utils.py +++ b/kwant/graph/tests/test_utils.py @@ -9,8 +9,8 @@ import numpy as np from nose.tools import assert_equal, assert_true from kwant.graph import Graph -from kwant.graph.utils import \ - make_undirected, remove_duplicates, induced_subgraph +from kwant.graph.utils import (make_undirected, remove_duplicates, + induced_subgraph) from kwant.graph.defs import gint_dtype def test_make_undirected(): diff --git a/kwant/lattice.py b/kwant/lattice.py index 0c0646e9..9da49766 100644 --- a/kwant/lattice.py +++ b/kwant/lattice.py @@ -503,8 +503,8 @@ class TranslationalSymmetry(builder.Symmetry): if self.periods.ndim != 2: # TODO: remove the second part of the following message once # everybody got used to it. - msg = "TranslationalSymmetry takes 1d sequences as parameters.\n" \ - "See What's new in Kwant 0.2 in the documentation." + msg = ("TranslationalSymmetry takes 1d sequences as parameters.\n" + "See What's new in Kwant 0.2 in the documentation.") raise ValueError(msg) if np.linalg.matrix_rank(periods) < len(periods): raise ValueError("Translational symmetry periods must be " @@ -549,12 +549,12 @@ class TranslationalSymmetry(builder.Symmetry): bravais_periods = np.dot(self.periods, inv) # Absolute tolerance is correct in the following since we want an error # relative to the closest integer. - if not np.allclose(bravais_periods, np.round(bravais_periods), - rtol=0, atol=1e-8) or \ - not np.allclose([fam.vec(i) for i in bravais_periods], - self.periods): - msg = 'Site family {0} does not have commensurate periods with ' +\ - 'symmetry {1}.' + if (not np.allclose(bravais_periods, np.round(bravais_periods), + rtol=0, atol=1e-8) or + not np.allclose([fam.vec(i) for i in bravais_periods], + self.periods)): + msg = ('Site family {0} does not have commensurate periods with ' + 'symmetry {1}.') raise ValueError(msg.format(fam, self)) bravais_periods = np.array(np.round(bravais_periods), dtype='int') (num_dir, lat_dim) = bravais_periods.shape @@ -596,8 +596,7 @@ class TranslationalSymmetry(builder.Symmetry): print m raise RuntimeError('Adding site family failed.') - det_x_inv_m = \ - np.array(np.round(det_m * np.linalg.inv(m)), dtype=int) + det_x_inv_m = np.array(np.round(det_m * np.linalg.inv(m)), dtype=int) assert (np.dot(m, det_x_inv_m) // det_m == np.identity(lat_dim)).all() det_x_inv_m_part = det_x_inv_m[:num_dir, :] @@ -633,20 +632,20 @@ class TranslationalSymmetry(builder.Symmetry): if b is None: return builder.Site(a.family, a.tag + delta, True) elif b.family == a.family: - return builder.Site(a.family, a.tag + delta, True), \ - builder.Site(b.family, b.tag + delta, True) + return (builder.Site(a.family, a.tag + delta, True), + builder.Site(b.family, b.tag + delta, True)) else: m_part = self._get_site_family_data(b.family)[0] try: delta2 = ta.dot(m_part, element) except ValueError: - msg = 'Expecting a {0}-tuple group element, ' + \ - 'but got `{1}` instead.' + msg = ('Expecting a {0}-tuple group element, ' + 'but got `{1}` instead.') raise ValueError(msg.format(self.num_directions, element)) if self.is_reversed: delta2 = -delta2 - return builder.Site(a.family, a.tag + delta, True), \ - builder.Site(b.family, b.tag + delta2, True) + return (builder.Site(a.family, a.tag + delta, True), + builder.Site(b.family, b.tag + delta2, True)) def to_fd(self, a, b=None): return self.act(-self.which(a), a, b) diff --git a/kwant/linalg/lll.py b/kwant/linalg/lll.py index 603d34a2..6586c206 100644 --- a/kwant/linalg/lll.py +++ b/kwant/linalg/lll.py @@ -80,8 +80,8 @@ def lll(basis, c=1.34): # Main part of LLL algorithm. i = 0 while i < m-1: - if np.linalg.norm(vecsstar[i]) ** 2 < \ - c * np.linalg.norm(vecsstar[i+1]) ** 2: + if (np.linalg.norm(vecsstar[i]) ** 2 < + c * np.linalg.norm(vecsstar[i+1]) ** 2): i += 1 else: vecsstar[i+1] += u[i+1, i] * vecsstar[i] diff --git a/kwant/linalg/mumps.py b/kwant/linalg/mumps.py index 170a2523..f6fa3844 100644 --- a/kwant/linalg/mumps.py +++ b/kwant/linalg/mumps.py @@ -97,18 +97,17 @@ class AnalysisStatistics(object): self.time = time def __str__(self): - string = " estimated memory for in-core factorization: " + \ - str(self.est_mem_incore) + " mbytes\n" - string += " estimated memory for out-of-core factorization: " + \ - str(self.est_mem_ooc) + " mbytes\n" - string += " estimated number of nonzeros in factors: " + \ - str(self.est_nonzeros) + "\n" - string += " estimated number of flops: " + str(self.est_flops) + "\n" - string += " ordering used: " + self.ordering + parts = ["estimated memory for in-core factorization:", + str(self.est_mem_incore), "mbytes\n", + "estimated memory for out-of-core factorization:", + str(self.est_mem_ooc), "mbytes\n", + "estimated number of nonzeros in factors:", + str(self.est_nonzeros), "\n", + "estimated number of flops:", str(self.est_flops), "\n", + "ordering used:", self.ordering] if hasattr(self, "time"): - string += "\n analysis time: " + str(self.time) + " secs" - - return string + parts.extend(["\n analysis time:", str(self.time), "secs"]) + return " ".join(parts) class FactorizationStatistics(object): @@ -131,19 +130,18 @@ class FactorizationStatistics(object): self.time = time def __str__(self): - string = " off-diagonal pivots: " + str(self.offdiag_pivots) + "\n" - string += " delayed pivots: " + str(self.delayed_pivots) + "\n" - string += " tiny pivots: " + str(self.tiny_pivots) + "\n" + parts = ["off-diagonal pivots:", str(self.offdiag_pivots), "\n", + "delayed pivots:", str(self.delayed_pivots), "\n", + "tiny pivots:", str(self.tiny_pivots), "\n"] if hasattr(self, "ordering"): - string += " ordering used: " + self.ordering + "\n" - string += " memory used during factorization : " + str(self.memory) + \ - " mbytes\n" - string += " nonzeros in factored matrix: " + str(self.nonzeros) + "\n" - string += " floating point operations: " + str(self.flops) + parts.extend(["ordering used:", self.ordering, "\n"]) + parts.extend(["memory used during factorization:", str(self.memory), + "mbytes\n", + "nonzeros in factored matrix:", str(self.nonzeros), "\n", + "floating point operations:", str(self.flops)]) if hasattr(self, "time"): - string += "\n factorization time: " + str(self.time) +" secs" - - return string + parts.extend(["\n factorization time:", str(self.time), "secs"]) + return " ".join(parts) class MUMPSContext(object): @@ -348,8 +346,8 @@ class MUMPSContext(object): x = np.empty((b.shape[0], b.shape[1]), order='F', dtype=self.data.dtype) - dtype, col_ptr, row_ind, data = \ - _make_sparse_rhs_from_csc(b, self.data.dtype) + dtype, col_ptr, row_ind, data = _make_sparse_rhs_from_csc( + b, self.data.dtype) if b.shape[0] != self.n: raise ValueError("Right hand side has wrong size") @@ -498,9 +496,8 @@ def schur_complement(a, indices, ordering='auto', ooc=False, pivot_tol=0.01, if not calc_stats: return schur_compl else: - return schur_compl, \ - FactorizationStatistics(mumps_instance, time=t2 - t1, - include_ordering=True) + return (schur_compl, FactorizationStatistics( + mumps_instance, time=t2 - t1, include_ordering=True)) # Some internal helper functions diff --git a/kwant/linalg/tests/test_linalg.py b/kwant/linalg/tests/test_linalg.py index f1526195..fa0838c2 100644 --- a/kwant/linalg/tests/test_linalg.py +++ b/kwant/linalg/tests/test_linalg.py @@ -6,9 +6,10 @@ # the AUTHORS file at the top-level directory of this distribution and at # http://kwant-project.org/authors. -from kwant.linalg import lu_factor, lu_solve, rcond_from_lu, gen_eig, schur, \ - convert_r2c_schur, order_schur, evecs_from_schur, gen_schur, \ - convert_r2c_gen_schur, order_gen_schur, evecs_from_gen_schur +from kwant.linalg import ( + lu_factor, lu_solve, rcond_from_lu, gen_eig, schur, + convert_r2c_schur, order_schur, evecs_from_schur, gen_schur, + convert_r2c_gen_schur, order_gen_schur, evecs_from_gen_schur) from nose.tools import assert_equal, assert_true import numpy as np from _test_utils import _Random, assert_array_almost_equal diff --git a/kwant/physics/leads.py b/kwant/physics/leads.py index 2e8ea9f9..269b9b3e 100644 --- a/kwant/physics/leads.py +++ b/kwant/physics/leads.py @@ -263,8 +263,7 @@ def setup_linsys(h_cell, h_hop, tol=1e6, stabilization=None): # the projected one (v^dagger psi lambda^-1, s u^dagger psi). def extract_wf(psi, lmbdainv): - wf = - dot(u, psi[: n_nonsing] * lmbdainv) - \ - dot(v, psi[n_nonsing:]) + wf = -dot(u, psi[: n_nonsing] * lmbdainv) - dot(v, psi[n_nonsing:]) if need_to_stabilize: wf += 1j * (dot(v, psi[: n_nonsing]) + dot(u, psi[n_nonsing:] * lmbdainv)) @@ -572,14 +571,14 @@ def modes(h_cell, h_hop, tol=1e6, stabilization=None): # False if h_hop is purely imaginary if not (np.any(h_hop.real) or np.any(h_hop.imag)): v = np.empty((0, m)) - return PropagatingModes(np.empty((0, n)), np.empty((0,)), - np.empty((0,))), \ - StabilizedModes(np.empty((0, 0)), np.empty((0, 0)), 0, v) + return (PropagatingModes(np.empty((0, n)), np.empty((0,)), + np.empty((0,))), + StabilizedModes(np.empty((0, 0)), np.empty((0, 0)), 0, v)) # Defer most of the calculation to helper routines. matrices, v, extract = setup_linsys(h_cell, h_hop, tol, stabilization) - ev, evanselect, propselect, vec_gen, ord_schur =\ - unified_eigenproblem(*(matrices + (tol,))) + ev, evanselect, propselect, vec_gen, ord_schur = unified_eigenproblem( + *(matrices + (tol,))) if v is not None: n = v.shape[1] @@ -591,8 +590,8 @@ def modes(h_cell, h_hop, tol=1e6, stabilization=None): # Compute the propagating eigenvectors. prop_vecs = vec_gen(propselect) # Compute their velocity, and, if necessary, rotate them - prop_vecs, real_space_data = \ - make_proper_modes(ev[propselect], prop_vecs, extract, tol) + prop_vecs, real_space_data = make_proper_modes( + ev[propselect], prop_vecs, extract, tol) vecs = np.c_[prop_vecs[n:], evan_vecs[n:]] vecslmbdainv = np.c_[prop_vecs[:n], evan_vecs[:n]] @@ -674,6 +673,6 @@ def square_selfenergy(width, hopping, fermi_energy): result = np.empty((width, width), dtype=complex) for i in xrange(width): for j in xrange(width): - result[i, j] = hopping * \ - (psi_p_i[:, i] * psi_p_i[:, j].conj() * f_p).sum() + result[i, j] = hopping * ( + psi_p_i[:, i] * psi_p_i[:, j].conj() * f_p).sum() return result diff --git a/kwant/physics/tests/test_leads.py b/kwant/physics/tests/test_leads.py index 21d6f662..8106de76 100644 --- a/kwant/physics/tests/test_leads.py +++ b/kwant/physics/tests/test_leads.py @@ -282,8 +282,8 @@ def test_algorithm_equivalence(): for vecs, algo in izip(evan_vecs, algos): # Evanescent modes must span the same linear space. - assert np.linalg.matrix_rank(np.c_[vecs, evan_vecs[0]], tol=1e-12) == \ - vecs.shape[1], msg.format(algo) + assert (np.linalg.matrix_rank(np.c_[vecs, evan_vecs[0]], tol=1e-12) == + vecs.shape[1]), msg.format(algo) def test_for_all_evs_equal(): @@ -308,11 +308,11 @@ def test_dtype_linsys(): h_hop) assert lsys.eigenproblem[0].dtype == np.float64 - lsys = kwant.physics.leads.setup_linsys(h_cell.astype(np.complex128) + lsys = kwant.physics.leads.setup_linsys(h_cell.astype(np.complex128) - 0.3*np.eye(2), h_hop.astype(np.complex128)) assert lsys.eigenproblem[0].dtype == np.float64 - + # energy=1 is an eigenstate of the isolated cell Hamiltonian, # i.e. a complex self-energy stabilization is necessary lsys = kwant.physics.leads.setup_linsys(h_cell - 1*np.eye(2), diff --git a/kwant/plotter.py b/kwant/plotter.py index 8bc192a1..f90c45b3 100644 --- a/kwant/plotter.py +++ b/kwant/plotter.py @@ -149,7 +149,7 @@ if mpl_enabled: corners = np.zeros((3, 8, 6), np.float_) corners[0, [0, 1, 2, 3], 0] = corners[0, [4, 5, 6, 7], 1] = \ corners[0, [0, 1, 4, 5], 2] = corners[0, [2, 3, 6, 7], 3] = \ - corners[0, [0, 2, 4, 6], 4] = corners[0, [1, 3, 5, 7], 5] = 1. + corners[0, [0, 2, 4, 6], 4] = corners[0, [1, 3, 5, 7], 5] = 1.0 class Line3DCollection(mplot3d.art3d.Line3DCollection): @@ -624,8 +624,8 @@ def output_fig(fig, output_mode='auto', file=None, savefile_opts=None, try: fake_fig = matplotlib.pyplot.figure() except AttributeError: - msg = 'matplotlib.pyplot is unavailable. Execute `import ' \ - 'matplotlib.pyplot` or use a different output mode.' + msg = ('matplotlib.pyplot is unavailable. Execute `import ' + 'matplotlib.pyplot` or use a different output mode.') raise RuntimeError(msg) fake_fig.canvas.figure = fig fig.canvas = fake_fig.canvas @@ -699,8 +699,8 @@ def sys_leads_sites(sys, num_lead_cells=2): for leadnr, lead in enumerate(sys.leads): start = len(sites) # We will only plot leads with a graph and with a symmetry. - if hasattr(lead, 'graph') and hasattr(lead, 'symmetry') and \ - len(sys.lead_interfaces[leadnr]): + if (hasattr(lead, 'graph') and hasattr(lead, 'symmetry') and + len(sys.lead_interfaces[leadnr])): sites.extend(((site, leadnr, i) for site in xrange(lead.cell_size) for i in xrange(num_lead_cells))) @@ -844,8 +844,8 @@ def sys_leads_hoppings(sys, num_lead_cells=2): for leadnr, lead in enumerate(sys.leads): start = len(hoppings) # We will only plot leads with a graph and with a symmetry. - if hasattr(lead, 'graph') and hasattr(lead, 'symmetry') and \ - len(sys.lead_interfaces[leadnr]): + if (hasattr(lead, 'graph') and hasattr(lead, 'symmetry') and + len(sys.lead_interfaces[leadnr])): hoppings.extend(((hop, leadnr, i) for hop in ll_hoppings(lead) for i in xrange(num_lead_cells))) lead_cells.append(slice(start, len(hoppings))) @@ -1098,8 +1098,8 @@ def plot(sys, num_lead_cells=2, unit='nn', def resize_to_dim(array): if array.shape[1] != dim: ar = np.zeros((len(array), dim), dtype=float) - ar[:, : min(dim, array.shape[1])] = \ - array[:, : min(dim, array.shape[1])] + ar[:, : min(dim, array.shape[1])] = array[ + :, : min(dim, array.shape[1])] return ar else: return array diff --git a/kwant/rmt.py b/kwant/rmt.py index 1d3fbb72..97ad0bc5 100644 --- a/kwant/rmt.py +++ b/kwant/rmt.py @@ -143,8 +143,8 @@ def gaussian(n, sym='A', v=1.): elif sym == 'CII': sigma_z = np.array((n // 4) * [1, 1, -1, -1]) idx_sigma_x = np.arange(n) + 2 * sigma_z - h += sigma_z.reshape(-1, 1) * h[idx_sigma_x][:, idx_sigma_x].conj() * \ - sigma_z + h += (sigma_z.reshape(-1, 1) * h[idx_sigma_x][:, idx_sigma_x].conj() * + sigma_z) factor /= np.sqrt(2) h *= factor diff --git a/kwant/solvers/common.py b/kwant/solvers/common.py index 5b16533c..9350adae 100644 --- a/kwant/solvers/common.py +++ b/kwant/solvers/common.py @@ -172,8 +172,10 @@ class SparseSolver(object): if not realspace: prop, stab = lead.modes(energy, args) lead_info.append(prop) - u, ulinv, nprop, svd_v = \ - stab.vecs, stab.vecslmbdainv, stab.nmodes, stab.sqrt_hop + u = stab.vecs + ulinv = stab.vecslmbdainv + nprop = stab.nmodes + svd_v = stab.sqrt_hop if len(u) == 0: rhs.append(None) @@ -190,11 +192,11 @@ class SparseSolver(object): iface_orbs = np.r_[tuple(slice(offsets[i], offsets[i + 1]) for i in interface)] - n_lead_orbs = svd_v.shape[0] if svd_v is not None else \ - u_out.shape[0] + n_lead_orbs = (svd_v.shape[0] if svd_v is not None + else u_out.shape[0]) if n_lead_orbs != len(iface_orbs): - msg = 'Lead {0} has hopping with dimensions ' + \ - 'incompatible with its interface dimension.' + msg = ('Lead {0} has hopping with dimensions ' + 'incompatible with its interface dimension.') raise ValueError(msg.format(leadnum)) coords = np.r_[[np.arange(len(iface_orbs))], [iface_orbs]] @@ -203,8 +205,8 @@ class SparseSolver(object): if svd_v is not None: v_sp = sp.csc_matrix(svd_v.T.conj()) * transf - vdaguout_sp = transf.T * \ - sp.csc_matrix(np.dot(svd_v, u_out)) + vdaguout_sp = (transf.T * + sp.csc_matrix(np.dot(svd_v, u_out))) lead_mat = - ulinv_out else: v_sp = transf @@ -233,9 +235,9 @@ class SparseSolver(object): for i in interface)] if sigma.shape != 2 * vars.shape: - msg = 'Self-energy dimension for lead {0} does not ' + \ - 'match the total number of orbitals of the ' + \ - 'sites for which it is defined.' + msg = ('Self-energy dimension for lead {0} does not ' + 'match the total number of orbitals of the ' + 'sites for which it is defined.') raise ValueError(msg.format(leadnum)) y, x = np.meshgrid(vars, vars) @@ -326,9 +328,9 @@ class SparseSolver(object): in_leads = range(n) if out_leads is None: out_leads = range(n) - if sorted(in_leads) != in_leads or sorted(out_leads) != out_leads or \ - len(set(in_leads)) != len(in_leads) or \ - len(set(out_leads)) != len(out_leads): + if (sorted(in_leads) != in_leads or sorted(out_leads) != out_leads or + len(set(in_leads)) != len(in_leads) or + len(set(out_leads)) != len(out_leads)): raise ValueError("Lead lists must be sorted and " "with unique entries.") if len(in_leads) == 0 or len(out_leads) == 0: @@ -409,9 +411,9 @@ class SparseSolver(object): in_leads = range(n) if out_leads is None: out_leads = range(n) - if sorted(in_leads) != in_leads or sorted(out_leads) != out_leads or \ - len(set(in_leads)) != len(in_leads) or \ - len(set(out_leads)) != len(out_leads): + if (sorted(in_leads) != in_leads or sorted(out_leads) != out_leads or + len(set(in_leads)) != len(in_leads) or + len(set(out_leads)) != len(out_leads)): raise ValueError("Lead lists must be sorted and " "with unique entries.") if len(in_leads) == 0 or len(out_leads) == 0: @@ -471,9 +473,8 @@ class SparseSolver(object): raise NotImplementedError("ldos for leads with only " "self-energy is not implemented yet.") - linsys, lead_info = \ - self._make_linear_sys(sys, xrange(len(sys.leads)), energy, args, - check_hermiticity) + linsys, lead_info = self._make_linear_sys( + sys, xrange(len(sys.leads)), energy, args, check_hermiticity) ldos = np.zeros(linsys.num_orb, float) factored = None @@ -532,12 +533,11 @@ class WaveFunction(object): for lead in sys.leads: if not hasattr(lead, 'modes'): # TODO: figure out what to do with self-energies. - msg = 'Wave functions for leads with only self-energy' + \ - ' are not available yet.' + msg = ('Wave functions for leads with only self-energy' + ' are not available yet.') raise NotImplementedError(msg) - linsys, lead_info = \ - solver._make_linear_sys(sys, xrange(len(sys.leads)), energy, args, - check_hermiticity) + linsys, lead_info = solver._make_linear_sys( + sys, xrange(len(sys.leads)), energy, args, check_hermiticity) self.solve = solver._solve_linear_sys self.rhs = linsys.rhs self.factorized_h = solver._factorized(linsys.lhs) @@ -630,9 +630,8 @@ class SMatrix(BlockResult): return np.linalg.norm(self.submatrix(lead_out, lead_in)) ** 2 def __repr__(self): - return "SMatrix(data=%r, lead_info=%r, " \ - "out_leads=%r, in_leads=%r)" % (self.data, self.lead_info, - self.out_leads, self.in_leads) + return ("SMatrix(data=%r, lead_info=%r, out_leads=%r, in_leads=%r)" % + (self.data, self.lead_info, self.out_leads, self.in_leads)) class GreensFunction(BlockResult): @@ -709,6 +708,6 @@ class GreensFunction(BlockResult): return result def __repr__(self): - return "GreensFunction(data=%r, lead_info=%r, " \ - "out_leads=%r, in_leads=%r)" % (self.data, self.lead_info, - self.out_leads, self.in_leads) + return ("GreensFunction(data=%r, lead_info=%r, " + "out_leads=%r, in_leads=%r)" % + (self.data, self.lead_info, self.out_leads, self.in_leads)) diff --git a/kwant/solvers/tests/test_mumps.py b/kwant/solvers/tests/test_mumps.py index c0f40078..c28f263b 100644 --- a/kwant/solvers/tests/test_mumps.py +++ b/kwant/solvers/tests/test_mumps.py @@ -9,8 +9,8 @@ #from nose.plugins.skip import Skip, SkipTest from numpy.testing.decorators import skipif try: - from kwant.solvers.mumps import \ - smatrix, greens_function, ldos, wave_function, options, reset_options + from kwant.solvers.mumps import ( + smatrix, greens_function, ldos, wave_function, options, reset_options) import _test_sparse no_mumps = False except ImportError: diff --git a/kwant/tests/test_comprehensive.py b/kwant/tests/test_comprehensive.py index 918001d1..bf4bac9d 100644 --- a/kwant/tests/test_comprehensive.py +++ b/kwant/tests/test_comprehensive.py @@ -16,8 +16,7 @@ def onsite(site, phi, salt): def test_qhe(W=16, L=8): def central_region(pos): x, y = pos - return -L < x < L and \ - abs(y) < W - 5.5 * math.exp(-x**2 / 5**2) + return -L < x < L and abs(y) < W - 5.5 * math.exp(-x**2 / 5**2) lat = kwant.lattice.square() sys = kwant.Builder() diff --git a/kwant/tests/test_plotter.py b/kwant/tests/test_plotter.py index 525091af..d5ffc4ad 100644 --- a/kwant/tests/test_plotter.py +++ b/kwant/tests/test_plotter.py @@ -100,8 +100,8 @@ def test_plot(): for color in color_opts: for sys in (sys2d, sys3d): fig = plot(sys, site_color=color, cmap='binary', file=out) - if color != 'k' and \ - isinstance(color(iter(sys2d.sites()).next()), float): + if (color != 'k' and + isinstance(color(iter(sys2d.sites()).next()), float)): assert fig.axes[0].collections[0].get_array() is not None assert len(fig.axes[0].collections) == (8 if sys is sys2d else 6) -- GitLab