Previous topic

Details

Next topic

mmf.objects

This Page

Asynchronous User InterfaceΒΆ

In this section we discuss a couple of techniques for interacting with the code. This includes a method for running the computation, and then connecting remotely to plot intermediate results, and possibly control the iterations.

<Incomplete>

A common operational pattern is to start a long-running computation, but to have some sort of interaction with that computation. The traditional solution is to print intermediate results – either to the screen or to a log file. This has many drawbacks, from producing reams of useless data (only the most recent values are typically needed), to slowing down the calculation (especially with plotting).

Here we explore a multi-threaded design pattern for providing interaction with the computation. The idea is to run the computation in one server process that allows clients to connect which can then inspect the process, displaying the current status, as well as possibly interacting with the process.

The server process contains a custom global dictionary-like interface object. The computation thread stores intermediate results in this dictionary, and (a) separate “connection” thread(s) in the server process transmit data from this dictionary to the connected clients (using the pickle protocol). A limited interface is provided for the clients to interact with the computational thread. For example, clients may pause the computational thread, ask it to terminate, or send it data.

At a minimum, the computation can just store intermediate results or convergence information in the interface dictionary. Clients can then look at this, but nothing else. A more complicated computation may periodically check with the interface dictionary to see if it should pause (for example, to allow a plotting client to display every iteration), or terminate, or to use data from the clients to modify its iteration.

The library controls termination and suspend signals in a careful manner to prevent conflicts etc.when multiple clients are connected. If the computation uses results from the clients to modify its progress, however, then it must be carefully structured:

-----------------------
| Connection Server   |
|                     |              ---------
|           /----- Channel 1 <---->  | GUI 1 |
|  ________/          |              =========
|  | Dict |------- Channel 2 <---->  | GUI 2 |
|  --------\          |              =========
|      |    \----- Channel 3 <---->  | GUI 3 |
|      |              |              ---------
| Computation         |
-----------------------