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

Enable Code Formatting Checks #5

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
python -m pip install --upgrade pip
python -m pip install pytest yapf toml
python -m pip install .
# - name: Lint with yapf
# working-directory: ./${{ matrix.package-name }}
# run: |
# yapf -r --diff .
- name: Lint with yapf
working-directory: ./${{ matrix.package-name }}
run: |
yapf -r --diff . --style ../.style.yapf
# - name: Test with pytest
# working-directory: ./${{ matrix.package-name }}
# run: |
Expand Down
5 changes: 5 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[style]
based_on_style = pep8
spaces_before_comment = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
spaces_before_comment = 4
spaces_before_comment = 2

maybe it's enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying out the space_inside_brackets setting, I agree that the resulting code looks good. I'm happy to move forward with it.

split_before_logical_operator = true
column_limit = 120
30 changes: 5 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@

# Add python modules to be documented
python_root = '..'
python_modules = ('geosx_mesh_tools_package',
'geosx_xml_tools_package',
'geosx_mesh_doctor',
'geos_ats_package',
'hdf5_wrapper_package',
'pygeosx_tools_package',
'timehistory_package')
python_modules = ('geosx_mesh_tools_package', 'geosx_xml_tools_package', 'geosx_mesh_doctor', 'geos_ats_package',
'hdf5_wrapper_package', 'pygeosx_tools_package', 'timehistory_package')
for m in python_modules:
sys.path.insert(0, os.path.abspath(os.path.join(python_root, m)))


# -- Project information -----------------------------------------------------

project = u'GEOS Python Packages'
Expand All @@ -40,7 +34,6 @@
# The full version, including alpha/beta/rc tags
release = u''


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand All @@ -51,17 +44,10 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx_design',
'sphinx.ext.todo',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.imgmath',
'sphinxarg.ext',
'sphinx.ext.napoleon',
'sphinxcontrib.programoutput'
'sphinx_design', 'sphinx.ext.todo', 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.imgmath',
'sphinxarg.ext', 'sphinx.ext.napoleon', 'sphinxcontrib.programoutput'
]


autodoc_mock_imports = ["pygeosx", "pylvarray", "meshio", "lxml", "mpi4py", "h5py", "ats", "scipy"]

# The suffix(es) of source filenames.
Expand Down Expand Up @@ -90,27 +76,21 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'


# -- Theme options ----------------------------------------------
extensions += [
'sphinx_rtd_theme',
]

html_theme = "sphinx_rtd_theme"

html_theme_options = {
'navigation_depth': -1,
'collapse_navigation': False
}
html_theme_options = {'navigation_depth': -1, 'collapse_navigation': False}

html_static_path = ['./_static']

html_css_files = [
'theme_overrides.css',
]


# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'geosPythonPackagesDoc'

37 changes: 16 additions & 21 deletions geosx_mesh_doctor/checks/check_fractures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
vtkCell,
)
from vtkmodules.vtkCommonCore import (
vtkPoints,
)
vtkPoints, )
from vtkmodules.vtkIOXML import (
vtkXMLMultiBlockDataReader,
)
vtkXMLMultiBlockDataReader, )
from vtkmodules.util.numpy_support import (
vtk_to_numpy,
)
vtk_to_numpy, )
from vtk_utils import (
vtk_iter,
)
vtk_iter, )


@dataclass(frozen=True)
Expand All @@ -47,7 +43,8 @@ class Result:
errors: Sequence[tuple[int, int, int]]


