Project

General

Profile

MAUSOnlineReconstructionOverview » History » Revision 5

Revision 4 (Jackson, Mike, 15 March 2012 13:50) → Revision 5/14 (Jackson, Mike, 15 March 2012 15:39)

h1. Online Reconstruction Overview 

 "Manchego" is the online reconstruction components of MAUS. Manchego stands for "Manchego is Analysis No-nonsense Controlroom Helping Existentially Guided Onlineness". 

 "Overview talk":https://micewww.pp.rl.ac.uk/attachments/816/20120209-MAUS-SSI-Status.ppt - 09/02/12 - contains a summary of the main concepts and architecture. 

 h2. Parallel transformation of spills 

 Each spill is transformed, by which we mean the data within the spill is analysed in various ways and derived data added to the spill. Each type of analysis is carried out by a "transformer". Each spill is independant spills can be transformed in parallel. 

 Celery, an distributed asynchronous task queue for Python is used to support parallel transformation of spills. Celery uses RabbitMQ as a message broker to handle communications between clients and Celery worker nodes. 

 A Celery worker executes one or more sub-processes each of which execute tasks, in the case of MAUS the transforms. By default Celery spawns N sub-processes where N is the number of CPUs on the host, but N can be explicitly set by a user. Each sub-process can execute tasks. 

 Multiple Celery workers can be deployed, each of which with one or more sub-processes. Celery therefore supports highly-parallelisable applications. 

 MAUS configures Celery as follows: 

 * The framework uses reflection to get the names of the transforms the user wants to use e.g. @MapPyGroup(MapPyBeamMaker, MapCppSimulation, MapCppTrackerDigitization)@. This is termed a "transform specification". 
 * A Celery broadcast is invoked, passing the transform specification, the MAUS configuration and a configuration ID (e.g. the client's process ID). 
 * Celery broadcasts are received by all Celery workers registered with the RabbitMQ message broker. 
 * On receipt of the broadcast, each Celery worker: 
 ** Checks that the client's MAUS version is the same as the workers. If not then an error is returned to the client. 
 ** Forces the transform specification down to each sub-process. 
 ** Waits for the sub-processes to confirm receipt. 
 ** If all sub-processes update correctly then a success message is returned to the client. 
 ** If any sub-process fails to update then a failure message, with details, is returned to the client. 
 ** Each Celery sub-process: 
 *** Invokes @death@ on the existing transforms, to allow for clean-up to be done. 
 *** Updates their configuration to be the one received. 
 *** Creates new transforms as specified in the transform configuration. 
 *** Invokes @birth@ on these with the new configuration. 
 *** Confirms with the Celery worker that the update has been done. 
 ** Celery workers and sub-processes catch any exceptions they can to avoid the sub-processes or, more seriously, the Celery worker itself from crashing in an unexpected way. 

 MAUS uses Celery as follows: 

 * A Celery client-side proxy is used to submit the spill to Celery. It gets an object which it can use to poll the status of the "job". 
 * The client-side proxy forwards the spill to RabbitMQ. 
 * RabbitMQ forwards this to a Celery worker. 
 * The Celery worker picks a sub-process. 
 * The sub-process executes the current transform on the spill. 
 * The result spill is returned to the Celery worker and there back to RabbitMQ. 
 * The MAUS framework regularly polls the status of the transform job until it's status is successful, in which case the result spill is available, or failed, in which case the error is recorded but execution continues. 

 h2. Document-oriented database 

 After spills have been transformed, a document-oriented database, MongoDB, is used to store the transformed spills. The database represents the interface between the input-transform and merge-output phases of a spill processing workflow. 

 Use of a database allows many merge-output clients to use the same data. 

 The MAUS framework is given the name of a collection of spills and reads these in order of the dates and times they were added to the database. It passes each spill to a merger and then takes the output of the merger and passes it to an outputter. 

 h2. Histogram mergers 


 Aggregate spill data and update histogram 
 Super-classes for graph packages 
 Matplotlib – ReducePyMatplotlibHistogram 
 PyROOT – ReducePyROOTHistogram 
 Examples: 
 ReducePyHistogramTDCADCCounts 
 ReducePyTOFPlot (Durga) 
 Mergers do not display the histograms 

 Configuration options 
 Image type e.g. EPS, PNG, JPG,… 
 Refresh rate e.g. output every spill, every N spills 
 Auto-number image tag 
 Output JSON document 
 Base64-encoded image data 
 Image tag used for a file name 
 Meta-data e.g. English description 

 Output images 


 OutputPyImage 
 Configuration options 
 Filename prefix 
 Directory 
 Extract and save base64-encoded image data 
 Image file e.g. EPS, PNG, JPG,… 



 Django 
 Python web framework 
 Refresh every 5 seconds 
 Currently using Django test web server 
 Serve up images from a directory 
 “API” between online reconstruction framework and web front-end is just this directory 
 Can run web-front end anywhere so long as images are made available “somehow” 




 h2. Run numbers 

 Run numbers are assumed to be as follows: 

 * -N : Monte Carlo simulation of run N 
 * 0 : pure Monte Carlo simulation 
 * +N : run N 

 h2. Transforming spills from an input stream (Input-Transform) 

 This is the algorithm used to transform spills from an input stream: 
 <pre> 
 CLEAR document store 
 run_number = None 
 WHILE an input spill is available 
   GET next spill 
   IF spill does not have a run number 
     # Assume pure MC 
     spill_run_number = 0 
   IF (spill_run_number != run_number) 
     # We've changed run. 
     IF spill is NOT a start_of_run spill 
       WARN user of missing start_of_run spill 
     WAIT for current Celery tasks to complete 
       WRITE result spills to document store 
     run_number = spill_run_number 
     CONFIGURE Celery by DEATHing current transforms and BIRTHing new transforms 
   TRANSFORM spill using Celery 
   WRITE result spill to document store 
  DEATH Celery worker transforms 
 </pre> 
 If there is no initial @start_of_run@ spill (or no @spill_num@ in the spills) in the input stream (as can occur when using @simple_histogram_example.py@ or @simulate_mice.py@) then spill_run_number will be 0, run_number will be None and a Celery configuration will be done before the first spill needs to be transformed.  

 Spills are inserted into the document store in the order of their return from Celery workers. This may not be in synch with the order in which they were originally read from the input stream. 

 h2. Merging spills and passing results to an output stream (Merge-Output) 

 This is the algorithm used to merge spills and pass the results to an output stream: 
 <pre> 
 run_number = None 
 end_of_run = None 
 is_birthed = FALSE 
 last_time = 01/01/1970 
 WHILE TRUE 
   READ spills added since last time from document store 
   IF spill IS "end_of_run" 
     end_of_run = spill 
   IF spill_run_number != run_number 
     IF is_birthed 
       IF end_of_run == None 
           end_of_run = {"daq_event_type":"end_of_run", "run_num":run_number} 
       Send end_of_run to merger 
       DEATH merger and outputter 
     BIRTH merger and outputter 
     run_number = spill_run_number 
     end_of_run = None 
     is_birthed = TRUE 
   MERGE and OUTPUT spill 
 Send END_OF_RUN block to merger 
 DEATH merger and outputter 
 </pre> 

 The Input-Transform policy of waiting for the processing of spills from a run to complete before starting processing spills from a new run means that all spills from run N-1 are guaranteed to have a time stamp < spills from run N. 

 is_birthed is used to ensure that there is no BIRTH-DEATH-BIRTH redundancy on receipt of the first spill. 

 h2. Document store 

 Spills are stored in documents in a collection in the document store.  

 Documents are of form @{"_id":ID, "date":DATE, "doc":SPILL}@ where: 

 * ID: index of this document in the chain of those successfuly transformed. It has no significance beyond being unique in an execution of Input-Transform loop below. It is not equal to the spill_num (Python @string@) 
 * DATE: date and time to the milli-second noting when the document was added (Python @timestamp@) 
 * DOC: spill document. (Python @string@ holding a valid JSON document) 

 h3. Collection names 

 For Input-Transform, 

 * If configuration parameter @doc_collection_name@ is @None@, @""@, or @auto@ then @HOSTNAME_PID@, where @HOSTNAME@ is the machine name and @PID@ the process ID, is used. 
 * Otherwise the value of @doc_collection_name@ is used. 
 * @doc_collection_name@ has default value @spills@. 

 For Merge-Output, 

 * If configuration parameter @doc_collection_name@ is @None@, @""@, or undefined then an error is raised. 
 * Otherwise the value of @doc_collection_name@ is used. 

 h2. Miscellaneous 

 * Currently Celery timeouts are not used, transforming a spill takes as long as it takes. 
 * Celery task retries on failure option is not used. If the transformation of a spill fails first time it can't be expected to succeed on a retry. 
 * If memory leaks arise, e.g. from C++ code, look at Celery rate limitss, which allow the time or number of tasks before sub-process is killed and respawned, to be defined. Soft rate limits would allow @death@ to be run on the transforms first.