MCMC Sampler¶
Since Lenstool v8, the ZeroMQ library offers a mechanism to make Python communicate with Lenstool. This lightweight messaging inter-process library opens a communication channel to transfer several types of information, such as computing a likelihood given input parameters values between 0 and 1, write a line in the burning or in the bayes.dat file, get the number of free parameters in a Lenstool model.
In this implementation, Lenstool is considered as a server and the Python script is a client. There can be several Lenstool servers running in parallel, but only one Python client.
In the current implementation, the EMCEE Ensemble sampler has been chosen to test the method. However, any MCMC sampler adapted to communicate with Lenstool using the ZMQ library should work.
EMCEE single process¶
In the single process mode, Lenstool is started as a background process on the command line, and the Python EMCEE script is started afterwards. The communication url between Lenstool and the Python script must match.
In Lenstool, the URL is specified in the runmode section with the inverse keyword
inverse 6 ipc:///tmp/lenstool_azerty
In the EMCEE script, the URL is given as an argument to the initialisation function of the sm_client class
import sm_client sm = sm_client.client("ipc:///tmp/lenstool_azerty")
Here is a shell script to launch the whole thing
lenstool test.par -n & python emcee_EnsembleSampler.py
and the following should appear on the console
$> lenstool nfw.par -n & [1] 10517 $> You are running openMP version of lenstool with 24 threads You can change number of threads by set environment variable OMP_NUM_THREADS INFO: prepare arclet 3470/3470 INFO: Waiting for clients here url = ipc:///tmp/sm_lenstool.test $> python emcee_EnsembleSampler.py INFO: Connected to clients here url = ipc:///tmp/sm_lenstool.test INFO: Number of free parameters : 6 Choose initial values for the 100 walkers burning: 100 Mean acceptance fraction: 0.02 Autocorrelation time: 0.84 steps min/max prob= -6499.184082952672 -1440.5218257264935 Ask server to write in burnin.dat
and you can check using the top command, that everything runs fine
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 10517 ejullo 20 0 1514164 13416 3252 R 899,0 0,0 30:44.08 lenstool nfw.par -n 10528 ejullo 20 0 1290580 65672 23448 S 45,6 0,1 0:12.61 python emcee_EnsembleSampler.py
Be aware that in EMCEE the switch between burnin and sampling phases is arbitrary. Therefore, the chains in bayes.dat might not have fully converged. You should check with care their behaviour before estimating error bars and contours.
EMCEE pool process¶