deleted incorrect var numPaulis and replaced with numrandomsteps in test2 bash script
[strong_simulation_stabilizer_rank.git] / randominputcommutingHermitianPauli.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4 #include <string.h>
5
6 // order of matrix elements is [row][column]!!!
7
8 /*********************************************************/
9 /* Generates random Hermitian Paulis that are commuting! */
10 /*********************************************************/
11 int main( int argc, char *argv[])
12 {
13
14   if(argc != 3) {
15     printf("randominputPauli arguments: \"number of qubits\" \"number of T gates\"\n");
16     exit(0);
17   }
18   
19   int N = atoi(argv[1]);              // number of qubits
20   int T = atoi(argv[2]);              // number of T gate magic states (set to the first 'K' of the 'N' qubits -- the rest are set to the '0' computational basis state)
21
22   printf("%d\n", N);
23   printf("%d\n", T);
24
25   int Pauli[N][N];
26   srand((unsigned)time(NULL));
27
28
29   int i, j, k;
30
31   int sign = 1;
32   
33   for(i=0; i<N; i++) {
34     
35     for(j=0; j<N; j++) {
36       Pauli[i][j] = rand()%3; // don't generate Y's (which is represented by '3'; I=0, Z=1, X=2, Y=3)
37     }
38     // see if the new Paulis commute with all the previous ones
39     for(j=0; j<i; j++) {
40       sign = 1;
41       for(k=0; k<N; k++) {
42         if(Pauli[j][k] != Pauli[i][k] && Pauli[j][k] != 0 && Pauli[i][k] != 0) // if the Paulis are different and neither is equal to the identity then they anticommute
43           sign *= -1;
44       }
45       if(sign == -1) {
46         i--; // try generating the ith set of Paulis again to get a commuting one
47         break; // break out of the loop over j
48       }
49     }
50     if(sign == 1) { // found a commuting set!
51       printf("%d\n", (rand()%2)*2); // omega must be 0 or 2 (since it is the power of i: i^omega)
52       for(j=0; j<N; j++) {
53         printf("%d %d %d %d\n", Pauli[i][j]==0, Pauli[i][j]==1, Pauli[i][j]==2, Pauli[i][j]==3);
54       }
55     }
56   }
57
58 }