Skip to content

Commit

Permalink
Format all Python files with black
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Feb 25, 2020
1 parent 6a8ff8f commit 2526173
Show file tree
Hide file tree
Showing 22 changed files with 1,194 additions and 765 deletions.
12 changes: 6 additions & 6 deletions src/start/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

try:
from Cython.Build import cythonize

USE_CYTHON = True
EXT = "pyx"
except ImportError:
Expand All @@ -16,13 +17,12 @@
cythonize = lambda ext: ext

extensions = [
Extension("cp2k", ["cp2k.{}".format(EXT)],
Extension(
"cp2k",
["cp2k.{}".format(EXT)],
include_dirs=[numpy.get_include()],
libraries=["cp2k"],
),
),
]

setup(
name="cp2k",
ext_modules=cythonize(extensions)
)
setup(name="cp2k", ext_modules=cythonize(extensions))
27 changes: 18 additions & 9 deletions tools/autotune_grid/xyz_to_vab/template_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

import sys


def load_template(template_filename):
""" Load the routine template string from a file and return the object """
# template_str = "\n".join([e.rstrip() for e in open(template_filename).readlines()])
return pyratemp.Template(filename = template_filename)
return pyratemp.Template(filename=template_filename)


def create_ordered_pairs():
Expand All @@ -50,18 +51,21 @@ def create_ordered_pairs():
(0, 1)--3750300
"""
# Order the most common cases
l = [ (1,0) , (1,1), (0,0), (0,1) ]
l = [(1, 0), (1, 1), (0, 0), (0, 1)]
# The rest are appended as is
for i in range(0,la_max_local_end+1):
for j in range(0,lb_max_local_end+1):
if not (i,j) in l:
l.append((i,j,))
for i in range(0, la_max_local_end + 1):
for j in range(0, lb_max_local_end + 1):
if not (i, j) in l:
l.append((i, j,))
return l


if __name__ == "__main__":
if len(sys.argv) != 3:
print(" Incorrect number of parameters ")
print(" Usage: " + str(sys.argv[0]) + " <template_file> " + " <destination_file>")
print(
" Usage: " + str(sys.argv[0]) + " <template_file> " + " <destination_file>"
)
sys.exit(1)

template_file_name = sys.argv[1]
Expand All @@ -70,8 +74,13 @@ def create_ordered_pairs():
l = create_ordered_pairs()
# Initialize the templates
module_template = load_template(template_file_name)
source_str = module_template(cray_tracing = False, la_max_local=la_max_local_end, lb_max_local=lb_max_local_end, pairs = l)
source_file = open(output_file_name,'w+')
source_str = module_template(
cray_tracing=False,
la_max_local=la_max_local_end,
lb_max_local=lb_max_local_end,
pairs=l,
)
source_file = open(output_file_name, "w+")
print(source_str, file=source_file)

source_file.close()
91 changes: 52 additions & 39 deletions tools/benchmark_plots/plot_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import argparse

# Base directory
BASE = '/home/jeremy/cp2k-uk/results/'
BASE = "/home/jeremy/cp2k-uk/results/"
YSHIFT = 1.1


def makePlot(benchmarkName, machineName, shift, showPlot):
"""
Make a plot of benchmark results.
Expand All @@ -27,69 +28,81 @@ def makePlot(benchmarkName, machineName, shift, showPlot):
plt.ioff()

# Construct file name based on machine name and benchmark name
fileName = BASE \
+ machineName.lower() \
+ '_benchmarks/' \
+ benchmarkName \
+ '/' \
+ benchmarkName \
+ '_besttimes.txt'

print('Processing benchmark results for %s from file:' % machineName)
fileName = (
BASE
+ machineName.lower()
+ "_benchmarks/"
+ benchmarkName
+ "/"
+ benchmarkName
+ "_besttimes.txt"
)

print("Processing benchmark results for %s from file:" % machineName)
print(fileName)

# Load data from file
data = np.loadtxt(fileName, dtype={'names': ('nodes', 'time', 'label'), \
'formats': ('i4', 'f4', 'a5')})
data = np.loadtxt(
fileName,
dtype={"names": ("nodes", "time", "label"), "formats": ("i4", "f4", "a5")},
)

# Create plot
fig = plt.figure()
ax = fig.add_subplot(111)
# Plot data
ax.loglog(data['nodes'], data['time'], marker='o')
ax.loglog(data["nodes"], data["time"], marker="o")
# Change axes ticks to integers
ax.get_xaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter('%d'))
ax.get_yaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter('%d'))
ax.get_xaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter("%d"))
ax.get_yaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter("%d"))
# Add title and axes labels
title = 'Performance of the ' + benchmarkName + ' benchmark on ' + machineName
title = "Performance of the " + benchmarkName + " benchmark on " + machineName
plt.title(title)
plt.xlabel('Number of nodes used')
plt.ylabel('Time (seconds)')
plt.xlabel("Number of nodes used")
plt.ylabel("Time (seconds)")
# Label the points with the best performance
for i, labelText in enumerate(data['label']):
ax.annotate(labelText, xy=(data['nodes'][i], data['time'][i]),
xytext=(data['nodes'][i], shift*data['time'][i]))
for i, labelText in enumerate(data["label"]):
ax.annotate(
labelText,
xy=(data["nodes"][i], data["time"][i]),
xytext=(data["nodes"][i], shift * data["time"][i]),
)

# Save plot to file
outFileName = benchmarkName + '-' + machineName.lower() + '.png'
outFileName = benchmarkName + "-" + machineName.lower() + ".png"

plt.savefig(outFileName)
if (showPlot):
if showPlot:
plt.show()
plt.clf()


