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

Create Stub Files: Scripts & CI #184

Merged
merged 6 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 18 additions & 0 deletions .github/update_stub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
#
# Copyright 2021-2023 The AMReX Community
#
# This script updates the .pyi stub files for documentation and interactive use.
# To run this script, pyAMReX needs to be installed (all dimensions) and importable.
#
# Authors: Axel Huebl
# License: BSD-3-Clause-LBNL
#
set -eu -o pipefail

# we are in the source directory, .github/
this_dir=$(cd $(dirname $0) && pwd)

pybind11-stubgen --exit-code -o ${this_dir}/../src/amrex/ amrex.space1d
pybind11-stubgen --exit-code -o ${this_dir}/../src/amrex/ amrex.space2d
pybind11-stubgen --exit-code -o ${this_dir}/../src/amrex/ amrex.space3d
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 👑 CI

# This workflow updates the .pyi stub files for documentation and interactive use.

on: [push, pull_request]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-ci
cancel-in-progress: true

jobs:
ubuntu:
name: 🐧 Ubuntu
uses: ./.github/workflows/ubuntu.yml

intel:
name: 🐧 Intel
uses: ./.github/workflows/intel.yml

hip:
name: 🐧 HIP
uses: ./.github/workflows/hip.yml

macos:
name: 🍏 macOS
uses: ./.github/workflows/macos.yml

windows:
name: 🪟 Windows
uses: ./.github/workflows/windows.yml

stubs:
name: 🔄 Update Stub Files
needs: [ubuntu, intel, hip, macos, windows]
uses: ./.github/workflows/stubs.yml
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CodeQL"
name: 🔎 CodeQL

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hip.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 🐧 HIP

on: [push, pull_request]
on: [workflow_call]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-hip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/intel.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 🐧 Intel

on: [push, pull_request]
on: [workflow_call]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-intel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 🍏 macOS

on: [push, pull_request]
on: [workflow_call]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-macos
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/stubs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 🔄 Update Stub Files

# This workflow updates the .pyi stub files for documentation and interactive use.

on: [workflow_call]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-stubs
cancel-in-progress: true

jobs:
# Build and install libamrex as AMReX CMake project
stubs:
name: Stubs
runs-on: ubuntu-22.04
env:
CC: gcc
CXX: g++
CXXFLAGS: "-O1"
OMP_NUM_THREAD: 2

if: github.event.pull_request.draft == false
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# changed files back to the repository.
contents: write

steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}

- name: Pull Remote Changes
run: git pull

- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.9'

- name: Dependencies
run: .github/workflows/dependencies/dependencies_gcc10.sh

- name: Build & Install
run: |
python3 -m pip install -U pip setuptools wheel
python3 -m pip install -U pip mpi4py pytest pybind11-stubgen pre-commit
cmake -S . -B build -DAMReX_SPACEDIM="1;2;3" -DpyAMReX_IPO=OFF
cmake --build build -j 2 --target pip_install

- name: Update Stubs
run: |
.github/update_stub.sh
ax3l marked this conversation as resolved.
Show resolved Hide resolved

- name: Run pre-commit cleanup
run: |
git add .
pre-commit run -a || true
git add .

- name: Update Install
run: |
cmake --build build -j 2 --target pip_install

- name: Unit tests
run: |
mpiexec -np 1 python3 -m pytest tests/

- uses: stefanzweifel/git-auto-commit-action@v4
name: Commit Updated Stub Files
with:
commit_message: Update Stub Files
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 🐧 Ubuntu

on: [push, pull_request]
on: [workflow_call]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-linux
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 🪟 Windows

