Commit 54519e79 authored by Matthieu Tristram's avatar Matthieu Tristram
Browse files

Update version used for Mnu paper

parent 667402b0
#!/bin/env bash
if [ -z "$NCHAINS" ] ; then
NCHAINS=4
fi
if [ -z "$NCORES" ] ; then
NCORES=8
fi
myexec=$CAMELROOT/$CMTCONFIG/mcmc
if [ $# -ne 2 ]; then
echo "usage: parFile mcsetup.txt"
exit
npar=1
if [ $# -lt 1 ]; then
echo "runMCMC.sh parFile"
echo " [Nsamples=500000]"
echo " [Nchain=4]"
echo " [Ncore=8]"
echo " [queue=mc_long]"
echo " [project=P_planck]"
echo ""
exit
fi
parFile=`readlink -f $1`
Nsample=500000
Nchain=4
Ncore=8
queue=mc_long
project=P_planck
while(( $# > "$npar")); do
((npar = npar + 1))
eval riri=\$$npar
vals=(${riri//=/ })
var=${vals[0]}
eval old=\$${vals[0]}
echo ${vals[0]}=${vals[1]} "( old:"$old")"
if [ -z "$old" ]; then
echo "wrong parameter"
exit
fi
eval ${vals[0]}=${vals[1]}
done
if [ -z "$CLIKDIR" ] ; then
echo "miss CLIKDIR"
exit
echo "miss CLIKDIR"
exit
fi
if ! [ -f $myexec ] ; then
echo "missing exec"
exit
echo "missing exec"
exit
fi
localexec=`basename $myexec`
file=$1
mcsetup=$(readlink -e $2)
parFile=$(readlink -e $file)
parbase=$(basename $parFile)
dirout=${parbase%".par"}_"MC"
zeroot=$PWD/$dirout
if ! [ -f $parFile ] ; then
echo "wrong parFile $parFile"
exit
fi
#cat $parFile
dirpar=`dirname $parFile`
parbase=`basename $parFile`
zename=${parbase%".par"}
echo $dirpar
echo $parFile
ndim=`awk '$1=="par"{n++}; END {print n}' $parFile`
if ! [ -f $parFile ] ; then
echo "wrong parFile $parFile"
#MCMC proposal
cov=${parbase%".par"}.cov
if ! [ -f $dirpar/$cov ] ; then
echo "$dirpar/$cov"
echo "no covariance matrix found ndim=$ndim"
exit
fi
echo `readlink -f $cov`
#create output directory
zeroot=$PWD/${zename}_MC
if [ -d "$zeroot" ] ; then
echo "directory $zeroot exists: still want to run? (y/n)"
read answer
if [ $answer != 'y' ] ; then
echo "exiting"
exit 1
fi
echo "directory $zeroot exists: still want to run? (y/N)"
read answer
if [ "$answer" != 'y' ] ; then
exit 1
fi
else
mkdir $zeroot
fi
#
mkdir $zeroot
cd $zeroot
#MCMC mandatory stuff
#read mcsetup
tmp=`mktemp`
grep proposal_cov $mcsetup >> $tmp
source $tmp
#checks on covmat
if [ -z "${proposal_cov}" ] ; then
echo "missing proposal_cov in mc_setup"
exit 1
fi
if [ ! -f ${proposal_cov} ] ; then
echo "covariance matrix $proposal_cov does not exist"
exit 1
fi
#check sizes
nlines=`wc -l ${proposal_cov} | cut -d " " -f 1`
ndim=`awk '$1=="par"{n++}; END {print n}' $parFile`
echo "ndim=$ndim nlines=$nlines"
if [ $ndim -ne $nlines ] ; then
echo "covariance matrix not compatible in size with parFile"
exit 1
fi
#generate parbase
#enleve precision pour MCMC
grep -v precision $dirpar/$parbase > $parbase
#cp $dirpar/$parbase .
cp $dirpar/$cov .
#setup MCMC
cat > mc_setup <<EOF
dim=$ndim
algo=ada
length=$Nsample
proposal_cov=./$cov
ts=10000
t0=2000
scale=0.001
do_move=false
EOF
#cat mc_setup
cat mc_setup >> $parbase
rm -f mc_setup
echo "**************************************"
cat $mcsetup
echo "**************************************"
cat > zerun.sh <<eof
echo "running on : \$(uname -a)"
export PYTHONPATH=${PICO_CODE}
export OMP_NUM_THREADS=$NCORES
export OMP_NUM_THREADS=$Ncore
cd \$TMPDIR
cp $myexec .
#enleve precision pour MCMC
grep -v precision $parFile > $parbase
cat $mcsetup >> $parbase
#each job from the array will have different seeds but is repoductible.
cp $zeroot/$parbase mcmc\${SGE_TASK_ID}.par
cp $zeroot/$cov .
RANDOM=\${SGE_TASK_ID}
echo "seed=\$RANDOM" >> $parbase
echo "seedU=\$RANDOM" >> $parbase
echo "seed=\$RANDOM" >> mcmc\${SGE_TASK_ID}.par
cp $parbase $PWD/camel.par
cp mcmc\${SGE_TASK_ID}.par $PWD/
./$localexec $parbase $PWD/samples\${SGE_TASK_ID}.txt
./$localexec mcmc\${SGE_TASK_ID}.par $PWD/samples\${SGE_TASK_ID}.txt
cp ar_vs_length.txt $PWD/ar_vs_length\${SGE_TASK_ID}.txt
cp scale_vs_length.txt $PWD/scale_vs_length\${SGE_TASK_ID}.txt
......@@ -113,24 +128,19 @@ cp corr.txt $PWD/corr\${SGE_TASK_ID}.txt
qstat -j \${JOB_ID} -nenv
eof
echo "**************************************"
#cat zerun.sh
#default qsub command (you may override)
if [ -z "${QSUB_CMD}" ] ; then
QSUB_CMD="qsub -P P_$GROUP -pe multicores $NCORES -q mc_longlasting -R y -j y -l sps=1"
fi
jobsub="${QSUB_CMD} -o $PWD -N $(basename $zeroot) -t 1-$NCHAINS zerun.sh"
echo "about to run : $jobsub"
echo "OK? [y/n]"
echo "queue : $queue"
echo "nchain : $Nchain"
echo "nsamples: $Nsample"
echo "OK? [y/N]"
read answer
if [ $answer != 'y' ] ; then
echo "exiting"
exit 1
if [ "$answer" != 'y' ]; then
exit 1
fi
eval $jobsub
QSUB_ARGS="-l sps=1 -R y -j y -o $PWD -e $PWD"
QUEUE_ARGS="-P $project -pe multicores $Ncore"
qsub ${QUEUE_ARGS} -q $queue ${QSUB_ARGS} -t 1-$Nchain -N $zename zerun.sh
cd - > /dev/null
echo "output will be in $zeroot"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment