Merge branch 'master' of s3miclassical.com:strong_simulation_stabilizer_rank
[strong_simulation_stabilizer_rank.git] / test.bash
1 #!/bin/bash
2 # simple Bash script to check if 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 threshold=0.005 # absolute value threshold difference between computed and exact value
11
12 numruns=100
13
14 echo "Starting test of $numruns random $numqubits-Pauli expectation values..."
15 for i in $(seq 1 $numruns)
16 do
17 # sleep for 1 second for the pseudorandom number generator
18 sleep 1;a=$(stdbuf -oL ./randominputPauli $numqubits $numTgates > inputfullPauli.txt && ./strongsim < inputfullPauli.txt | tail -1)
19 b=$(stdbuf -oL ./multipauli < inputfullPauli.txt | tail -n1)
20 are=$(echo "$a" | cut -f 1 -d " " | cut -c 1-5);
21 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 " ");
22 bre=$(echo "$b" | cut -f 1 -d " " | cut -c 1-5);
23 bim=$(echo "$b" | cut -f 3 -d " " | cut -c 1-5);
24 c=$( printf 'scale=5; (%.5f)^2 + (%.5f)^2\n' "$are" "$aim" | bc -l )
25 echo "$i: $are $aimsign $aim and $bre $bimsign $bim"
26 rediff=$( printf 'sqrt((%f - %f)^2)\n' "$are" "$bre" | bc -l )
27 imdiff=$( printf 'sqrt((%f - %f)^2)\n' "$aim" "$bim" | bc -l )
28 if (( $(echo "$rediff < $threshold" |bc -l) )) && (( $(echo "$imdiff < $threshold" |bc -l) ))
29 then
30     if  (( $(echo "$bim < $threshold" |bc -l) )) || [ "$aimsign" == "$bimsign" ]
31     then
32         continue
33     else
34         echo "NOT EQUAL!"
35         exit
36     fi
37   else
38     echo "NOT EQUAL!"
39     exit
40 fi
41 done
42 echo "Test passed!"