2 # Bash script to get some timing analysis
4 # Runtime for different t's
6 # number of runs to run in parallel
8 # NOTE: that this is not the same as running weaksim in parallel! For that you need to set OMP_NUM_THREADS appropriately (see README.txt)
9 # Note that setting OMP_NUM_THREADS>1 will lead to more pessimistic runtime analysis, due to parallelization overhead, though the runs should complete faster!
11 ## For the most accurate time analysis, run with
12 ## export OMP_NUM_THREADS=1
13 ## export OMP_PROC_BIND=false
14 #export OMP_NUM_THREADS=6
15 #export OMP_PROC_BIND=true
16 export OMP_NUM_THREADS=1
17 export OMP_PROC_BIND=false
20 deltasquared=`bc -l <<< $delta^2`
28 #for t in 2 4 8 #16 #32
31 #delta=`bc -l <<< 10^-$deltapower`
33 # alpha is the fraction of t supplemental states that we will take to keep the cost the same
34 # alpha = delta*xi^t/t
35 #echo "0.25*$delta*1.17^$t/$t"
36 #alpha=`bc -l <<< 0.25*$delta*1.17^$t/$t`
40 for (( i=1; i<=$numruns; i++ ))
42 # Generate two t-Pauli measurements
43 ./randominputcommutingHermitianPauli2 $t $t 1000 | head -n $[2*$t+4] > inputPauli_$[i].txt
46 for (( i=1; i<=$numruns; i++ ))
49 ./multipauli < inputPauli_$[i].txt | tail -1 | cut -d ' ' -f 1 > tmp_$[t]_exact_$[i].txt &
50 #seed=`od -A n -t d -N 4 /dev/urandom |tr -d ' '|tr -d '-'`
51 #./weaksim 0.001 0.25 2 $seed < inputPauli_$[i].txt | tail -1 | cut -d ' ' -f 3 > tmp_$[t]_exact_$[i].txt &
52 #./weaksim 0.01 0.25 2 $seed < inputPauli_$[i].txt | tail -1 | cut -d ' ' -f 3 > tmp_$[t]_exact_$[i].txt &
53 # minus one below so as not to count grep search job
54 numthreads=$[`ps -aux | grep multipauli | wc -l`-1]
55 #numthreads=$[`ps -aux | grep weaksim | wc -l`-1]
56 while [ $numthreads -gt $[$maxthreads-1] ]
59 numthreads=$[`ps -aux | grep multipauli | wc -l`-1]
60 #numthreads=$[`ps -aux | grep weaksim | wc -l`-1]
64 for (( i=1; i<=$numruns; i++ ))
72 seed=`od -A n -t d -N 4 /dev/urandom |tr -d ' '|tr -d '-'`
73 while (( $(echo "$approxerror > $deltasquared" |bc -l) )); do
74 echo "samplePrefactor=$samplePrefactor"
75 ( time ( ./weaksim $delta 0.25 0 $seed $samplePrefactor < inputPauli_$[i].txt >> tmp_$[t]_iid_$[i].txt ) ) 2> tmp_$[t]_iid_$[i]_timing.txt
77 exactanswer=`tail -1 tmp_$[t]_exact_$[i].txt`
78 approxanswer=`tail -1 tmp_$[t]_iid_$[i].txt | cut -d ' ' -f 3`
79 approxerror=`bc -l <<< "sqrt(($exactanswer-$approxanswer)^2)"`
81 samplePrefactor=`bc -l <<< "scale=4;($samplePrefactor*1.1)/1"`
83 samplePrefactor=`bc -l <<< "scale=4;($samplePrefactor/1.1)/1"`
84 echo "samplePrefactor used=$samplePrefactor"
85 echo $approxerror >> tmp_$[t]_iid_$[i]_error.txt
88 while (( $(echo "$approxcoherror > $deltasquared" |bc -l) )); do
89 echo "samplePrefactor=$samplePrefactor"
90 ( time ( ./weaksim $delta 0.25 2 $seed $samplePrefactor < inputPauli_$[i].txt >> tmp_$[t]_t_$[i].txt ) ) 2> tmp_$[t]_t_$[i]_timing.txt
92 exactanswer=`tail -1 tmp_$[t]_exact_$[i].txt`
93 approxcoherentanswer=`tail -1 tmp_$[t]_t_$[i].txt | cut -d ' ' -f 3`
94 approxcoherror=`bc -l <<< "sqrt(($exactanswer-$approxcoherentanswer)^2)"`
96 samplePrefactor=`bc -l <<< "scale=4;($samplePrefactor*1.1)/1"`
98 samplePrefactor=`bc -l <<< "scale=4;($samplePrefactor/1.1)/1"`
99 echo "samplePrefactor used=$samplePrefactor"
100 echo $approxcoherror >> tmp_$[t]_t_$[i]_error.txt
104 for (( i=1; i<=$numruns; i++ ))
106 rm tmp_$[t]_exact_$[i].txt;
107 rm tmp_$[t]_iid_$[i].txt;
108 rm tmp_$[t]_t_$[i].txt;
109 rm inputPauli_$[i].txt;
110 #echo "*******************" >> tmp_$[t]_iid.txt
111 #echo "*******************" >> tmp_$[t]_t.txt
114 echo "Longest runtime:" >> tmp_$[t]_iid.txt
115 cat tmp_$[t]_iid_[1-9]*_timing.txt | sort -n | tail -2 >> tmp_$[t]_iid.txt
116 rm tmp_$[t]_iid_[1-9]*_timing.txt
117 echo "Longest runtime:" >> tmp_$[t]_t.txt
118 cat tmp_$[t]_t_[1-9]*_timing.txt | sort -n | tail -2 >> tmp_$[t]_t.txt
119 rm tmp_$[t]_t_[1-9]*_timing.txt
120 echo "Largest error:" >> tmp_$[t]_iid.txt
121 cat tmp_$[t]_iid_[1-9]*_error.txt | sort -n | tail -1 >> tmp_$[t]_iid.txt
122 rm tmp_$[t]_iid_[1-9]*_error.txt
123 echo "Largest error:" >> tmp_$[t]_t.txt
124 cat tmp_$[t]_t_[1-9]*_error.txt | sort -n | tail -1 >> tmp_$[t]_t.txt
125 rm tmp_$[t]_t_[1-9]*_error.txt
126 echo "delta=$delta done!"