Skip to content

Commit

Permalink
resolve conflict. work in Python mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhamv committed Aug 22, 2024
2 parents 301ebcc + d9bd5dc commit 9fa5139
Show file tree
Hide file tree
Showing 34 changed files with 997 additions and 1,596 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
- uses: mpi4py/setup-mpi@v1
- name: Install dependencies
run: |
#sudo apt-get install libopenmpi-dev
#pip install numpy numba h5py matplotlib scipy pytest colorama mpi4py ngsolve distinctipy
pip list
pip install -e .
pip list
- name: Patch Numba
run : |
bash .github/workflows/patch.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"] #, "macos-latest"
os: ["ubuntu-latest"]
steps:
- uses: actions/checkout@v3
- name: Set up python 3.11
Expand All @@ -22,10 +22,8 @@ jobs:
- uses: mpi4py/setup-mpi@v1
- name: Install dependencies
run: |
#sudo apt-get install libopenmpi-dev
#pip install numpy numba h5py matplotlib scipy pytest colorama mpi4py ngsolve distinctipy
pip list
pip install -e .
pip list
- name: Patch Numba
run : |
bash .github/workflows/patch.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ jobs:
- uses: mpi4py/setup-mpi@v1
- name: Install dependencies
run: |
#sudo apt-get install libopenmpi-dev
#pip install numpy numba h5py matplotlib scipy pytest colorama mpi4py ngsolve distinctipy
pip list
pip install -e .
pip list
- name: Patch Numba
run : |
bash .github/workflows/patch.sh
- name: Regression Test - Numba
run: |
cd test/regression
python run.py --mode=numba
python run.py --mode=numba --target=gpu
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
- uses: mpi4py/setup-mpi@v1
- name: Install dependencies
run: |
#sudo apt-get install libopenmpi-dev
#pip install numpy numba h5py matplotlib scipy pytest colorama mpi4py ngsolve distinctipy
pip list
pip install -e .
pip list
- name: Patch Numba
run : |
bash .github/workflows/patch.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
- uses: mpi4py/setup-mpi@v1
- name: Install dependencies
run: |
#sudo apt-get install libopenmpi-dev
#pip install numpy numba h5py matplotlib scipy pytest colorama mpi4py ngsolve distinctipy
pip list
pip install -e .
pip list
- name: Patch Numba
run : |
bash .github/workflows/patch.sh
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# On Read the Docs, need to mock any python packages that would require c
from unittest.mock import MagicMock

MOCK_MODULES = ["mpi4py", "colorama"]
MOCK_MODULES = ["mpi4py", "colorama", "mpi4py.util.dtlib"]
sys.modules.update((mod_name, MagicMock()) for mod_name in MOCK_MODULES)


Expand Down
13 changes: 6 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! { python3 -c 'import sys; assert sys.version_info < (3,12)' > /dev/null 2>&
echo " Found $v at $p."
echo "ERROR: Installation failed."
exit 1
fi
fi

# Install or build mpi4py
if [ $# -eq 0 ]; then
Expand Down Expand Up @@ -41,15 +41,14 @@ while [ $# -gt 0 ]; do
shift
done

# Install MC/DC module
# Install MC/DC module (and the dependencies)
pip install -e .

# Patch Numba
bash patch_numba.sh

# Install MC/DC dependencies, reply "y" to conda prompt
conda install numpy numba matplotlib scipy h5py pytest colorama <<< "y"
# Install pre-commit hook
pre-commit install

# Installing visualization dependencies (required via pip for osx-arm64)
pip install ngsolve distinctipy

bash patch_numba.sh

1 change: 0 additions & 1 deletion mcdc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
iQMC,
weight_roulette,
IC_generator,
dsm,
uq,
reset,
domain_decomposition,
Expand Down
55 changes: 1 addition & 54 deletions mcdc/adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def add_active(particle, prog):

@for_gpu()
def add_active(particle, prog):
P = kernel.recordlike_to_particle(particle)
P = kernel.make_particle(particle)
if SIMPLE_ASYNC:
step_async(prog, P)
else:
Expand Down Expand Up @@ -383,59 +383,6 @@ def add_IC(particle, prog):
kernel.add_particle(particle, mcdc["technique"]["IC_bank_neutron_local"])


@for_cpu()
def local_translate():
return np.zeros(1, dtype=type_.translate)[0]


@for_gpu()
def local_translate():
trans = cuda.local.array(1, type_.translate)[0]
for i in range(3):
trans["values"][i] = 0
return trans


@for_cpu()
def local_group_array():
return np.zeros(1, dtype=type_.group_array)[0]


@for_gpu()
def local_group_array():
return cuda.local.array(1, type_.group_array)[0]


@for_cpu()
def local_j_array():
return np.zeros(1, dtype=type_.j_array)[0]


@for_gpu()
def local_j_array():
return cuda.local.array(1, type_.j_array)[0]


@for_cpu()
def local_particle():
return np.zeros(1, dtype=type_.particle)[0]


@for_gpu()
def local_particle():
return cuda.local.array(1, dtype=type_.particle)[0]


@for_cpu()
def local_particle_record():
return np.zeros(1, dtype=type_.particle_record)[0]


@for_gpu()
def local_particle_record():
return cuda.local.array(1, dtype=type_.particle_record)[0]


@for_cpu()
def global_add(ary, idx, val):
result = ary[idx]
Expand Down
37 changes: 37 additions & 0 deletions mcdc/algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from numba import njit


@njit
def binary_search_with_length(val, grid, length):
"""
Binary search that returns the bin index of the value `val` given grid `grid`
Only search up to `length`-th element
Some special cases:
val < min(grid) --> -1
val > max(grid) --> size of bins
val = a grid point --> bin location whose upper bound is val
(-1 if val = min(grid)
"""
left = 0
if length == 0:
right = len(grid) - 1
else:
right = length - 1
mid = -1
while left <= right:
mid = int((left + right) / 2)
if grid[mid] < val:
left = mid + 1
else:
right = mid - 1
return int(right)


@njit
def binary_search(val, grid):
"""
Binary search with full length of the given grid.
See binary_search_with _length
"""
return binary_search_with_length(val, grid, 0)
Loading

0 comments on commit 9fa5139

Please sign in to comment.