-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
142 changed files
with
183,412 additions
and
48,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Castro development | ||
|
||
on: [push, pull_request] | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.head_ref }}-apps-dev | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
castro-development: | ||
name: Castro development | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Download Castro | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: 'AMReX-Astro/Castro' | ||
ref: development | ||
path: 'Castro' | ||
- name: Download AMReX | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: 'AMReX-Codes/amrex' | ||
ref: development | ||
path: 'amrex' | ||
- name: Dependencies | ||
run: | | ||
.github/workflows/dependencies/dependencies.sh | ||
.github/workflows/dependencies/dependencies_ccache.sh | ||
- name: Set Up Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/ccache | ||
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }} | ||
restore-keys: | | ||
ccache-${{ github.workflow }}-${{ github.job }}-git- | ||
- name: Build flame_wave | ||
run: | | ||
export CCACHE_COMPRESS=1 | ||
export CCACHE_COMPRESSLEVEL=10 | ||
export CCACHE_MAXSIZE=75M | ||
export CCACHE_LOGFILE=${{ github.workspace }}/ccache.log.txt | ||
ccache -z | ||
export AMREX_HOME=${PWD}/amrex | ||
export MICROPHYSICS_HOME=${PWD} | ||
cd Castro/Exec/science/flame_wave/ | ||
make -j2 CCACHE=ccache USE_MPI=FALSE | ||
ccache -s | ||
du -hs ~/.cache/ccache | ||
- name: Build subchandra | ||
run: | | ||
export CCACHE_COMPRESS=1 | ||
export CCACHE_COMPRESSLEVEL=10 | ||
export CCACHE_MAXSIZE=75M | ||
export CCACHE_LOGFILE=${{ github.workspace }}/ccache.log.txt | ||
ccache -z | ||
export AMREX_HOME=${PWD}/amrex | ||
export MICROPHYSICS_HOME=${PWD} | ||
cd Castro/Exec/science/subchandra/ | ||
make -j2 CCACHE=ccache USE_MPI=FALSE | ||
ccache -s | ||
du -hs ~/.cache/ccache | ||
save_pr_number: | ||
if: github.event_name == 'pull_request' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Save PR number | ||
env: | ||
PR_NUMBER: ${{ github.event.number }} | ||
run: | | ||
echo $PR_NUMBER > pr_number.txt | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: pr_number | ||
path: pr_number.txt | ||
retention-days: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import subprocess | ||
import sys | ||
import os | ||
import re | ||
|
||
|
||
def pow_to_powi(text): | ||
# Finds all possible std::pow(x, n) or gcem::pow(x, n) | ||
# where n is a potential integer to amrex::Math::powi<n>(x) | ||
|
||
# Check for all positive and negative integer, whole float numbers | ||
# with and without _rt | ||
match_pattern = r"([^,]+),\s*(-?(?:\d+\.0*_rt?|\d))" | ||
|
||
# Match fails when there is a nested pow, so only inner most pow is matched | ||
negate_pattern = r"(?![\s\S]*(?:std|gcem)::pow\((?:[^,]+),\s*(?:-?(?:\d+\.0*_rt?|\d))\))" | ||
|
||
# Final pattern | ||
pattern = rf"(?:std|gcem)::pow\({negate_pattern}{match_pattern}\)" | ||
# pattern = rf"(?:std|gcem)::pow\((?![\s\S]*(?:std|gcem)::pow\((?:[^,]+),\s*(?:-?(?:\d+\.0*_rt?|\d))\))([^,]+),\s*(-?(?:\d+\.0*_rt?|\d))\)" | ||
|
||
def replacement(match): | ||
x = match.group(1) | ||
n = match.group(2) | ||
|
||
# Only extracts out the integer part before decimal point | ||
n = n.split('.')[0] if '.' in n else n | ||
return f"amrex::Math::powi<{n}>({x})" | ||
|
||
text = re.sub(pattern, replacement, text) | ||
return text | ||
|
||
def process_content(dir_path): | ||
# This function processes all text in the given directory | ||
for root, dirs, filenames in os.walk(dir_path): | ||
for filename in filenames: | ||
if filename.endswith(".H") or filename.endswith(".cpp"): | ||
filepath = os.path.join(root, filename) | ||
|
||
with open(filepath, 'r') as file: | ||
old_content = file.read() | ||
|
||
# Iterate over content until content is the same | ||
# This is used to get rid of potential nested pow | ||
new_content = pow_to_powi(old_content) | ||
while new_content != old_content: | ||
old_content = new_content | ||
new_content = pow_to_powi(old_content) | ||
|
||
with open(filepath, 'w') as file: | ||
file.write(new_content) | ||
|
||
def git_diff(): | ||
# Run git diff to see if there are any changes made | ||
|
||
git_diff_output = subprocess.run(['git', 'diff', '--color=always'], | ||
capture_output=True, text=True) | ||
|
||
# Print out suggested change and raise error after detecting modification | ||
if git_diff_output.stdout: | ||
print("Detected potential usage to replace std::pow" + | ||
"with integer powers via amrex::Math::powi\n") | ||
print("Below are the suggested change:\n") | ||
print(git_diff_output.stdout) | ||
|
||
raise RuntimeError("Changes detected after modification") | ||
|
||
if __name__ == '__main__': | ||
|
||
# Get directory paths | ||
directory_paths = sys.argv[1:] | ||
|
||
# Modify the std::pow -> amrex::Math::powi if needed | ||
for dir_path in directory_paths: | ||
process_content(dir_path) | ||
|
||
# Give suggested change if there are any modifications made | ||
git_diff() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: check powi | ||
|
||
on: | ||
push: | ||
branches: | ||
- development | ||
- main | ||
pull_request: | ||
branches: | ||
- development | ||
|
||
jobs: | ||
check-ifdefs: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Cache pip | ||
uses: actions/cache@v3 | ||
with: | ||
# this path is specific to Ubuntu | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Run check_powi | ||
run: | | ||
python .github/workflows/check_powi.py . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.