-
Notifications
You must be signed in to change notification settings - Fork 3
update notebooks #831
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
update notebooks #831
Changes from all commits
6c799bc
9151656
c7cf3fd
c5da5c1
39f7492
43256cf
1f2ab00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,123 @@ | ||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| from mpi4py.MPI import Request, SUM, MAX, MIN, IN_PLACE, IDENT, CONGRUENT, SIMILAR, UNEQUAL | ||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||
| pass | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class MPI4PYWrapper: | ||||||||||||||||||||||
| def __init__(self, comm, parent=None): | ||||||||||||||||||||||
| self.comm = comm | ||||||||||||||||||||||
| self.size = comm.size | ||||||||||||||||||||||
| self.rank = comm.rank | ||||||||||||||||||||||
| self.parent = parent # XXX check C-object against comm.parent? | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def new_communicator(self, ranks): | ||||||||||||||||||||||
| comm = self.comm.Create(self.comm.group.Incl(ranks)) | ||||||||||||||||||||||
| if self.comm.rank in ranks: | ||||||||||||||||||||||
| return MPI4PYWrapper(comm, parent=self) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| # This cpu is not in the new communicator: | ||||||||||||||||||||||
| return None | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def max_scalar(self, a, root=-1): | ||||||||||||||||||||||
| return self.sum_scalar(a, root=-1, _op=MAX) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def min_scalar(self, a, root=-1): | ||||||||||||||||||||||
| return self.sum_scalar(a, root=-1, _op=MIN) | ||||||||||||||||||||||
|
Comment on lines
+24
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused Both Forward the def max_scalar(self, a, root=-1):
- return self.sum_scalar(a, root=-1, _op=MAX)
+ return self.sum_scalar(a, root=root, _op=MAX)
def min_scalar(self, a, root=-1):
- return self.sum_scalar(a, root=-1, _op=MIN)
+ return self.sum_scalar(a, root=root, _op=MIN)📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.13.3)24-24: Unused method argument: (ARG002) 27-27: Unused method argument: (ARG002) 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def sum_scalar(self, a, root=-1, _op=None): | ||||||||||||||||||||||
| if _op is None: | ||||||||||||||||||||||
| _op = SUM | ||||||||||||||||||||||
| assert isinstance(a, (int, float, complex)) | ||||||||||||||||||||||
| if root == -1: | ||||||||||||||||||||||
| return self.comm.allreduce(a, op=_op) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| return self.comm.reduce(a, root=root, op=_op) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def sum(self, a, root=-1): | ||||||||||||||||||||||
| if root == -1: | ||||||||||||||||||||||
| self.comm.Allreduce(IN_PLACE, a, op=SUM) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| if root == self.rank: | ||||||||||||||||||||||
| self.comm.Reduce(IN_PLACE, a, root=root, op=SUM) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| self.comm.Reduce(a, None, root=root, op=SUM) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def scatter(self, a, b, root): | ||||||||||||||||||||||
| self.comm.Scatter(a, b, root) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def alltoallv(self, sbuffer, scounts, sdispls, rbuffer, rcounts, rdispls): | ||||||||||||||||||||||
| self.comm.Alltoallv((sbuffer, (scounts, sdispls), sbuffer.dtype.char), | ||||||||||||||||||||||
| (rbuffer, (rcounts, rdispls), rbuffer.dtype.char)) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def all_gather(self, a, b): | ||||||||||||||||||||||
| self.comm.Allgather(a, b) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def gather(self, a, root, b=None): | ||||||||||||||||||||||
| self.comm.Gather(a, b, root) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def broadcast(self, a, root): | ||||||||||||||||||||||
| self.comm.Bcast(a, root) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def sendreceive(self, a, dest, b, src, sendtag=123, recvtag=123): | ||||||||||||||||||||||
| return self.comm.Sendrecv(a, dest, sendtag, b, src, recvtag) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def send(self, a, dest, tag=123, block=True): | ||||||||||||||||||||||
| if block: | ||||||||||||||||||||||
| self.comm.Send(a, dest, tag) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| return self.comm.Isend(a, dest, tag) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def ssend(self, a, dest, tag=123): | ||||||||||||||||||||||
| return self.comm.Ssend(a, dest, tag) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def receive(self, a, src, tag=123, block=True): | ||||||||||||||||||||||
| if block: | ||||||||||||||||||||||
| self.comm.Recv(a, src, tag) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| return self.comm.Irecv(a, src, tag) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def test(self, request): | ||||||||||||||||||||||
| return request.test() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def testall(self, requests): | ||||||||||||||||||||||
| return Request.testall(requests) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def wait(self, request): | ||||||||||||||||||||||
| request.wait() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def waitall(self, requests): | ||||||||||||||||||||||
| Request.waitall(requests) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def name(self): | ||||||||||||||||||||||
| return self.comm.Get_name() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def barrier(self): | ||||||||||||||||||||||
| self.comm.barrier() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def abort(self, errcode): | ||||||||||||||||||||||
| self.comm.Abort(errcode) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def compare(self, othercomm): | ||||||||||||||||||||||
| code = self.comm.Compare(othercomm.comm) | ||||||||||||||||||||||
| if code == IDENT: | ||||||||||||||||||||||
| return "ident" | ||||||||||||||||||||||
| elif code == CONGRUENT: | ||||||||||||||||||||||
| return "congruent" | ||||||||||||||||||||||
| elif code == SIMILAR: | ||||||||||||||||||||||
| return "similar" | ||||||||||||||||||||||
| elif code == UNEQUAL: | ||||||||||||||||||||||
| return "unequal" | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| raise ValueError(f"Unknown compare code {code}") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def translate_ranks(self, other, ranks): | ||||||||||||||||||||||
| return np.array(self.comm.Get_group().Translate_ranks(ranks, other.comm.Get_group())) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_members(self): | ||||||||||||||||||||||
| return self.translate_ranks(self.parent, np.arange(self.size)) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_c_object(self): | ||||||||||||||||||||||
| return self.comm | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -179,13 +179,13 @@ jobs: | |||||
| channels: conda-forge | ||||||
| conda-remove-defaults: "true" | ||||||
| environment-file: .ci_support/environment-integration.yml | ||||||
| - name: Install | ||||||
| shell: bash -l {0} | ||||||
| run: pip install . --no-deps --no-build-isolation | ||||||
| - name: Notebooks | ||||||
| shell: bash -l {0} | ||||||
| timeout-minutes: 20 | ||||||
| run: | | ||||||
| pip install . --no-deps --no-build-isolation | ||||||
| cp .ci_support/mpi4pywrapper.py /home/runner/miniconda3/envs/test/lib/python3.12/site-packages/gpaw | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded Python version in path is brittle. The path explicitly includes Consider using a version-agnostic approach: - cp .ci_support/mpi4pywrapper.py /home/runner/miniconda3/envs/test/lib/python3.12/site-packages/gpaw
+ cp .ci_support/mpi4pywrapper.py $(python -c "import sysconfig; print(sysconfig.get_path('purelib'))")/gpaw📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| flux start flux resource list | ||||||
| flux start papermill notebooks/5-1-gpaw.ipynb notebooks/5-1-gpaw-out.ipynb -k python3 | ||||||
| flux start papermill notebooks/5-2-quantum-espresso.ipynb notebooks/5-2-quantum-espresso-out.ipynb -k python3 | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silent import failure prevents clear error diagnosis.
The bare
passin the except clause silently suppresses import errors, which will lead to crypticNameErrorexceptions later when MPI constants are referenced (lines 25, 28, 32, 35, etc.). This makes it difficult to diagnose missing dependencies.Consider one of these approaches:
Option 1: Fail fast if mpi4py is unavailable:
try: from mpi4py.MPI import Request, SUM, MAX, MIN, IN_PLACE, IDENT, CONGRUENT, SIMILAR, UNEQUAL except ImportError: - pass + raise ImportError("mpi4py is required but not installed")Option 2: Define stub constants if testing without mpi4py is intentional:
try: from mpi4py.MPI import Request, SUM, MAX, MIN, IN_PLACE, IDENT, CONGRUENT, SIMILAR, UNEQUAL except ImportError: - pass + # Define stubs for environments without mpi4py + Request = SUM = MAX = MIN = IN_PLACE = IDENT = CONGRUENT = SIMILAR = UNEQUAL = None📝 Committable suggestion
🤖 Prompt for AI Agents