def __read_multiblock(vtk_input_file: str, matrix_name: str, fracture_name: str) -> Tuple[vtkUnstructuredGrid, vtkUnstructuredGrid]:
def __read_multiblock(vtk_input_file: str, matrix_name: str,
fracture_name: str) -> Tuple[vtkUnstructuredGrid, vtkUnstructuredGrid]:
reader = vtkXMLMultiBlockDataReader()
reader.SetFileName(vtk_input_file)
reader.Update()
Expand Down Expand Up @@ -75,10 +72,10 @@ def format_collocated_nodes(fracture_mesh: vtkUnstructuredGrid) -> Sequence[Iter
return tuple(generator)


def __check_collocated_nodes_positions(matrix_points: Sequence[Tuple[float, float, float]],
fracture_points: Sequence[Tuple[float, float, float]],
g2l: Sequence[int],
collocated_nodes: Iterable[Iterable[int]]) -> Collection[Tuple[int, Iterable[int], Iterable[Tuple[float, float, float]]]]:
def __check_collocated_nodes_positions(
matrix_points: Sequence[Tuple[float, float, float]], fracture_points: Sequence[Tuple[float, float, float]],
g2l: Sequence[int], collocated_nodes: Iterable[Iterable[int]]
) -> Collection[Tuple[int, Iterable[int], Iterable[Tuple[float, float, float]]]]:
issues = []
for li, bucket in enumerate(collocated_nodes):
matrix_nodes = (fracture_points[li], ) + tuple(map(lambda gi: matrix_points[g2l[gi]], bucket))
Expand All @@ -99,9 +96,7 @@ def my_iter(ccc):
yield (i, )


def __check_neighbors(matrix: vtkUnstructuredGrid,
fracture: vtkUnstructuredGrid,
g2l: Sequence[int],
def __check_neighbors(matrix: vtkUnstructuredGrid, fracture: vtkUnstructuredGrid, g2l: Sequence[int],
collocated_nodes: Sequence[Iterable[int]]):
fracture_nodes: Set[int] = set()
for bucket in collocated_nodes:
Expand All @@ -121,7 +116,7 @@ def __check_neighbors(matrix: vtkUnstructuredGrid,
# Finding the cells
for c in tqdm(range(fracture.GetNumberOfCells()), desc="Finding neighbor cell pairs"):
cell: vtkCell = fracture.GetCell(c)
cns: Set[FrozenSet[int]] = set() # subset of collocated_nodes
cns: Set[FrozenSet[int]] = set() # subset of collocated_nodes
point_ids = frozenset(vtk_iter(cell.GetPointIds()))
for point_id in point_ids:
bucket = collocated_nodes[point_id]
Expand All @@ -134,7 +129,9 @@ def __check_neighbors(matrix: vtkUnstructuredGrid,
if f in fracture_faces:
found += 1
if found != 2:
logging.warning(f"Something went wrong since we should have found 2 fractures faces (we found {found}) for collocated nodes {cns}.")
logging.warning(
f"Something went wrong since we should have found 2 fractures faces (we found {found}) for collocated nodes {cns}."
)


def __check(vtk_input_file: str, options: Options) -> Result:
Expand All @@ -153,9 +150,7 @@ def __check(vtk_input_file: str, options: Options) -> Result:
g2l.flags.writeable = False

issues = __check_collocated_nodes_positions(vtk_to_numpy(matrix.GetPoints().GetData()),
vtk_to_numpy(fracture.GetPoints().GetData()),
g2l,
collocated_nodes)
vtk_to_numpy(fracture.GetPoints().GetData()), g2l, collocated_nodes)
assert len(issues) == 0

__check_neighbors(matrix, fracture, g2l, collocated_nodes)
Expand Down
7 changes: 3 additions & 4 deletions geosx_mesh_doctor/checks/collocated_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Options:

@dataclass(frozen=True)
class Result:
nodes_buckets: Iterable[Iterable[int]] # Each bucket contains the duplicated node indices.
wrong_support_elements: Collection[int] # Element indices with support node indices appearing more than once.
nodes_buckets: Iterable[Iterable[int]] # Each bucket contains the duplicated node indices.
wrong_support_elements: Collection[int] # Element indices with support node indices appearing more than once.


def __check(mesh, options: Options) -> Result:
Expand Down Expand Up @@ -69,8 +69,7 @@ def __check(mesh, options: Options) -> Result:
if len({cell.GetPointId(i) for i in range(num_points_per_cell)}) != num_points_per_cell:
wrong_support_elements.append(c)

return Result(nodes_buckets=tmp,
wrong_support_elements=wrong_support_elements)
return Result(nodes_buckets=tmp, wrong_support_elements=wrong_support_elements)


def check(vtk_input_file: str, options: Options) -> Result:
Expand Down
14 changes: 7 additions & 7 deletions geosx_mesh_doctor/checks/element_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
vtkMeshQuality,
)
from vtkmodules.util.numpy_support import (
vtk_to_numpy,
)

vtk_to_numpy, )

from . import vtk_utils

Expand All @@ -39,7 +37,7 @@ def __check(mesh, options: Options) -> Result:
cs.ComputeSumOff()
cs.ComputeVertexCountOff()
cs.ComputeVolumeOn()
volume_array_name = "__MESH_DOCTOR_VOLUME-" + str(uuid.uuid4()) # Making the name unique
volume_array_name = "__MESH_DOCTOR_VOLUME-" + str(uuid.uuid4()) # Making the name unique
cs.SetVolumeArrayName(volume_array_name)

cs.SetInputData(mesh)
Expand All @@ -50,19 +48,21 @@ def __check(mesh, options: Options) -> Result:

mq.SetTetQualityMeasureToVolume()
mq.SetHexQualityMeasureToVolume()
if hasattr(mq, "SetPyramidQualityMeasureToVolume"): # This feature is quite recent
if hasattr(mq, "SetPyramidQualityMeasureToVolume"): # This feature is quite recent
mq.SetPyramidQualityMeasureToVolume()
SUPPORTED_TYPES.append(VTK_PYRAMID)
mq.SetWedgeQualityMeasureToVolume()
SUPPORTED_TYPES.append(VTK_WEDGE)
else:
logging.warning("Your \"pyvtk\" version does not bring pyramid nor wedge support with vtkMeshQuality. Using the fallback solution.")
logging.warning(
"Your \"pyvtk\" version does not bring pyramid nor wedge support with vtkMeshQuality. Using the fallback solution."
)

mq.SetInputData(mesh)
mq.Update()

volume = cs.GetOutput().GetCellData().GetArray(volume_array_name)
quality = mq.GetOutput().GetCellData().GetArray("Quality") # Name is imposed by vtk.
quality = mq.GetOutput().GetCellData().GetArray("Quality") # Name is imposed by vtk.

assert volume is not None
assert quality is not None
Expand Down
5 changes: 2 additions & 3 deletions geosx_mesh_doctor/checks/fix_elements_orderings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
)