on: [push, pull_request]
on: [workflow_call]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-windows
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ repos:
args: [--allow-multiple-documents]
- id: check-added-large-files
args: ['--maxkb=40']
exclude: ^.*\.pyi$
- id: requirements-txt-fixer
# - id: fix-encoding-pragma
# exclude: ^noxfile.py$
Expand Down
51 changes: 37 additions & 14 deletions src/Base/Array4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@
{
using namespace amrex;

constexpr bool is_not_const = std::is_same_v<std::remove_cv_t<T>, T>;

// dispatch simpler via: py::format_descriptor<T>::format() naming
auto const array_name = std::string("Array4_").append(typestr);
py::class_< Array4<T> >(m, array_name.c_str())
py::class_< Array4<T> > py_array4(m, array_name.c_str());
py_array4
.def("__repr__",
[typestr](Array4<T> const & a4) {
std::stringstream s;
Expand Down Expand Up @@ -193,15 +196,7 @@
.def("contains", &Array4<T>::contains)
//.def("__contains__", &Array4<T>::contains)

// setter & getter
.def("__setitem__", [](Array4<T> & a4, IntVect const & v, T const value){ a4(v) = value; })
.def("__setitem__", [](Array4<T> & a4, std::array<int, 4> const key, T const value){
a4(key[0], key[1], key[2], key[3]) = value;
})
.def("__setitem__", [](Array4<T> & a4, std::array<int, 3> const key, T const value){
a4(key[0], key[1], key[2]) = value;
})

// getter
.def("__getitem__", [](Array4<T> & a4, IntVect const & v){ return a4(v); })
.def("__getitem__", [](Array4<T> & a4, std::array<int, 4> const key){
return a4(key[0], key[1], key[2], key[3]);
Expand All @@ -211,11 +206,25 @@
})
;

// setter
if constexpr (is_not_const)
{
py_array4
.def("__setitem__", [](Array4<T> & a4, IntVect const & v, T const value){ a4(v) = value; })
.def("__setitem__", [](Array4<T> & a4, std::array<int, 4> const key, T const value){
a4(key[0], key[1], key[2], key[3]) = value;
})
.def("__setitem__", [](Array4<T> & a4, std::array<int, 3> const key, T const value){
a4(key[0], key[1], key[2]) = value;
})
;
}

// free standing C++ functions:
m.def("lbound", &lbound< Array4<T> >);
m.def("ubound", &ubound< Array4<T> >);
m.def("length", &length< Array4<T> >);
m.def("makePolymorphic", &makePolymorphic< Array4<T> >);
m.def("lbound", &lbound< T >);
m.def("ubound", &ubound< T >);
m.def("length", &length< T >);
//m.def("makePolymorphic", &makePolymorphic< T >);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
}

void init_Array4(py::module &m) {
Expand All @@ -233,6 +242,20 @@
make_Array4< unsigned long >(m, "ulong");
make_Array4< unsigned long long >(m, "ulonglong");

make_Array4< float const >(m, "float_const");
make_Array4< double const >(m, "double_const");
make_Array4< long double const >(m, "longdouble_const");

make_Array4< short const >(m, "short_const");
make_Array4< int const >(m, "int_const");
make_Array4< long const >(m, "long_const");
make_Array4< long long const >(m, "longlong_const");

make_Array4< unsigned short const >(m, "ushort_const");
make_Array4< unsigned int const >(m, "uint_const");
make_Array4< unsigned long const >(m, "ulong_const");
make_Array4< unsigned long long const >(m, "ulonglong_const");

// std::complex< float|double|long double> ?

/*
Expand Down
4 changes: 4 additions & 0 deletions src/Base/BoxArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
#include "pyAMReX.H"

#include "Base/Vector.H"

#include <AMReX_BoxArray.H>
#include <AMReX_IntVect.H>

Expand Down Expand Up @@ -281,4 +283,6 @@ void init_BoxArray(py::module &m) {
*/

;

make_Vector<BoxArray> (m, "BoxArray");
}
19 changes: 13 additions & 6 deletions src/Base/CoordSys.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* Copyright 2021-2023 The AMReX Community
*
* Authors: Axel Huebl, Ryan Sandberg
* License: BSD-3-Clause-LBNL
*/
#include "pyAMReX.H"

#include <AMReX_CoordSys.H>
Expand All @@ -8,6 +13,14 @@ void init_CoordSys(py::module& m)
using namespace amrex;

py::class_<CoordSys> coord_sys(m, "CoordSys");

py::enum_<CoordSys::CoordType>(coord_sys, "CoordType")
.value("undef", CoordSys::CoordType::undef)
.value("cartesian", CoordSys::CoordType::cartesian)
.value("RZ", CoordSys::CoordType::RZ)
.value("SPHERICAL", CoordSys::CoordType::SPHERICAL)
.export_values();

coord_sys.def("__repr__",
[](const CoordSys&) {
return "<amrex.CoordSys>";
Expand All @@ -27,10 +40,4 @@ void init_CoordSys(py::module& m)
// ...
;

py::enum_<CoordSys::CoordType>(coord_sys, "CoordType")
.value("undef", CoordSys::CoordType::undef)
.value("cartesian", CoordSys::CoordType::cartesian)
.value("RZ", CoordSys::CoordType::RZ)
.value("SPHERICAL", CoordSys::CoordType::SPHERICAL)
.export_values();
}
4 changes: 4 additions & 0 deletions src/Base/DistributionMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
#include "pyAMReX.H"

#include "Base/Vector.H"

#include <AMReX_BoxArray.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_Vector.H>
Expand Down Expand Up @@ -73,4 +75,6 @@ void init_DistributionMapping(py::module &m) {
return dm[index];
})
;

make_Vector<DistributionMapping> (m, "DistributionMapping");
}
4 changes: 3 additions & 1 deletion src/Base/FArrayBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ void init_FArrayBox(py::module &m) {
.def(py::init< Arena* >())
.def(py::init< Box const &, int, Arena* >())
.def(py::init< Box const &, int, bool, bool, Arena* >())
.def(py::init< FArrayBox const &, MakeType, int, int >())
//.def(py::init< FArrayBox const &, MakeType, int, int >())
.def(py::init< Box const &, int, Real const* >())
.def(py::init< Box const &, int, Real* >())
.def(py::init< Array4<Real> const& >())
.def(py::init< Array4<Real> const&, IndexType >())
.def(py::init< Array4<Real const> const& >())
.def(py::init< Array4<Real const> const&, IndexType >())

/*
.def("read_from",
py::overload_cast<std::istream&>(&FArrayBox::readFrom),
py::arg("is")
Expand All @@ -51,5 +52,6 @@ void init_FArrayBox(py::module &m) {
py::overload_cast<std::ostream&, int, int>(&FArrayBox::writeOn, py::const_),
py::arg("of"), py::arg("comp"), py::arg("num_comp")
)
*/
;
}
4 changes: 4 additions & 0 deletions src/Base/Geometry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pyAMReX.H"

#include "Base/Vector.H"

#include <AMReX_Geometry.H>
#include <AMReX_CoordSys.H>
#include <AMReX_MultiFab.H>
Expand Down Expand Up @@ -205,4 +207,6 @@ void init_Geometry(py::module& m)
// .def("computeRoundoffDomain")
;


make_Vector<Geometry> (m, "Geometry");
}
Loading
Loading