if __name__ == "__main__":
# Command line options
parser = argparse.ArgumentParser(description='Plot benchmark results.')
parser.add_argument('--name',
default='fayalite-FIST',
help='name of the benchmark to process')
parser.add_argument('--machine',
default='Magnus',
help='name of the machine used to obtain results')
parser.add_argument('--shift',
default=YSHIFT,
help='Fractional shift of label in y-direction',
type=float)
parser.add_argument('--show',
action='store_true',
help='show the plot window as well as saving to file')
parser = argparse.ArgumentParser(description="Plot benchmark results.")
parser.add_argument(
"--name", default="fayalite-FIST", help="name of the benchmark to process"
)
parser.add_argument(
"--machine", default="Magnus", help="name of the machine used to obtain results"
)
parser.add_argument(
"--shift",
default=YSHIFT,
help="Fractional shift of label in y-direction",
type=float,
)
parser.add_argument(
"--show",
action="store_true",
help="show the plot window as well as saving to file",
)

args = parser.parse_args()

benchmarkName = args.name
machineName = args.machine
shift=args.shift
shift = args.shift
showPlot = args.show

makePlot(benchmarkName, machineName, shift, showPlot)
makePlot(benchmarkName, machineName, shift, showPlot)
113 changes: 63 additions & 50 deletions tools/benchmark_plots/plot_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from itertools import cycle

# Base directory
BASE = '/home/jeremy/cp2k-uk/results/'
BASE = "/home/jeremy/cp2k-uk/results/"
YSHIFT = 1.1


def makePlot(benchmarkName, machineNames, shifts, showPlot):
"""
Make a comparison plot of benchmark results.
Expand All @@ -26,77 +27,89 @@ def makePlot(benchmarkName, machineNames, shifts, showPlot):
# Turn interactive mode off (required in ipython)
plt.ioff()

markers = ['o', 'v', '^', 's', '*']
markers = ["o", "v", "^", "s", "*"]
markerCycler = cycle(markers)
shiftCycler = cycle(shifts)

fig = plt.figure()
ax = fig.add_subplot(111)
title = 'Performance of the ' + benchmarkName + ' benchmark'
title = "Performance of the " + benchmarkName + " benchmark"
plt.title(title)
plt.xlabel('Number of nodes used')
plt.ylabel('Time (seconds)')
plt.xlabel("Number of nodes used")
plt.ylabel("Time (seconds)")

for machineName in machineNames:
fileName = BASE \
+ machineName.lower() \
+ '_benchmarks/' \
+ benchmarkName \
+ '/' \
+ benchmarkName \
+ '_besttimes.txt'
print('Processing benchmark results from file:')
fileName = (
BASE
+ machineName.lower()
+ "_benchmarks/"
+ benchmarkName
+ "/"
+ benchmarkName
+ "_besttimes.txt"
)
print("Processing benchmark results from file:")
print(fileName)
data = np.loadtxt(fileName,
dtype={'names': ('nodes', 'time', 'label'), \
'formats': ('i4', 'f4', 'a5')})
ax.loglog(data['nodes'], data['time'],
marker=next(markerCycler),
label=machineName)
data = np.loadtxt(
fileName,
dtype={"names": ("nodes", "time", "label"), "formats": ("i4", "f4", "a5")},
)
ax.loglog(
data["nodes"], data["time"], marker=next(markerCycler), label=machineName
)

shift = next(shiftCycler)
alignment = 'left'
if (shift < 1.0):
alignment = 'right'
for i, labelText in enumerate(data['label']):
ax.annotate(labelText,
xy=(data['nodes'][i], data['time'][i]),
xytext=(data['nodes'][i], shift*data['time'][i]),
horizontalalignment=alignment)

ax.get_xaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter('%d'))
ax.get_yaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter('%d'))
alignment = "left"
if shift < 1.0:
alignment = "right"
for i, labelText in enumerate(data["label"]):
ax.annotate(
labelText,
xy=(data["nodes"][i], data["time"][i]),
xytext=(data["nodes"][i], shift * data["time"][i]),
horizontalalignment=alignment,
)

ax.get_xaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter("%d"))
ax.get_yaxis().set_major_formatter(matplotlib.ticker.FormatStrFormatter("%d"))
plt.legend()

outFileName = benchmarkName + '-comparison'
outFileName = benchmarkName + "-comparison"
for machineName in machineNames:
outFileName = outFileName + '-' + machineName.lower()
outFileName = outFileName + '.png'
outFileName = outFileName + "-" + machineName.lower()
outFileName = outFileName + ".png"

plt.savefig(outFileName)

if (showPlot):
if showPlot:
plt.show()
plt.clf()


if __name__ == "__main__":
# Command line arguments
parser = argparse.ArgumentParser(description='Plot benchmark results.')
parser.add_argument('--name',
default='fayalite-FIST',
help='name of the benchmark to process')
parser.add_argument('--machines',
default='Magnus',
help='name of the machines used to obtain results',
nargs='*')
parser.add_argument('--shifts',
default=[YSHIFT],
help='Fractional shift of label in y-direction',
nargs='*',
type=float)
parser.add_argument('--show',
action='store_true',
help='show the plot window as well as saving to file')
parser = argparse.ArgumentParser(description="Plot benchmark results.")
parser.add_argument(
"--name", default="fayalite-FIST", help="name of the benchmark to process"
)
parser.add_argument(
"--machines",
default="Magnus",
help="name of the machines used to obtain results",
nargs="*",
)
parser.add_argument(
"--shifts",
default=[YSHIFT],
help="Fractional shift of label in y-direction",
nargs="*",
type=float,
)
parser.add_argument(
"--show",
action="store_true",
help="show the plot window as well as saving to file",
)

args = parser.parse_args()

Expand Down
Loading

0 comments on commit 2526173

Please sign in to comment.