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

Better error reporting in python context interface #1732

Merged
merged 6 commits into from
Oct 29, 2021

Conversation

bcumming
Copy link
Member

Give clear error messages when a user attempts to initialise a Python context with GPU or MPI
when Arbor has not been configured with support for the respective hardware feature.

  • update Python wrapper
  • update docs.

Fixes #1646.

Comment on lines -177 to -189
.. function:: context(threads, gpu_id)
:noindex:

Create a context that uses a set number of :attr:`threads` and the GPU with id :attr:`gpu_id`.

.. attribute:: threads

The number of threads available locally for execution, 1 by default.

.. attribute:: gpu_id

The identifier of the GPU to use, ``None`` by default.
Must be ``None``, or a non-negative integer.
Copy link
Collaborator

@Helveg Helveg Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this go though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was removed, and replaced with context(threads=1, gpu_id=None, mpi=None)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now a single constructor, that is available regardless of which features were enabled at compile time.
If the user requests a disabled feature, i.e. GPU or MPI, an exception with a (hopefully) helpful message is thrown.

"Construct a local context with arguments:\n"
" threads: The number of threads available locally for execution, 1 by default.\n"
" gpu_id: The identifier of the GPU to use, None by default.\n")
[](proc_allocation_shim alloc, pybind11::object mpi){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would roll the constructor from proc_allocation_shim (sans MPI) into this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are now two context constructors that take a proc_allocation_shim, one takes an MPI object in addition. Line 100 and line 140. This could be rolled into one constructor, same as the constructor you modified.

Copy link
Member Author

@bcumming bcumming Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two constructors in this version:

  1. a constructor where the user can list the hardware (threads, gpu and mpi), with default values when they do not explicitly set one (i.e. if a gpu is not requested, the default is not to use a GPU).
  2. a constructor that takes a proc_allocation and an (optional) mpi context.

Would you like to change this?

Copy link
Contributor

@brenthuisman brenthuisman Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 :) The one on line 100 is very short. But I see that I'm not reading correctly either: you can simply delete the one on line 100.

Copy link
Collaborator

@Helveg Helveg Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling just arbor.context() will still work right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there were 4! They have been removed.

@@ -144,11 +144,13 @@ The Python wrapper provides an API for:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the top of this page, I would like a reminder that the availability of certain features (MPI, GPU) depend on how Arbor was built.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stated at the top of the page: the first code sample shows how to use arbor.__config__ to check for features.
I have added two sentences a the very to further clarify this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make it a note at the actual top of the page, even before the API documentation: that some options depend on compile time configuration. Repeating this here (who reads the Build and Install page after all) is not excessive.

@@ -8,6 +8,9 @@ Arbor provides two ways for working with hardware resources:
* *Prescribe* the hardware resources and their contexts for use in Arbor simulations.
* *Query* available hardware resources (e.g. the number of available GPUs), and initializing MPI.

Note that to utilize some hardware features Arbor must be built and installed with the feature enabled, for example MPI or a GPU.
Please refer to the :ref:`kind <modelcellkind>` for informatioon on how to enable hardware support.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:ref:`kind <modelcellkind>` for informatioon -> :ref:`in_build_install` for information

@brenthuisman brenthuisman merged commit d4e65e4 into arbor-sim:master Oct 29, 2021
bcumming added a commit to bcumming/arbor that referenced this pull request Dec 3, 2021
@bcumming bcumming deleted the fix/python-context-ctor branch February 22, 2022 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.context() arg error does not mention lack of MPI support
3 participants