XActor: A Distributed Actor Programming Framework

Introduction

XActor is a framework for doing distributed computing in Python, using the actor model of programming.

In XActor any Python object can be an actor. Actors communicate with each other by sending messages. Messages in XActor are implemented as method invocations on the recipient object. The return value of the above method invocations (if any) are ignored by the XActor framework. If the recipient needs to send a response back to the sender, it needs to send new message to the sender.

XActor provides a simple classical actor framework, that is actors communicate with each other by sending messages. Current version of XActor doesn’t provide futures. XActor currently doesn’t implement exception chaining, where exceptions in the child actors are passed to parent actors. XActor uses the communicating event loop version of the Actor model, which means that all actors running in a single process share the inbox/message queue.

Current version of XActor is built on top of MPI (using mpi4py). Future versions may support other backends.

Installation

XActor depends on mpi4py which requires a MPI implementation and compiler tools be installed on the system.

Installing MPICH and mpi4py inside a conda environment

To create a new virtual environment with conda, have Anaconda/Miniconda setup on your system. Installation instructions for Anaconda can be found here. After installation of Anaconda/Miniconda execute the following commands:

$ conda create -n xactor -c conda-forge python=3 mpich mpi4py

The above command creates a new conda environment called xactor with python, mpich and mpi4py installed.

The following commands assume you are inside the above conda environment.

Installing XActor

One can use pip to install XActor for PyPI as follows:

$ pip install xactor

Dependencies of XActor (including mpi4py) will be installed as part of the above pip command.

To install xactor from source:

$ git clone https://github.com/NSSAC/xactor.git
$ cd xactor
$ pip install -e .

Hello World

The following code shows a simple “hello world” example using XActor.

#!/usr/bin/env python3
"""Hello World in XActor."""

import logging
import xactor as xa

# This is the class of the `Greeter` actor.
class Greeter:
    def greet(self, name):
        print("Greetings to %s from rank %s" % (name, xa.current_rank()))

# This the class of the `Main` actor.
class Main:
    def main(self):
        greeter_id = "greeter"

        # Create the actor proxy
        every_greeter = xa.ActorProxy(xa.EVERY_RANK, greeter_id)

        # Create the actors
        every_greeter.create_actor_(Greeter)

        # Send the greeters the greet message.
        every_greeter.greet("world")

        # We are done now.
        xa.stop()

def main():
    # Create the main actor
    xa.start("main", Main)

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    main()

To execute the above program save it as hello.py.

The following command executes the above program using two processes on the current machine:

$ mpiexec -n 2 python hello.py

Indices and tables