-
Notifications
You must be signed in to change notification settings - Fork 3
Changing to boolean argument in parallel_assert
#11
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
Merged
connorjward
merged 12 commits into
firedrakeproject:main
from
brownbaerchen:bool_parallel_assert
Mar 1, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9eb7866
parallel_assert now takes boolean argument and added basic tests
brownbaerchen cc3326c
Moved test environment file
brownbaerchen f771aff
Added missing mpi4py dependency to test environment
brownbaerchen c4edcf8
Forgot to adapt README to new syntax
brownbaerchen 8c7e0fb
Update tests/test_parallel_assert.py
brownbaerchen 4cc1914
Update tests/test_parallel_assert.py
brownbaerchen 3612e71
Update pytest_mpi/parallel_assert.py
brownbaerchen dac946d
Update pytest_mpi/parallel_assert.py
brownbaerchen a83d0d7
Implemented @connorjward's comments
brownbaerchen 2281096
Merge branch 'bool_parallel_assert' of github.com:brownbaerchen/mpi-p…
brownbaerchen 13553f7
Fixed documentation
brownbaerchen cb0ca7f
Added CI badge to README
brownbaerchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
--- | ||
|
||
name: MPICH_test_env | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- pytest | ||
- mpich | ||
- mpi4py |
This file contains hidden or 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,36 @@ | ||
--- | ||
|
||
name: CI pipeline for mpi-pytest | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: '1 5 * * 1' | ||
|
||
jobs: | ||
|
||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python: ['3.9', '3.10', '3.11', '3.12', '3.13'] | ||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Install Conda environment with Micromamba | ||
uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
environment-file: ".github/etc/test_environment_mpich.yml" | ||
create-args: >- | ||
python=${{ matrix.python }} | ||
- name: Install mpi-pytest as a package in the current environment | ||
run: | | ||
pip install --no-deps -e . | ||
- name: Run tests | ||
run: | | ||
pytest --continue-on-collection-errors -v tests |
This file contains hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
import pytest | ||
from mpi4py import MPI | ||
from pytest_mpi.parallel_assert import parallel_assert | ||
|
||
|
||
@pytest.mark.parametrize('expression', [True, False]) | ||
def test_parallel_assert_equivalent_to_assert_in_serial(expression): | ||
try: | ||
parallel_assert(expression) | ||
parallel_raised_exception = False | ||
except AssertionError: | ||
parallel_raised_exception = True | ||
try: | ||
assert expression | ||
serial_raised_exception = False | ||
except AssertionError: | ||
serial_raised_exception = True | ||
|
||
assert serial_raised_exception == parallel_raised_exception | ||
|
||
|
||
@pytest.mark.parallel([1, 2, 3]) | ||
def test_parallel_assert_all_tasks(): | ||
comm = MPI.COMM_WORLD | ||
expression = comm.rank < comm.size // 2 # will be True on some tasks but False on others | ||
|
||
try: | ||
parallel_assert(expression, 'Failed') | ||
raised_exception = False | ||
except AssertionError: | ||
raised_exception = True | ||
|
||
assert raised_exception, f'No exception raised on rank {comm.rank}!' | ||
|
||
|
||
@pytest.mark.parallel([1, 2, 3]) | ||
def test_parallel_assert_participating_tasks_only(): | ||
comm = MPI.COMM_WORLD | ||
expression = comm.rank < comm.size // 2 # will be True on some tasks but False on others | ||
|
||
try: | ||
parallel_assert(expression, participating=expression) | ||
raised_exception = False | ||
except AssertionError: | ||
raised_exception = True | ||
|
||
assert not raised_exception, f'Exception raised on rank {comm.rank}!' | ||
brownbaerchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.mark.parallel([1, 2, 3]) | ||
def test_legacy_parallel_assert(): | ||
comm = MPI.COMM_WORLD | ||
expression = comm.rank < comm.size // 2 # will be True on some tasks but False on others | ||
if expression: | ||
local_expression = expression # This variable is undefined on non-participating tasks | ||
|
||
try: | ||
parallel_assert(lambda: local_expression, participating=expression) | ||
raised_exception = False | ||
except AssertionError: | ||
raised_exception = True | ||
|
||
assert not raised_exception, f'Exception raised on rank {comm.rank}!' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.