final v1.0 files
[weak_simulation_stab_extent.git] / randomstabilizerstate_equatorial.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4 #include <string.h>
5 #include <math.h>
6
7 #include "matrix.h"
8
9 #include "randomstabilizerstate_equatorial.h"
10
11 #define ZEROTHRESHOLD (0.00000001)
12
13 // Note: Make sure you seed the random number generator before calling this!
14 // i.e. srand((unsigned)time(NULL));
15 void randomstabilizerstate_equatorial(int n, int* k, int** h, int*** G, int*** GBar, int* Q, int** D, int*** J)
16 {
17   // vector and matrix pointers should all be passed unallocated! (no freeing of memory performed)
18   
19   int d;
20
21   int i, j;
22
23   d = 0;
24   
25   *k = n; // we will get it to be k=n-d by calling shrinkstar d times below
26   
27   int info;
28   int numsingvals = -1;
29
30   *G = calloc(n, sizeof(int*)); *GBar = calloc(n, sizeof(int*));
31   *h = calloc(n, sizeof(int));
32
33   for(i=0; i<n; i++) {
34     (*G)[i] = calloc(n, sizeof(int));
35     (*GBar)[i] = calloc(n, sizeof(int));
36
37     (*G)[i][i] = 1;
38     (*GBar)[i][i] = 1;
39   }
40
41   // keep the equatorial states with h=0 since it shouldn't matter if they have equal amplitude across all computational basis states
42   for(i=0; i<n; i++)
43     (*h)[i] = 0;//rand()%2;
44
45   *Q = (rand()%8); // Q \in Z/8Z
46   
47   *D = calloc(*k, sizeof(int));
48   for(i=0; i<*k; i++)
49     (*D)[i] = (rand()%4)*2; // D_a \in {0, 2, 4, 6}
50
51   *J = calloc(*k, sizeof(int*));
52   for(i=0; i<*k; i++) {
53     (*J)[i] = calloc(*k, sizeof(int));
54     for(j=(i+1); j<*k; j++)
55       (*J)[i][j] = (rand()%2)*4; // J_{a,b} \in {0, 4} for a!=b
56     (*J)[i][i] = (2*(*D)[i])%8;
57   }
58   for(i=0; i<*k; i++) {
59     for(j=(i+1); j<*k; j++) {
60       (*J)[j][i] = (*J)[i][j];
61     }
62   }
63
64   return;
65
66 }