locally bind sim to simuPOP. As the importing is performed in a separate module, sim is not bound to simuPOP in the local namescope.
generate keys of P and W using a function, as it appears more than one place.
add missing import
implement writing results into CSV file