from vtkmodules.vtkCommonCore import (
vtkIdList,
)
vtkIdList, )

from . import vtk_utils
from .vtk_utils import (
Expand All @@ -34,7 +33,7 @@ def __check(mesh, options: Options) -> Result:
# The vtk cell type is an int and will be the key of the following mapping,
# that will point to the relevant permutation.
cell_type_to_ordering: Dict[int, List[int]] = options.cell_type_to_ordering
unchanged_cell_types: Set[int] = set() # For logging purpose
unchanged_cell_types: Set[int] = set() # For logging purpose

# Preparing the output mesh by first keeping the same instance type.
output_mesh = mesh.NewInstance()
Expand Down
19 changes: 9 additions & 10 deletions geosx_mesh_doctor/checks/generate_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import numpy

from vtkmodules.vtkCommonCore import (
vtkPoints,
)
vtkPoints, )
from vtkmodules.vtkCommonDataModel import (
VTK_HEXAHEDRON,
vtkCellArray,
Expand All @@ -15,13 +14,11 @@
vtkUnstructuredGrid,
)
from vtkmodules.util.numpy_support import (
numpy_to_vtk,
)
numpy_to_vtk, )

from . import vtk_utils
from .vtk_utils import (
VtkOutput,
)
VtkOutput, )

from .generate_global_ids import __build_global_ids

Expand Down Expand Up @@ -87,7 +84,7 @@ def build_rectilinear_blocks_mesh(xyzs: Iterable[XYZ]) -> vtkUnstructuredGrid:
cells = vtkCellArray()
cells.AllocateExact(num_cells, num_cells * 8)

m = (0, 1, 3, 2, 4, 5, 7, 6) # VTK_VOXEL and VTK_HEXAHEDRON do not share the same ordering.
m = (0, 1, 3, 2, 4, 5, 7, 6) # VTK_VOXEL and VTK_HEXAHEDRON do not share the same ordering.
offset = 0
for rg in rgs:
for i in range(rg.GetNumberOfCells()):
Expand Down Expand Up @@ -121,6 +118,7 @@ def __add_fields(mesh: vtkUnstructuredGrid, fields: Iterable[FieldInfo]) -> vtkU


def __build(options: Options):

def build_coordinates(positions, num_elements):
result = []
it = zip(zip(positions, positions[1:]), num_elements)
Expand All @@ -129,18 +127,19 @@ def build_coordinates(positions, num_elements):
while True:
start, stop = coords
end_point = False
tmp = numpy.linspace(start=start, stop=stop, num=n+end_point, endpoint=end_point)
tmp = numpy.linspace(start=start, stop=stop, num=n + end_point, endpoint=end_point)
coords, n = next(it)
result.append(tmp)
except StopIteration:
end_point = True
tmp = numpy.linspace(start=start, stop=stop, num=n+end_point, endpoint=end_point)
tmp = numpy.linspace(start=start, stop=stop, num=n + end_point, endpoint=end_point)
result.append(tmp)
return numpy.concatenate(result)

x = build_coordinates(options.xs, options.nxs)
y = build_coordinates(options.ys, options.nys)
z = build_coordinates(options.zs, options.nzs)
cube = build_rectilinear_blocks_mesh((XYZ(x, y, z),))
cube = build_rectilinear_blocks_mesh((XYZ(x, y, z), ))
cube = __add_fields(cube, options.fields)
__build_global_ids(cube, options.generate_cells_global_ids, options.generate_points_global_ids)
return cube
Expand Down
Loading