Skip to content

Commit

Permalink
Merge branch 'development' into topic-upstream-soa-named
Browse files Browse the repository at this point in the history
  • Loading branch information
atmyers committed Nov 22, 2024
2 parents 50a26a2 + 66fc71f commit d41d068
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 47 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Build & Install
# mkl/rng/device/detail/mrg32k3a_impl.hpp has a number of sign-compare error
# mkl/rng/device/detail/mrg32k3a_impl.hpp has missing braces in array-array initalization
env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wno-sign-compare -Wno-missing-braces"}
env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wno-unused-variable -Wno-shadow"}
run: |
set +e
source /opt/intel/oneapi/setvars.sh
Expand Down Expand Up @@ -73,10 +73,8 @@ jobs:
restore-keys: |
ccache-${{ github.workflow }}-${{ github.job }}-git-
- name: Build & Install
# mkl/rng/device/detail/mrg32k3a_impl.hpp has a number of sign-compare error
# mkl/rng/device/detail/mrg32k3a_impl.hpp has missing braces in array-array initalization
# /usr/include/c++/12/bits/stl_tempbuf.h has deprecated-declarations in 'get_temporary_buffer<std::pair<long, int>>'
env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wno-sign-compare -Wno-missing-braces -Wno-error=pass-failed -Wno-tautological-constant-compare -Wno-deprecated-declarations"}
env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wno-deprecated-declarations"}
run: |
set +e
source /opt/intel/oneapi/setvars.sh
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ repos:
# Python: Ruff linter & formatter
# https://docs.astral.sh/ruff/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.3
hooks:
# Run the linter
- id: ruff
Expand All @@ -94,7 +94,7 @@ repos:

# Checks the manifest for missing files (native support)
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
rev: "0.50"
hooks:
- id: check-manifest
# This is a slow hook, so only run this if --hook-stage manual is passed
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Preamble ####################################################################
#
cmake_minimum_required(VERSION 3.24.0)
project(pyAMReX VERSION 24.10)
project(pyAMReX VERSION 24.11)

include(${pyAMReX_SOURCE_DIR}/cmake/pyAMReXFunctions.cmake)

Expand Down
4 changes: 2 additions & 2 deletions cmake/dependencies/AMReX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ macro(find_amrex)
message(STATUS "Searching for pre-installed AMReX ...")
# https://amrex-codes.github.io/amrex/docs_html/BuildingAMReX.html#importing-amrex-into-your-cmake-project
# not strictly required yet to compile pyAMReX: EB
find_package(AMReX 24.10 CONFIG REQUIRED COMPONENTS PARTICLES PIC)
find_package(AMReX 24.11 CONFIG REQUIRED COMPONENTS PARTICLES PIC)
message(STATUS "AMReX: Found version '${AMReX_VERSION}'")

