FLAKE8

parent 8cb38ebf
Pipeline #46371354 failed with stage
in 1 minute and 56 seconds
[flake8]
ignore = E129,E741,W293,W503,W504
ignore = E,W,E129,E741,W293,W503,W504
......@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# Emacs: treat this as -*- python -*-
# flake8: noqa
from __future__ import print_function
from optparse import OptionParser
......
......@@ -29,9 +29,9 @@ def polygon(x, y1, y2, *args, **kwargs):
def plot_count(dpi=70):
year, month, f, c, py, test, doc, rst = np.loadtxt('lines.data').T
date = year + (month - 1) / 12
fig = pl.figure(1, figsize=(10, 5), dpi=dpi)
ax = fig.add_subplot(111)
fig.add_subplot(111)
polygon(date, c + py + test + doc, c + py + test + doc + rst,
facecolor='m', label='Documentation (.rst)')
polygon(date, c + py + test, c + py + test + doc,
......@@ -56,16 +56,15 @@ def count_lines():
stop = now.year, now.month
year = 2005
month = 11
fd = open('lines.data', 'w')
results = []
while (year, month) <= stop:
hash = subprocess.check_output(
'git rev-list -n 1 --before="{}-{}-01 12:00" master'
.format(year, month), shell=True).strip()
print(year, month, hash)
subprocess.call(['git', 'checkout', hash])
c = count('c', '\*.[ch]')
py = count('.', '\*.py')
test = count('gpaw/test', '\*.py')
......@@ -78,7 +77,7 @@ def count_lines():
if month == 13:
month = 1
year += 1
fd.close()
......
#!/usr/bin/env python
# flake8: noqa
from __future__ import print_function
from optparse import OptionParser
......
......@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# Emacs: treat this as -*- python -*-
from __future__ import print_function
from optparse import OptionParser
parser = OptionParser(usage='%prog [options]',
......@@ -21,10 +20,6 @@ opt, args = parser.parse_args()
import os
import datetime
from math import sqrt
import numpy as np
colors = [
......@@ -39,13 +34,11 @@ colors = [
'gray',
'gray']
from ase.data import atomic_numbers as numbers
def plot(xdata, ydata, std,
title,
xlabel, ylabel,
label, color, num=1):
import matplotlib
#matplotlib.use('Agg')
import pylab
......@@ -136,22 +129,16 @@ def analyse_benchmark(ncores=8, startcores=1, machine='TEST', runs=7):
# absolute path to directory
root_abspath = os.path.abspath(opt.dir)
# length of directory name
rootlen = len(root_abspath) + 1
ref_value_3300 = -44.85826
ref_SCF_3300 = 19
ref_value_3301 = -44.85709
ref_SCF_3301 = 31
ref_value_3721 = -44.85666
ref_SCF_3721 = 35
# ref_value_3721 = -44.85666
# ref_SCF_3721 = 35
ref_value_5147 = -44.83504
ref_SCF_5147 = 30
ref_value_6383 = -44.84197
ref_SCF_6383 = 28
ref_value = ref_value_6383
ref_SCF = ref_SCF_6383
tolerance = 0.0001
......@@ -181,20 +168,16 @@ def analyse_benchmark(ncores=8, startcores=1, machine='TEST', runs=7):
if len(str(gpaw_version)) > 1:
if gpaw_version <= 6383:
ref_value = ref_value_6383
ref_SCF = ref_SCF_6383
if gpaw_version <= 5147:
ref_value = ref_value_5147
ref_SCF = ref_SCF_5147
if gpaw_version <= 3720:
ref_value = ref_value_3301
ref_SCF = ref_SCF_3301
if gpaw_version <= 3300:
ref_value = ref_value_3300
ref_SCF = ref_SCF_3300
elif len(str(gpaw_version)) == 1:
if gpaw_version <= 4:
ref_value = ref_value_3300
ref_SCF = ref_SCF_3300
# ref_SCF = ref_SCF_3300
gpaw_versions.append(gpaw_version)
# search for timings
print('gpaw version %d' % gpaw_version)
......@@ -261,15 +244,11 @@ def analyse_benchmark(ncores=8, startcores=1, machine='TEST', runs=7):
# q.append(np.std(pre_results[p]))
import matplotlib
matplotlib.use('Agg')
from matplotlib import pylab, ticker
from twiny import twiny
from matplotlib import pylab
# from http://matplotlib.sourceforge.net/examples/dashtick.py
ROTATION=75
DASHROTATION=115
DASHBASE=5
DASHLEN=25
DASHSTAGGER=3
FONTSIZE=10
def dashlen(step):
return DASHBASE+(DASHLEN*(step%DASHSTAGGER))
# print scaling results
......
from pylab import *
from pylab import gcf, gca, draw_if_interactive
def twiny(ay=None):
"""
Make a second axes overlay ay (or the current axes if ay is None)
......
# flake8: noqa
class Density:
def __init__(self):
self.gd = None
......
# flake8: noqa
class PAW(ASECalculator):
def __init__(self, restart=None, **kwargs):
ASECalculator.__init__(self)
......@@ -14,7 +15,7 @@ class PAW(ASECalculator):
self.density.read(reader)
self.hamiltonian.read(reader)
self.wfs = self.wfs.read(reader)
def update(self, atoms, **kwargs):
"""Lazy update."""
self.density.update(self.atoms, kwargs)
......@@ -23,7 +24,7 @@ class PAW(ASECalculator):
# If we change mode, we could get a completely new type of
# wave function object:
self.wfs = self.wfs.update(self.atoms, kwargs)
def set(self, **kwargs):
self.update(self,atoms, **kwargs)
......
from __future__ import print_function
# flake8: noqa
"""
File content::
0: "IOASE..."
8: version
16: nitems (int64)
......@@ -42,7 +43,7 @@ def writeint(fd, n, pos=None):
if pos is not None:
fd.seek(pos)
np.array(n, np.int64).tofile(fd)
class Writer:
def __init__(self, fd, mode='w', data=None):
......@@ -58,7 +59,7 @@ class Writer:
read() method."""
assert np.little_endian
if data is None:
data = {}
if mode == 'w':
......@@ -67,7 +68,7 @@ class Writer:
self.offsets = np.array([-1], np.int64)
fd = open(fd, 'wb')
# Write file format identifier:
fd.write(b'IOASE...')
np.array([VERSION, self.nitems, self.itemoffsets],
......@@ -75,7 +76,7 @@ class Writer:
self.offsets.tofile(fd)
elif mode == 'a':
fd = open(fd, 'r+b')
version, self.nitems, self.itemoffsets, offsets = \
read_header(fd)
assert version == VERSION
......@@ -87,32 +88,32 @@ class Writer:
fd.seek(0, 2)
else:
2 / 0
self.fd = fd
self.data = data
# Shape and dtype of array being filled:
self.shape = (0,)
self.dtype = None
def add_array(self, name, shape, dtype=float, delayed_read=True):
if isinstance(shape, int):
shape = (shape,)
i = align(self.fd)
self.data[name] = {'_type': 'numpy.ndarray',
'shape': shape,
'dtype': np.dtype(dtype).name,
'offset': i}
if delayed_read:
self.data[name]['_delayed'] = True
assert self.shape[0] == 0, 'last array not done'
self.dtype = dtype
self.shape = shape
def fill(self, a):
assert a.dtype == self.dtype
if a.shape[1:] == self.shape[1:]:
......@@ -122,7 +123,7 @@ class Writer:
assert a.shape == self.shape[1:]
self.shape = (self.shape[0] - 1,) + self.shape[1:]
assert self.shape[0] >= 0
a.tofile(self.fd)
def sync(self):
......@@ -136,7 +137,7 @@ class Writer:
s = encode(self.data).encode()
writeint(self.fd, len(s))
self.fd.write(s)
n = len(self.offsets)
if self.nitems >= n:
offsets = np.zeros(n * N1, np.int64)
......@@ -145,7 +146,7 @@ class Writer:
offsets.tofile(self.fd)
writeint(self.fd, self.itemoffsets, 24)
self.offsets = offsets
self.offsets[self.nitems] = i
writeint(self.fd, i, self.itemoffsets + self.nitems * 8)
self.nitems += 1
......@@ -153,7 +154,7 @@ class Writer:
self.fd.flush()
self.fd.seek(0, 2) # end of file
self.data = {}
def write(self, **kwargs):
"""Write data.
......@@ -161,7 +162,7 @@ class Writer:
writer.write(n=7, s='abc', a=np.zeros(3), density=density).
"""
for name, value in kwargs.items():
if isinstance(value, (bool, int, float, complex,
dict, list, tuple, str)):
......@@ -176,12 +177,12 @@ class Writer:
value.__class__.__name__}
writer = Writer(self.fd, data=self.data[name])
value.write(writer)
def close(self):
self.sync()
self.fd.close()
def read_header(fd):
fd.seek(0)
assert fd.read(8) == b'IOASE...'
......@@ -190,21 +191,21 @@ def read_header(fd):
offsets = np.fromfile(fd, np.int64, nitems)
return version, nitems, itemoffsets, offsets
class Reader:
def __init__(self, fd, item=0, data=None):
"""Create hierarchy of readers.
Store data as attributes for easy access and to allow
tab-completion."""
assert np.little_endian
if isinstance(fd, str):
fd = open(fd, 'rb')
self.fd = fd
if data is None:
self.version, self.nitems, self.itemoffsets, self.offsets = \
read_header(fd)
......@@ -222,20 +223,20 @@ class Reader:
value = value.read()
else:
value = Reader(self.fd, data=value)
data[name] = value
self.data = data
def __dir__(self):
return self.data.keys()
def __getattr__(self, attr):
value = self.data[attr]
if isinstance(value, NDArrayReader):
return value.read()
return value
def proxy(self, name):
value = self.data[name]
assert isinstance(value, NDArrayReader)
......@@ -243,17 +244,17 @@ class Reader:
def __len__(self):
return self.nitems
def _read_data(self, item):
self.fd.seek(self.offsets[item])
size = np.fromfile(self.fd, np.int64, 1)[0]
data = decode(self.fd.read(size).decode())
return data
def __getitem__(self, i):
data = self._read_data(i)
return Reader(self.fd, data=data)
read = Reader
write = Writer
......@@ -265,18 +266,18 @@ class NDArrayReader:
self.shape = tuple(shape)
self.dtype = dtype
self.offset = offset
self.ndim = len(self.shape)
self.itemsize = dtype.itemsize
self.size = np.prod(self.shape)
self.nbytes = self.size * self.itemsize
def __len__(self):
return self.shape[0]
def read(self):
return self[:]
def __getitem__(self, i):
if isinstance(i, int):
return self[i:i + 1][0]
......@@ -297,19 +298,19 @@ def main():
exec('x = ' + rags[1])
# csv for 2d ...
print(x)
if __name__ == '__main__':
class A:
def write(self, writer):
writer.write(x=np.ones((2, 3)))
@staticmethod
def read(reader):
a = A()
a.x = reader.x
return a
w = Writer('a.ioase')
w.write(a=A(), y=9)
w.write(s='abc')
......@@ -319,7 +320,7 @@ if __name__ == '__main__':
w.write(s='abc3', z=np.ones(7, int))
w.close()
print(w.data)
r = Reader('a.ioase')
print(r.y, r.s)
print(A.read(r.a).x)
......@@ -327,7 +328,7 @@ if __name__ == '__main__':
print(r[1].s)
print(r[2].s)
print(r[2].z)
w = Writer('a.ioase', 'a')
print(w.nitems, w.offsets)
w.write(d={'h': [1, 'asdf']})
......
......@@ -3,7 +3,7 @@ processes, each process working on a separate system."""
from __future__ import print_function
from gpaw import GPAW, mpi
import numpy as np
from ase import Atoms, Atom
from ase import Atoms
cell = (8., 8., 8.)
p = 4.
......@@ -16,7 +16,7 @@ if rank == 0:
system = Atoms('N', [(p, p, p)], magmoms=[3], cell=cell)
elif rank == 1:
system = Atoms('N2', [(p, p, p + separation / 2.),
(p, p, p - separation / 2.)],
(p, p, p - separation / 2.)],
cell=cell)
else:
raise Exception('This example uses only two processes')
......
from ase import *
from ase.io import *
from ase.parallel import parprint
from gpaw import GPAW
from gpaw.poisson import PoissonSolver
from gpaw.mpi import world, size
from gpaw import *
from gpaw.poisson import *
from gpaw.mpi import world, size, rank
from gpaw.lrtddft2 import *
from gpaw.lrtddft2 import LrTDDFT2
from gpaw.lrtddft2.lr_communicators import LrCommunicators
# atoms, gs_calc = restart('r-methyl-oxirane.gpw')
......
from ase import *
from ase.io import *
from ase.parallel import parprint
from gpaw import *
from gpaw.poisson import *
from gpaw.mpi import world, size, rank
from gpaw import GPAW
from gpaw.poisson import PoissonSolver
from gpaw.mpi import world, size
from gpaw.lrtddft2 import *
from gpaw.lrtddft2 import LrTDDFT2
from gpaw.lrtddft2.lr_communicators import LrCommunicators
# atoms, gs_calc = restart('r-methyl-oxirane.gpw')
......
from gpaw import *
from ase.io import *
from gpaw import GPAW
from ase.io import read
L = 14 # ang
atoms = read('r-methyl-oxirane.xyz')
......
# Creates: na2_casida_Ffe.png, na2_casida_Frho.png, na2_casida_Fphi.png
# -*- coding: utf-8 -*-
from gpaw.mpi import world
assert world.size == 1, 'This script should be run in serial mode (with one process).'
import numpy as np
import matplotlib.pyplot as plt
from gpaw.inducedfield.inducedfield_base import BaseInducedField
from gpaw.tddft.units import (attosec_to_autime, autime_to_attosec,
eV_to_aufrequency, aufrequency_to_eV)
from gpaw.tddft.units import aufrequency_to_eV
assert world.size == 1, 'Script should be run in serial mode (one process).'
# Helper function
......@@ -19,7 +19,7 @@ def do_plot(d_g, ng, box, atoms):
ylabel = u'x / Å'
x = np.linspace(0, box[2], ng[2])
xlabel = u'z / Å'
# Plot
plt.figure()
ax = plt.subplot(1, 1, 1)
......
# Creates: na2_td_Ffe.png, na2_td_Frho.png, na2_td_Fphi.png
# -*- coding: utf-8 -*-
from gpaw.mpi import world
assert world.size == 1, 'This script should be run in serial mode (with one process).'
import numpy as np
import matplotlib.pyplot as plt
from gpaw.inducedfield.inducedfield_base import BaseInducedField
from gpaw.tddft.units import (attosec_to_autime, autime_to_attosec,
eV_to_aufrequency, aufrequency_to_eV)
from gpaw.tddft.units import aufrequency_to_eV
assert world.size == 1, 'Script should be run in serial mode (one process).'
# Helper function
......@@ -19,7 +19,7 @@ def do_plot(d_g, ng, box, atoms):
ylabel = u'x / Å'
x = np.linspace(0, box[2], ng[2])
xlabel = u'z / Å'
# Plot
plt.figure()
ax = plt.subplot(1, 1, 1)
......
from ase import Atoms
from gpaw.tddft import photoabsorption_spectrum
from gpaw import PoissonSolver
from gpaw.lcaotddft.tddfpt import TDDFPT, DensityCollector
from gpaw.lcaotddft.tddfpt import DensityCollector
from gpaw.lcaotddft import LCAOTDDFT
atoms = Atoms('Na8', positions=[[i * 3.0, 0, 0] for i in range(8)])
......
from __future__ import print_function
import pickle
import numpy as np
from gpaw.mpi import world
from parms import V, H, h1, ion_shift
from kgf.GreenFunctions import NonEqNonIntGreenFunction, NonEqIntGreenFunction
from kgf.ScatteringHamiltonianMatrix import ScatteringHamiltonianMatrix
from kgf.LeadHamiltonianMatrix import LeadHamiltonianMatrix
from kgf.CurrentCalculator import CurrentCalculator
from kgf.selfenergies import NonEqConstantSelfEnergy
from kgf.selfenergies.GW2index import Hartree2index, Fock2index, GW2index
......@@ -16,9 +14,9 @@ hmat = ScatteringHamiltonianMatrix(leftprincipallayer=1,
left = LeadHamiltonianMatrix(principallayer=1,
hamiltonianmatrix=h1)
right = LeadHamiltonianMatrix(principallayer=1,
hamiltonianmatrix=h1)
hamiltonianmatrix=h1)
energies = np.arange(-96.0, 96.0, 0.02)
de = energies[1] - energies[0]
......@@ -26,9 +24,10 @@ assert abs(energies).min() < 1.0e-8
fermi = 0.0
g0 = NonEqNonIntGreenFunction(hmat, left, right, E_Fermi=fermi,
energies=energies)
g0.SetInfinitesimal(2*de)
g0.SetInfinitesimal(2 * de)
Ntot = g0.GetTotalParticleNumber()
if world.rank==0: print('Total electron number:', Ntot)
if world.rank == 0:
print('Total electron number:', Ntot)
se_null = NonEqConstantSelfEnergy(g0, np.zeros((6, 6), complex), 'null')
se_ion = NonEqConstantSelfEnergy(g0, ion_shift, 'shift')
se_hartree = Hartree2index(g0, V, initialhartree=np.zeros((6, 6), complex))
......@@ -42,7 +41,7 @@ se_ion.SetActive(False)
se_hartree.SetActive(False)
se_fock.SetActive(False)
se_gw.SetActive(False)
gf.WriteSpectralInfoToNetCDFFile('nonint.nc',
gf.WriteSpectralInfoToNetCDFFile('nonint.nc',
diagonalize=True,
orbitals=orbitals,
spectral='individual')
......@@ -51,7 +50,7 @@ se_ion.SetActive(True)
se_hartree.SetActive(True)
se_fock.SetActive(True)
gf.SelfConsistent(log='HF.log', pulay=pulay)
gf.WriteSpectralInfoToNetCDFFile('HF.nc',
gf.WriteSpectralInfoToNetCDFFile('HF.nc',
diagonalize=True,
orbitals=orbitals,
spectral='individual')
......@@ -59,9 +58,7 @@ gf.WriteSpectralInfoToNetCDFFile('HF.nc',
# GW calculation
se_gw.SetActive(True)
gf.SelfConsistent(log='GW.log', pulay=pulay)
gf.WriteSpectralInfoToNetCDFFile('GW.nc',
gf.WriteSpectralInfoToNetCDFFile('GW.nc',
diagonalize=True,
orbitals=orbitals,
spectral='individual')
......@@ -5,7 +5,6 @@ from ase.build import molecule
from gpaw.cluster import Cluster
from gpaw import GPAW, KohnShamConvergenceError, FermiDirac
from gpaw.eigensolvers import CG, RMMDIIS
from gpaw.mixer import MixerDif
calc_parms = [
{'xc': 'PBE0:unocc=True',
......@@ -38,9 +37,7 @@ def calc_me(atoms, nbands):
'energy': 0.005,
'bands': nbands,
'eigenstates': 1e-4,
'density': 1e-3,
}
)
'density': 1e-3})
atoms.set_calculator(calc)
try:
atoms.get_potential_energy()
......
"""First example for using RSF."""
from ase import Atoms
from gpaw import GPAW
from gpaw.eigensolvers import RMMDIIS
from gpaw.occupations import FermiDirac
......
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import xml.sax
from optparse import OptionParser
from math import exp, log
from math import exp
class Reader(xml.sax.handler.ContentHandler):
......@@ -67,7 +66,7 @@ class Reader(xml.sax.handler.ContentHandler):
if self.data is not None:
for r, x in zip(self.r, self.data.split()):
print(r, x)
op = OptionParser(usage='%prog [options] setup[.gz]',
version='%prog 0.2')
......
import numpy as np
from ase.build import bulk
from gpaw import GPAW, PW, FermiDirac, MethfesselPaxton
from gpaw import GPAW, PW
a0 = 4.04
al = bulk('Al', 'fcc',