Skip to content
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

Add Python linter #277

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ jobs:
- run: bundle install
- run: bundle exec danger || true
- run: BML_OPENMP=no EMACS=emacs27 ./build.sh check_indent
- run: sudo apt-get install --yes pycodestyle
- run: pycodestyle $(git ls-files '*.py')

build:
name: Build and test (${{ matrix.JOBNAME }})
runs-on: ubuntu-20.04
needs: lint
strategy:
fail-fast: false
matrix:
Expand Down
31 changes: 14 additions & 17 deletions examples/gpmd/get_energy.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#!/usr/bin/env python
import os, sys
import sys
import numpy

MyFileName=str(sys.argv[1])
#print 'File name:', MyFileName
MyFileName = str(sys.argv[1])

count=-1
MyFile = open(MyFileName,"r")
count = -1
MyFile = open(MyFileName, "r", encoding="utf-8")

for lines in MyFile:
count = count + 1
Dim=count
#print 'Dim', Dim
count = count + 1
Dim = count
datos = numpy.zeros(Dim+1)

count=-1
MyFile = open(MyFileName,"r")
count = -1
MyFile = open(MyFileName, "r", encoding="utf-8")
for lines in MyFile:
lines_split = lines.split()
count = count + 1
if(len(lines_split) > 2):
if(lines_split[0] == "Energy"):
if(lines_split[1] == "Total"):
print " ", lines_split[4]

lines_split = lines.split()
count = count + 1
if len(lines_split) > 2:
if lines_split[0] == "Energy":
if lines_split[1] == "Total":
print(" ", lines_split[4])
77 changes: 40 additions & 37 deletions examples/gpmd/test-energy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse


def compare_MD(reference, current, reltol):
"""Compare MD energies.
Expand All @@ -8,29 +11,24 @@ def compare_MD(reference, current, reltol):
"""

import sys
#energy = re.compile("MD_data\s+([0-9eE.+-]+)\s+([0-9eE.+-]+)")

fd = open(reference)
reference_energies = []
for line in fd:
result = line.split()
reference_energies.append(float(result[0]))
fd.close()

fd = open(current)
current_energies = []
for line in fd:
result = line.split()
current_energies.append(float(result[0]))
fd.close()


with open(reference, encoding="utf-8") as fd:
reference_energies = []
for line in fd:
result = line.split()
reference_energies.append(float(result[0]))

with open(current, encoding="utf-8") as fd:
current_energies = []
for line in fd:
result = line.split()
current_energies.append(float(result[0]))

if len(reference_energies) != len(current_energies):
raise Exception("[error] different number of MD steps\n"
+ (" reference ran for %4d steps\n" % (len(reference_energies)))
+ (" current ran for %4d steps\n" % (len(current_energies)))
+ " can not compare")
raise Exception(
"[error] different number of MD steps\n"
+ (" reference ran for %4d steps\n" % (len(reference_energies)))
+ (" current ran for %4d steps\n" % (len(current_energies)))
+ " can not compare")

result = True
for i in range(len(reference_energies)):
Expand All @@ -41,29 +39,34 @@ def compare_MD(reference, current, reltol):
print("failure in MD step %d" % (i+1))
result = False
if not result:
raise Exception(("[error] when comparing '%s' with '%s'" % (reference, current))
+ "energies do not agree")
raise Exception(
("[error] when comparing '%s' with '%s'" % (reference, current))
+ "energies do not agree")

print("Energy test passed without failure ...")

print("Energy test passed without failure ...")

def main():
"""The main function.
"""

import argparse, os, sys

parser = argparse.ArgumentParser(description="""Script to compare MD results by using the total energy""")
parser.add_argument("--reference",
help="The reference output")
parser.add_argument("--current",
help="The current output")
parser.add_argument("--reltol",
help="Relative tolerance when comparing, default is %(default)s",
type=float,
default=1e-10)
parser = argparse.ArgumentParser(description="""Script to compare
MD results by using the total energy""")
parser.add_argument(
"--reference",
help="The reference output")
parser.add_argument(
"--current",
help="The current output")
parser.add_argument(
"--reltol",
help="Relative tolerance when comparing, default is %(default)s",
type=float,
default=1e-10)
options = parser.parse_args()

compare_MD(options.reference, options.current, options.reltol)


if __name__ == "__main__":
main()
7 changes: 3 additions & 4 deletions examples/gpmdcov/get_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import argparse
import re

energy_re = re.compile("Energy Total.*=\s+([0-9-.]+)")
energy_re = re.compile(r"Energy Total.*=\s+([0-9-.]+)")

parser = argparse.ArgumentParser()
parser.add_argument("OUT",
help="The output")
parser.add_argument("OUT", help="The output")
options = parser.parse_args()

with open(options.OUT) as fd:
with open(options.OUT, encoding="utf-8") as fd:
for line in fd:
result = energy_re.search(line)
if result:
Expand Down
75 changes: 39 additions & 36 deletions examples/gpmdcov/test-energy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python

import argparse


def compare_MD(reference, current, reltol):
"""Compare MD energies.

Expand All @@ -8,29 +11,24 @@ def compare_MD(reference, current, reltol):

"""

import sys
#energy = re.compile("MD_data\s+([0-9eE.+-]+)\s+([0-9eE.+-]+)")

fd = open(reference)
reference_energies = []
for line in fd:
result = line.split()
reference_energies.append(float(result[0]))
fd.close()

fd = open(current)
current_energies = []
for line in fd:
result = line.split()
current_energies.append(float(result[0]))
fd.close()


with open(reference, encoding="utf-8") as fd:
reference_energies = []
for line in fd:
result = line.split()
reference_energies.append(float(result[0]))

with open(current, encoding="utf-8") as fd:
current_energies = []
for line in fd:
result = line.split()
current_energies.append(float(result[0]))

if len(reference_energies) != len(current_energies):
raise Exception("[error] different number of MD steps\n"
+ (" reference ran for %4d steps\n" % (len(reference_energies)))
+ (" current ran for %4d steps\n" % (len(current_energies)))
+ " can not compare")
raise Exception(
"[error] different number of MD steps\n"
+ (" reference ran for %4d steps\n" % (len(reference_energies)))
+ (" current ran for %4d steps\n" % (len(current_energies)))
+ " can not compare")

result = True
for i in range(len(reference_energies)):
Expand All @@ -41,29 +39,34 @@ def compare_MD(reference, current, reltol):
print("failure in MD step %d" % (i+1))
result = False
if not result:
raise Exception(("[error] when comparing '%s' with '%s'" % (reference, current))
+ "energies do not agree")
raise Exception(
("[error] when comparing '%s' with '%s'" % (reference, current))
+ "energies do not agree")

print("Energy test passed without failure ...")

print("Energy test passed without failure ...")

def main():
"""The main function.
"""

import argparse, os, sys

parser = argparse.ArgumentParser(description="""Script to compare MD results by using the total energy""")
parser.add_argument("--reference",
help="The reference output")
parser.add_argument("--current",
help="The current output")
parser.add_argument("--reltol",
help="Relative tolerance when comparing, default is %(default)s",
type=float,
default=1e-10)
parser = argparse.ArgumentParser(description="""Script to compare MD
results by using the total energy""")
parser.add_argument(
"--reference",
help="The reference output")
parser.add_argument(
"--current",
help="The current output")
parser.add_argument(
"--reltol",
help="Relative tolerance when comparing, default is %(default)s",
type=float,
default=1e-10)
options = parser.parse_args()

compare_MD(options.reference, options.current, options.reltol)


if __name__ == "__main__":
main()
Loading