deleted incorrect var numPaulis and replaced with numrandomsteps in test2 bash script
[strong_simulation_stabilizer_rank.git] / test2.bash
1 #!/bin/bash
2 # simple Bash diagnostic script to check if non-zero relative error stabilizer rank code works
3
4 # choose the number of qubits and T gates on those qubits
5 # NOTE: numqubits must be a multiple of your gauss sum tensor multiple!
6 # e.g. if you test gausssums_multipleof6 then numqubits=6*n for some integer n
7 numqubits=6
8 numTgates=6
9
10 numrandomsteps=1000000 #10000 # number of random steps when generating Paulis
11
12 # number of random stabilizer states to use for stochastic sampling
13 numsamples=1000
14
15 # since this is a stochastic calculation, we need a threshold to determine when the calculation is withing close enough relative error 
16 threshold=0.005 # absolute value threshold difference between computed and exact value
17
18 numruns=100
19
20 echo "Starting test of $numruns random $numqubits-Pauli expectation values calculated by averaging $numsamples random stabilizer states and comparing to threshold $threshold..."
21
22 for i in $(seq 1 $numruns)
23 do
24 # sleep for 1 second for the pseudorandom number generator
25 sleep 1; a=$(stdbuf -oL ./randominputcommutingHermitianPauli2 $numqubits $numTgates $numrandomsteps > inputPauli.txt && ./strongsim_relerr $numsamples < inputPauli.txt | tail -1)
26 b=$(stdbuf -oL ./multipauli < inputPauli.txt | tail -n1)
27 are=$(echo "$a" | cut -f 1 -d " " | cut -c 1-5);
28 aim=$(echo "$a" | cut -f 3 -d " " | cut -c 1-5); aimsign=$(echo $a | cut -f 2 -d " "); bimsign=$(echo $b | cut -f 2 -d " ");
29 bre=$(echo "$b" | cut -f 1 -d " " | cut -c 1-5);
30 bim=$(echo "$b" | cut -f 3 -d " " | cut -c 1-5); echo "$i: $are $aimsign $aim and $bre $bimsign $bim"
31 rediff=$( printf 'sqrt((%f - %f)^2)\n' "$are" "$bre" | bc -l )
32 imdiff=$( printf 'sqrt((%f - %f)^2)\n' "$aim" "$bim" | bc -l )
33 if (( $(echo "$rediff < $threshold" |bc -l) )) && (( $(echo "$imdiff < $threshold" |bc -l) ))
34 then
35     if (( $(echo "$bim < $threshold" |bc -l) )) || [ "$aimsign" == "$bimsign" ]
36     then
37         continue
38     else
39         echo "NOT EQUAL!"
40         exit
41     fi
42   else
43     echo "NOT EQUAL!"
44     exit
45 fi
46 done
47 echo "Test passed!"