# Path: nested_sampling/_mc_walker.py
# class MCWalkerParallelWrapper(mp.Process):
#     """define a worker to do the monte carlo chain in a separate process
#     (using multiprocessing)
#     """
#     def __init__(self, conn, mc_runner):
#         mp.Process.__init__(self)
#         self.conn = conn
#         self.mc_runner = mc_runner
# 
#     def do_MC(self, x0, stepsize, Emax, energy, seed):
#         return self.mc_runner(x0, stepsize, Emax, energy, seed) 
#      
#     def run(self):
#         while 1:
#             message = self.conn.recv()
#             if message == "kill":
#                 return
#             elif message[0] == "do mc":
#                 x0, stepsize, Emax, energy, seed = message[1:]
#                 res = self.do_MC(x0, stepsize, Emax, energy, seed)
#                 self.conn.send(res)
#             else:
#                 print "error: unknown message: %s\n%s" % (self.name, message)


import random
import numpy as np
import sys
import copy
import Pyro4
import Pyro4.util
import multiprocessing as mp
import nested_sampling.utils.fix_multiprocessing
    import queue
    import Queue as queue
from itertools import izip
from nested_sampling._mc_walker import MCWalkerParallelWrapper
        self.iter_number = 0
        self.failed_mc_walks = 0
        self._mc_niter = 0 # total number of monte carlo iterations
        
        #pyro
        self.serializer= serializer
        self.dispatcher_URI = dispatcher_URI
                
        if self.verbose:
            print "nreplicas", len(self.replicas)
            sys.stdout.flush()

        
        if self.nproc > 1:
            if dispatcher_URI is not None:
                self._set_up_serializer()
            else:
                self._set_up_multiproc_parallelization()
        assert not (dispatcher_URI is None and self.nproc>1), "using only 1 core with active dispatcher" 
    
    #===========================================================================
    # multiprocessing functions for cpu locked parallelisation (on single node)
    #===========================================================================
    
    def _set_up_multiproc_parallelization(self):
        #initialize the parallel workers to do the Monte Carlo Walk
        self.connlist = []
        self.workerlist = []
        for _ in xrange(self.nproc):
            parent_conn, child_conn = mp.Pipe()

# Path: nested_sampling/_mc_walker.py
# class MCWalkerParallelWrapper(mp.Process):
#     """define a worker to do the monte carlo chain in a separate process
#     (using multiprocessing)
#     """
#     def __init__(self, conn, mc_runner):
#         mp.Process.__init__(self)
#         self.conn = conn
#         self.mc_runner = mc_runner
# 
#     def do_MC(self, x0, stepsize, Emax, energy, seed):
#         return self.mc_runner(x0, stepsize, Emax, energy, seed) 
#      
#     def run(self):
#         while 1:
#             message = self.conn.recv()
#             if message == "kill":
#                 return
#             elif message[0] == "do mc":
#                 x0, stepsize, Emax, energy, seed = message[1:]
#                 res = self.do_MC(x0, stepsize, Emax, energy, seed)
#                 self.conn.send(res)
#             else:
#                 print "error: unknown message: %s\n%s" % (self.name, message)


# Path: nested_sampling/_nested_sampling.py
import random
import numpy as np
import sys
import copy
import Pyro4
import Pyro4.util
import multiprocessing as mp
import nested_sampling.utils.fix_multiprocessing
    import queue
    import Queue as queue
from itertools import izip
from nested_sampling._mc_walker import MCWalkerParallelWrapper

        self.iter_number = 0
        self.failed_mc_walks = 0
        self._mc_niter = 0 # total number of monte carlo iterations
        
        #pyro
        self.serializer= serializer
        self.dispatcher_URI = dispatcher_URI
                
        if self.verbose:
            print "nreplicas", len(self.replicas)
            sys.stdout.flush()

        
        if self.nproc > 1:
            if dispatcher_URI is not None:
                self._set_up_serializer()
            else:
                self._set_up_multiproc_parallelization()
        assert not (dispatcher_URI is None and self.nproc>1), "using only 1 core with active dispatcher" 
    
    #===========================================================================
    # multiprocessing functions for cpu locked parallelisation (on single node)
    #===========================================================================
    
    def _set_up_multiproc_parallelization(self):
        #initialize the parallel workers to do the Monte Carlo Walk
        self.connlist = []
        self.workerlist = []
        for _ in xrange(self.nproc):
            parent_conn, child_conn = mp.Pipe()

            worker = MCWalkerParallelWrapper(child_conn, self.mc_walker)