MockMPI


NameMockMPI JSON
Version 0.8.1 PyPI version JSON
download
home_pagehttps://github.com/rmjarvis/MockMPI
SummaryA tool for mocking mpi4py for testing
upload_time2022-03-25 19:19:05
maintainer
docs_urlNone
authorMike Jarvis and collaborators
requires_python>=3.5
license
keywords mpi development unittesting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Overview
--------

Message Passing Interface (MPI) is an approach to parallelism based on explicit communication between processes.  Python bindings to it are available via mpi4py.

Testing code that uses MPI can be awkward.  This package provides a pure-python mock MPI communicator that can be used to do so, without requiring actual MPI.  It uses multiprocessing to
start processes and makes a mocked Communicator (comm) object that takes the place of 
mpi4py.MPI.COMM_WORLD.


Installation
------------

The code is pure python; you can install it with:

```
    pip install mockmpi
```

Usage
-----

Define a function that holds the code that should work in an MPI session:

```
    def function_to_test(comm):
        ...
```

If this were a real MPI session, it should work as:

```
    import mpi4py
    comm = MPI.COMM_WORLD
    function_to_test(comm)
```

which you would run with `mpiexec -n nproc ...`

To test the code without MPI, import mock_mpiexec from this package and run:

```
    mock_mpiexec(nproc, function_to_test)
```

Extra Arguments
---------------

You can also supply additional named or positional arguments to `mock_mpiexec` and they will be
passed to `function_to_test`:

```
    mock_mpiexec(nproc, function_to_test, 1, 2, 3, a='b')
```

mimics:

```
    import mpi4py
    comm = MPI.COMM_WORLD
    function_to_test(comm, 1, 2, 3, a='b')

```

This works if the arguments can be pickled (true for most basic python and numpy types).

Caveats
-------

1. This runs on python 3.5+
2. Absolutely no attention was paid to making this efficient.  This code
   is designed to be used for unit testing, not production.
3. Only the IntraComm object is currently mocked, not the many other features
   like operators, futures, topologies, windows, spawning ... 
3. Many methods are currently missing.  Only those below are currently implemented.  Others will raise ``NotImplementedError``
 - Get_rank
 - Get_size
 - Barrier
 - send - unlike real MPI this is non-blocking
 - Send - also non-blocking
 - recv
 - Recv
 - barrier
 - bcast
 - Bcast
 - scatter
 - reduce (only with the default sum operation)
 - Reduce (only with the default sum operation)
 - allreduce
 - Allreduce
 - alltoall
 - gather

Contributions and License
-------------------------

We would greatly welcome contributions, especially to fill in missing features.

The code and any contributions are released under a BSD 2-clause license (see the LICENSE file).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rmjarvis/MockMPI",
    "name": "MockMPI",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "MPI,development,unittesting",
    "author": "Mike Jarvis and collaborators",
    "author_email": "michael@jarvis.net",
    "download_url": "https://files.pythonhosted.org/packages/48/99/27611735b8b9059e0361a9ecd6cba893bf6fb17a516d1cc0f4cbcd6ddd60/MockMPI-0.8.1.tar.gz",
    "platform": null,
    "description": "Overview\n--------\n\nMessage Passing Interface (MPI) is an approach to parallelism based on explicit communication between processes.  Python bindings to it are available via mpi4py.\n\nTesting code that uses MPI can be awkward.  This package provides a pure-python mock MPI communicator that can be used to do so, without requiring actual MPI.  It uses multiprocessing to\nstart processes and makes a mocked Communicator (comm) object that takes the place of \nmpi4py.MPI.COMM_WORLD.\n\n\nInstallation\n------------\n\nThe code is pure python; you can install it with:\n\n```\n    pip install mockmpi\n```\n\nUsage\n-----\n\nDefine a function that holds the code that should work in an MPI session:\n\n```\n    def function_to_test(comm):\n        ...\n```\n\nIf this were a real MPI session, it should work as:\n\n```\n    import mpi4py\n    comm = MPI.COMM_WORLD\n    function_to_test(comm)\n```\n\nwhich you would run with `mpiexec -n nproc ...`\n\nTo test the code without MPI, import mock_mpiexec from this package and run:\n\n```\n    mock_mpiexec(nproc, function_to_test)\n```\n\nExtra Arguments\n---------------\n\nYou can also supply additional named or positional arguments to `mock_mpiexec` and they will be\npassed to `function_to_test`:\n\n```\n    mock_mpiexec(nproc, function_to_test, 1, 2, 3, a='b')\n```\n\nmimics:\n\n```\n    import mpi4py\n    comm = MPI.COMM_WORLD\n    function_to_test(comm, 1, 2, 3, a='b')\n\n```\n\nThis works if the arguments can be pickled (true for most basic python and numpy types).\n\nCaveats\n-------\n\n1. This runs on python 3.5+\n2. Absolutely no attention was paid to making this efficient.  This code\n   is designed to be used for unit testing, not production.\n3. Only the IntraComm object is currently mocked, not the many other features\n   like operators, futures, topologies, windows, spawning ... \n3. Many methods are currently missing.  Only those below are currently implemented.  Others will raise ``NotImplementedError``\n - Get_rank\n - Get_size\n - Barrier\n - send - unlike real MPI this is non-blocking\n - Send - also non-blocking\n - recv\n - Recv\n - barrier\n - bcast\n - Bcast\n - scatter\n - reduce (only with the default sum operation)\n - Reduce (only with the default sum operation)\n - allreduce\n - Allreduce\n - alltoall\n - gather\n\nContributions and License\n-------------------------\n\nWe would greatly welcome contributions, especially to fill in missing features.\n\nThe code and any contributions are released under a BSD 2-clause license (see the LICENSE file).\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A tool for mocking mpi4py for testing",
    "version": "0.8.1",
    "project_urls": {
        "Download": "https://github.com/rmjarvis/MockMPI/releases/tag/v0.8.1.zip",
        "Homepage": "https://github.com/rmjarvis/MockMPI"
    },
    "split_keywords": [
        "mpi",
        "development",
        "unittesting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "489927611735b8b9059e0361a9ecd6cba893bf6fb17a516d1cc0f4cbcd6ddd60",
                "md5": "57bf62b51a3880c1b08715945c349e49",
                "sha256": "ae333fdb2076175b459b9d1b81bfe5f6e44a577e7adde39ace0d7abd5b678e5d"
            },
            "downloads": -1,
            "filename": "MockMPI-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "57bf62b51a3880c1b08715945c349e49",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 8713,
            "upload_time": "2022-03-25T19:19:05",
            "upload_time_iso_8601": "2022-03-25T19:19:05.506887Z",
            "url": "https://files.pythonhosted.org/packages/48/99/27611735b8b9059e0361a9ecd6cba893bf6fb17a516d1cc0f4cbcd6ddd60/MockMPI-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-25 19:19:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rmjarvis",
    "github_project": "MockMPI",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mockmpi"
}
        
Elapsed time: 0.25508s