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

style: enable and fix many flake8 issues #6

Merged
merged 6 commits into from
Mar 28, 2024
Merged
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
22 changes: 13 additions & 9 deletions benchmarks/scalar_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@
import os
import time
import warnings
import pyopencl as cl
import pyopencl.clrandom

import numpy as np

import loopy as lp
import pymbolic as pmbl
import pymbolic.primitives as primitives
from pymbolic.functions import sin, cos, exp, tan, log # noqa: F401
import pyopencl as cl
import pyopencl.clrandom
from pymbolic.functions import cos, exp, log, sin, tan # noqa: F401

from volumential.tools import ScalarFieldExpressionEvaluation


# {{{ math functions

# cf.
Expand Down Expand Up @@ -66,7 +70,7 @@ def math_func_mangler(target, name, arg_dtypes):

fname = name.name
if not (isinstance(name.aggregate, pmbl.primitives.Variable)
and name.aggregate.name == 'math'):
and name.aggregate.name == "math"):
raise RuntimeError("unexpected aggregate '%s'" %
str(name.aggregate))

Expand All @@ -80,7 +84,7 @@ def math_func_mangler(target, name, arg_dtypes):
arg_dtype)

return lp.CallMangleInfo(
target_name="%s_%s" % (tpname, fname),
target_name=f"{tpname}_{fname}",
result_dtypes=(arg_dtype,),
arg_dtypes=(arg_dtype,))

Expand Down Expand Up @@ -139,7 +143,7 @@ def get_evaluator(dim, expression, variables=None):
# needed for using loopy.statistics
knl = lp.add_and_infer_dtypes(
knl,
dict(x0=np.float64, x1=np.float64, x2=np.float64))
{"x0": np.float64, "x1": np.float64, "x2": np.float64})
knl = lp.set_options(knl, ignore_boostable_into=True)

# {{{ wall time
Expand Down Expand Up @@ -178,13 +182,13 @@ def get_evaluator(dim, expression, variables=None):
op_map = lp.get_op_map(knl, subgroup_size=ncpus, count_redundant_work=True,
count_within_subscripts=True)

params = dict(n_targets=pts.shape[1])
print('Operation counts:')
params = {"n_targets": pts.shape[1]}
print("Operation counts:")
total_ops = 0
for op in op_map.keys():
sub_count = op_map[op].eval_with_dict(params)
total_ops += sub_count
print('\t', op.name, op_map[op], sub_count)
print("\t", op.name, op_map[op], sub_count)
print("Total:", total_ops)

# TODO: weight each operation by running micro-benchmarks
Expand Down
9 changes: 6 additions & 3 deletions benchmarks/table_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
THE SOFTWARE.
"""

import logging
import time

import pyopencl as cl

from volumential.table_manager import NearFieldInteractionTableManager

import logging
logging.basicConfig(format='%(name)s:%(levelname)s: %(message)s')

logging.basicConfig(format="%(name)s:%(levelname)s: %(message)s")


def bench_table_build(queue):
Expand Down Expand Up @@ -68,5 +71,5 @@ def main():
bench_table_build(queue)


if __name__ == '__main__':
if __name__ == "__main__":
main()
66 changes: 35 additions & 31 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Volumential documentation build configuration file, created by
# sphinx-quickstart on Mon Oct 23 10:27:37 2017.
Expand All @@ -20,9 +19,11 @@
import os
import sys
from datetime import datetime

import volumential.version as __version__

sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- General configuration ------------------------------------------------
Expand All @@ -35,35 +36,38 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
'sphinx.ext.githubpages']
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"sphinx.ext.githubpages"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# Set the mathjax CDN
mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"
mathjax_path = (
"https://cdnjs.cloudflare.com/ajax/libs/"
"mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"
)

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'Volumential'
copyright = '%s, Xiaoyu Wei' % str(datetime.today().year)
author = 'Xiaoyu Wei'
project = "Volumential"
copyright = "%s, Xiaoyu Wei" % str(datetime.today().year)
author = "Xiaoyu Wei"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -88,7 +92,7 @@
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
Expand All @@ -99,7 +103,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -110,25 +114,25 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
"**": [
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Volumentialdoc'
htmlhelp_basename = "Volumentialdoc"

# -- Options for LaTeX output ---------------------------------------------

Expand All @@ -154,8 +158,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Volumential.tex', 'Volumential Documentation',
'Xiaoyu Wei', 'manual'),
(master_doc, "Volumential.tex", "Volumential Documentation",
"Xiaoyu Wei", "manual"),
]


Expand All @@ -164,7 +168,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'volumential', 'Volumential Documentation',
(master_doc, "volumential", "Volumential Documentation",
[author], 1)
]

Expand All @@ -175,7 +179,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Volumential', 'Volumential Documentation',
author, 'Volumential', 'One line description of project.',
'Miscellaneous'),
(master_doc, "Volumential", "Volumential Documentation",
author, "Volumential", "One line description of project.",
"Miscellaneous"),
]
33 changes: 17 additions & 16 deletions examples/laplace2d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" This example evaluates the volume potential over
[-1,1]^2 with the Laplace kernel.
"""
from __future__ import absolute_import, division, print_function