if(AMReX_GPU_BACKEND STREQUAL CUDA)
Expand All @@ -86,7 +86,7 @@ option(pyAMReX_amrex_internal "Download & build AMReX" ON)
set(pyAMReX_amrex_repo "https://github.com/AMReX-Codes/amrex.git"
CACHE STRING
"Repository URI to pull and build AMReX from if(pyAMReX_amrex_internal)")
set(pyAMReX_amrex_branch "8df11b69a1169a1b7791a7a5e723feecd121b467"
set(pyAMReX_amrex_branch "24.11"
CACHE STRING
"Repository branch for pyAMReX_amrex_repo if(pyAMReX_amrex_internal)")

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
# built documents.
#
# The short X.Y version.
version = "24.10"
version = "24.11"
# The full version, including alpha/beta/rc tags.
release = "24.10"
release = "24.11"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def build_extension(self, ext):
setup(
name="amrex",
# note PEP-440 syntax: x.y.zaN but x.y.z.devN
version="24.10",
version="24.11",
packages=["amrex"],
# Python sources:
package_dir={"": "src"},
Expand Down
10 changes: 6 additions & 4 deletions src/Base/BoxArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ void init_BoxArray(py::module &m) {
//! \brief Apply surroundingNodes(Box,int) to each Box in
//! BoxArray. See the documentation of Box for details.
BoxArray& surroundingNodes (int dir);
*/

//! Apply Box::enclosedCells() to each Box in the BoxArray.
BoxArray& enclosedCells ();
//! Apply Box::enclosedCells(int) to each Box in the BoxArray.
BoxArray& enclosedCells (int dir);
.def("enclosed_cells",
py::overload_cast<>(&BoxArray::enclosedCells))
.def("enclosed_cells",
py::overload_cast<int>(&BoxArray::enclosedCells))

/*
//! Apply Box::convert(IndexType) to each Box in the BoxArray.
BoxArray& convert (IndexType typ);
Expand Down
1 change: 1 addition & 0 deletions src/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ foreach(D IN LISTS AMReX_SPACEDIM)
Utility.cpp
Vector.cpp
Version.cpp
VisMF.cpp
)

if (AMReX_MPI)
Expand Down
6 changes: 4 additions & 2 deletions src/Base/IntVect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ namespace
py::class_< iv_type > py_iv(m, iv_name.c_str());
py_iv
.def("__repr__",
[iv_name](const iv_type&) {
return "<amrex." + iv_name + ">";
[iv_name](const iv_type& iv) {
std::stringstream s;
s << iv;
return "<amrex." + iv_name + s.str() + ">";
}
)
.def("__str",
Expand Down
46 changes: 46 additions & 0 deletions src/Base/VisMF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright 2024 The AMReX Community
*
* Authors: David Grote
* License: BSD-3-Clause-LBNL
*/
#include "pyAMReX.H"

#include <AMReX_VisMF.H>
#include <AMReX_MultiFab.H>

void init_VisMF(py::module &m)
{
py::class_< amrex::VisMF > py_VisMF(m, "VisMF");

py_VisMF
.def_static("Write",
[](const amrex::FabArray<amrex::FArrayBox> &mf, const std::string& name) {
return amrex::VisMF::Write(mf, name);
},
py::arg("mf"), py::arg("name"),
"Writes a Multifab to the specified file")
.def_static("Read",
[](const std::string &name) {
amrex::MultiFab mf;
if (amrex::VisMF::Exist(name)) {
amrex::VisMF::Read(mf, name);
} else {
throw std::runtime_error("MultiFab file " + name + " couldn't be found!");
}
return mf;
},
py::return_value_policy::move,
py::arg("name"),
"Reads a MultiFab from the specified file")
.def_static("Read",
[](const std::string &name, amrex::MultiFab &mf) {
if (amrex::VisMF::Exist(name)) {
amrex::VisMF::Read(mf, name);
} else {
throw std::runtime_error("MultiFab file " + name + " couldn't be found!");
}
},
py::arg("name"), py::arg("mf"),
"Reads a MultiFab from the specified file into the given MultiFab. The BoxArray on the disk must match the BoxArray * in mf")
;
}
62 changes: 48 additions & 14 deletions src/amrex/extensions/MultiFab.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,19 @@ def _process_index(self, index):
# If only one slice or integer passed in, it was not wrapped in a tuple
index = [index]
elif isinstance(index, tuple):
index = list(index)
for i in range(len(index)):
if index[i] == Ellipsis:
index = (
index[:i] + (dims + 2 - len(index)) * [slice(None)] + index[i + 1 :]
)
break
if len(index) == 0:
# The empty tuple specifies all valid and ghost cells
index = [index]
else:
index = list(index)
for i in range(len(index)):
if index[i] == Ellipsis:
index = (
index[:i]
+ (dims + 2 - len(index)) * [slice(None)]
+ index[i + 1 :]
)
break
else:
raise Exception("MultiFab.__getitem__: unexpected index type")

Expand Down Expand Up @@ -463,7 +469,7 @@ def _get_intersect_slice(self, mfi, index, with_internal_ghosts):
return None, None


def __getitem__(self, index):
def __getitem__(self, index, with_internal_ghosts=False):
"""Returns slice of the MultiFab using global indexing, as a numpy array.
This uses numpy array indexing, with the indexing relative to the global array.
The slice ranges can cross multiple blocks and the result will be gathered into a single
Expand All @@ -484,13 +490,18 @@ def __getitem__(self, index):
----------
index : the index using numpy style indexing
Index of the slice to return.
with_internal_ghosts : bool, optional
Whether to include internal ghost cells. When true, data from ghost cells may be used that
overlaps valid cells.
"""
index = _process_index(self, index)
index4 = _process_index(self, index)

# Gather the data to be included in a list to be sent to other processes
datalist = []
for mfi in self:
block_slices, global_slices = _get_intersect_slice(self, mfi, index, False)
block_slices, global_slices = _get_intersect_slice(
self, mfi, index4, with_internal_ghosts
)
if global_slices is not None:
# Note that the array will always have 4 dimensions.
device_arr = _get_field(self, mfi)
Expand Down Expand Up @@ -522,11 +533,29 @@ def __getitem__(self, index):
raise Exception("MultiFab.__getitem__ requires mpi4py")
all_datalist = comm_world.allgather(datalist)

# Create the array to be returned
result_shape = tuple([max(0, ii.stop - ii.start) for ii in index])
# The shape of the array to be returned
result_shape = tuple([max(0, ii.stop - ii.start) for ii in index4])

# If the boxes do not fill the domain, then include the internal ghost
# cells since they may cover internal regions not otherwise covered by valid cells.
# If the domain is not completely covered, __getitem__ is done twice, the first time
# including internal ghost cells, and the second time without. The second time is needed
# to ensure that in places where ghost cells overlap with valid cells, that the data
# from the valid cells is used.
# The domain is complete if the number of cells in the box array is the same as
# the number of cells in the minimal box.
cell_centered_box_array = self.box_array().enclosed_cells()
domain_complete = (
cell_centered_box_array.numPts == cell_centered_box_array.minimal_box().numPts()
)

if domain_complete or with_internal_ghosts:
result_global = None
else:
# First get the data including the internal ghost cells
result_global = self.__getitem__(index, with_internal_ghosts=True)

# Now, copy the data into the result array
result_global = None
for datalist in all_datalist:
for global_slices, f_arr in datalist:
if result_global is None:
Expand All @@ -540,7 +569,12 @@ def __getitem__(self, index):

# Remove dimensions of length 1, and if all dimensions
# are removed, return a scalar (that's what the [()] does)
return result_global.squeeze()[()]
if with_internal_ghosts:
# Return the data without the squeeze so that the result can be used in the loop
# above again.
return result_global
else:
return result_global.squeeze()[()]


def __setitem__(self, index, value):
Expand Down
5 changes: 4 additions & 1 deletion src/amrex/space1d/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ amrex
StructOfArrays
Utility
Vector
VisMF
"""

Expand Down Expand Up @@ -261,6 +262,7 @@ from amrex.space1d.amrex_1d_pybind import (
Vector_Long,
Vector_Real,
Vector_string,
VisMF,
XDim3,
begin,
coarsen,
Expand Down Expand Up @@ -508,6 +510,7 @@ __all__ = [
"Vector_Real",
"Vector_int",
"Vector_string",
"VisMF",
"XDim3",
"amrex_1d_pybind",
"begin",
Expand Down Expand Up @@ -553,4 +556,4 @@ def d_decl(x, y, z):

__author__: str = "Axel Huebl, Ryan T. Sandberg, Shreyas Ananthan, David P. Grote, Revathi Jambunathan, Edoardo Zoni, Remi Lehe, Andrew Myers, Weiqun Zhang"
__license__: str = "BSD-3-Clause-LBNL"
__version__: str = "24.10-8-g8df11b69a116"
__version__: str = "24.11"
34 changes: 31 additions & 3 deletions src/amrex/space1d/amrex_1d_pybind/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ amrex
StructOfArrays
Utility
Vector
VisMF

"""

Expand Down Expand Up @@ -261,6 +262,7 @@ __all__ = [
"Vector_Real",
"Vector_int",
"Vector_string",
"VisMF",
"XDim3",
"begin",
"coarsen",
Expand Down Expand Up @@ -4935,6 +4937,10 @@ class BoxArray:
@typing.overload
def coarsenable(self, arg0: IntVect1D, arg1: IntVect1D) -> bool: ...
def define(self, arg0: Box) -> None: ...
@typing.overload
def enclosed_cells(self) -> BoxArray: ...
@typing.overload
def enclosed_cells(self, arg0: int) -> BoxArray: ...
def get(self, arg0: int) -> Box: ...
def ix_type(self) -> IndexType: ...
@typing.overload
Expand All @@ -4959,7 +4965,7 @@ class BoxArray:
def size(self) -> int: ...

class Config:
amrex_version: typing.ClassVar[str] = "24.10-8-g8df11b69a116"
amrex_version: typing.ClassVar[str] = "24.11"
gpu_backend = None
have_eb: typing.ClassVar[bool] = False
have_gpu: typing.ClassVar[bool] = False
Expand Down Expand Up @@ -6276,7 +6282,7 @@ class MultiFab(FabArray_FArrayBox):
"""
dst = src + a*dst
"""
def __getitem__(self, index):
def __getitem__(self, index, with_internal_ghosts=False):
"""
Returns slice of the MultiFab using global indexing, as a numpy array.
This uses numpy array indexing, with the indexing relative to the global array.
Expand All @@ -6298,6 +6304,9 @@ class MultiFab(FabArray_FArrayBox):
----------
index : the index using numpy style indexing
Index of the slice to return.
with_internal_ghosts : bool, optional
Whether to include internal ghost cells. When true, data from ghost cells may be used that
overlaps valid cells.

"""
@typing.overload
Expand Down Expand Up @@ -18043,6 +18052,25 @@ class Vector_string:
"""
def size(self) -> int: ...

class VisMF:
@staticmethod
@typing.overload
def Read(name: str) -> MultiFab:
"""
Reads a MultiFab from the specified file
"""
@staticmethod
@typing.overload
def Read(name: str, mf: MultiFab) -> None:
"""
Reads a MultiFab from the specified file into the given MultiFab. The BoxArray on the disk must match the BoxArray * in mf
"""
@staticmethod
def Write(mf: FabArray_FArrayBox, name: str) -> int:
"""
Writes a Multifab to the specified file
"""

class XDim3:
x: float
y: float
Expand Down Expand Up @@ -18351,5 +18379,5 @@ def write_single_level_plotfile(

__author__: str = "Axel Huebl, Ryan T. Sandberg, Shreyas Ananthan, David P. Grote, Revathi Jambunathan, Edoardo Zoni, Remi Lehe, Andrew Myers, Weiqun Zhang"
__license__: str = "BSD-3-Clause-LBNL"
__version__: str = "24.10-8-g8df11b69a116"
__version__: str = "24.11"
IntVect = IntVect1D
Loading

0 comments on commit d41d068

Please sign in to comment.