__copyright__ = "Copyright (C) 2017 - 2018 Xiaoyu Wei"

Expand All @@ -27,6 +26,7 @@

import logging


logger = logging.getLogger(__name__)

if 1:
Expand All @@ -36,12 +36,14 @@
# clean
logging.basicConfig(level=logging.CRITICAL)

from functools import partial

import numpy as np
import pyopencl as cl
from volumential.tools import ScalarFieldExpressionEvaluation as Eval

import pymbolic as pmbl
from functools import partial
import pyopencl as cl

from volumential.tools import ScalarFieldExpressionEvaluation as Eval


def main():
Expand Down Expand Up @@ -205,17 +207,18 @@ def main():

# {{{ build near field potential table

from volumential.table_manager import NearFieldInteractionTableManager
import os

from volumential.table_manager import NearFieldInteractionTableManager

if download_table and (not os.path.isfile(table_filename)):
import json
with open("table_urls.json", 'r') as fp:
with open("table_urls.json") as fp:
urls = json.load(fp)

print("Downloading table from %s" % urls['Laplace2D'])
print("Downloading table from %s" % urls["Laplace2D"])
import subprocess
subprocess.call(["wget", "-q", urls['Laplace2D'], table_filename])
subprocess.call(["wget", "-q", urls["Laplace2D"], table_filename])

tm = NearFieldInteractionTableManager(
table_filename, root_extent=root_table_source_extent,
Expand Down Expand Up @@ -280,9 +283,7 @@ def main():
exclude_self = True

from volumential.expansion_wrangler_fpnd import (
FPNDExpansionWranglerCodeContainer,
FPNDExpansionWrangler
)
FPNDExpansionWrangler, FPNDExpansionWranglerCodeContainer)

wcc = FPNDExpansionWranglerCodeContainer(
ctx,
Expand Down Expand Up @@ -317,9 +318,9 @@ def main():

# {{{ conduct fmm computation

from volumential.volume_fmm import drive_volume_fmm

import time

from volumential.volume_fmm import drive_volume_fmm
queue.finish()

t0 = time.time()
Expand Down Expand Up @@ -386,8 +387,8 @@ def main():
from mpl_toolkits.mplot3d import Axes3D

plt3d = plt.figure()
ax = Axes3D(plt3d) # noqa
surf = ax.plot_surface(oxx, oyy, opot.reshape(oxx.shape)) # noqa
ax = Axes3D(plt3d)
surf = ax.plot_surface(oxx, oyy, opot.reshape(oxx.shape)) # noqa: F841
# ax.scatter(x, y, src.get())
# ax.set_zlim(-0.25, 0.25)

Expand Down Expand Up @@ -472,7 +473,7 @@ def main():
# }}} End postprocess and plot


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


Expand Down
Loading
Loading