X-Git-Url: https://s3miclassical.com/gitweb/?p=strong_simulation_stabilizer_rank.git;a=blobdiff_plain;f=measurepauli.c;fp=measurepauli.c;h=202d3fbe0f5e2846d4ab85ab0d6854639628d490;hp=0000000000000000000000000000000000000000;hb=f36d60f8c85e0879a7d2b52e816638d2b4fdf86a;hpb=a85d4d567fc589503c5e263e1520295c8d433a45 diff --git a/measurepauli.c b/measurepauli.c new file mode 100644 index 0000000..202d3fb --- /dev/null +++ b/measurepauli.c @@ -0,0 +1,165 @@ +#include +#include +#include +#include + +#include "matrix.h" +#include "shrink.h" +#include "extend.h" +#include "measurepauli.h" + + +/**************************************************************************** + * Takes a stabilizer state (n, k, h, G, GBar, Q, D, J) and a Pauli operator + * (m, X, Z) and returns the norm (abs. value) of the projected state. + * If it is non-zero,then it transforms the stabilizer state to the + * projected state. + ****************************************************************************/ +// This assumes the order Z-first X-second order when operator is read from left-to-right! +double measurepauli(int n, int *k, int *h, int **G, int **GBar, int *Q, int **D, int ***J, int m, int *X, int *Z) { + // Note that X is 'xi' and Z is 'zeta' in Bravyi et al. 'xi' and 'zeta' are instead used for the vectors with elements xi_a and zeta_a. + // Note that D and J must be dynamically allocated arrays as they can change size in this function. This is also the reason that we need their base pointer and are greater in pointer depth by one. + + int a, b; + + int omega; + + int *xi, *zeta, *Xprime; + xi = calloc(*k, sizeof(int)); + zeta = calloc(*k, sizeof(int)); + Xprime = calloc(n, sizeof(int)); + + for(a=0; a<*k; a++) { + xi[a] = dotProductMod(GBar[a], X, n, 2); + zeta[a] = dotProductMod(G[a], Z, n, 2); + } + + for(a=0; a 0) + free(*D); + *D = calloc(*k, sizeof(int)); + for(a=0; a<*k; a++) { + (*D)[a] = newD[a]; + } + free(newD); + + int **tmpMatrix = calloc(*k, sizeof(int*)); + for(a=0; a<(*k-1); a++) { + tmpMatrix[a] = calloc(*k, sizeof(int)); + for(b=0; b<(*k-1); b++) { + tmpMatrix[a][b] = (*J)[a][b]; + } + } + tmpMatrix[*k-1] = calloc(*k, sizeof(int)); + for(a=0; a<(*k-1); a++) { + tmpMatrix[*k-1][a] = 4*zeta[a]; + tmpMatrix[a][*k-1] = 4*zeta[a]; + } + tmpMatrix[*k-1][*k-1] = (4*m)%8; + if(*k-1 > 0) + deallocate_mem(J, *k-1); + //for(a=0; a<(*k-1); a++) + // free((*J)[a]); + //free(*J); + *J = calloc(*k, sizeof(int*)); + for(a=0; a<*k; a++) { + (*J)[a] = calloc(*k, sizeof(int)); + for(b=0; b<*k; b++) { + (*J)[a][b] = tmpMatrix[a][b]; + } + } + deallocate_mem(&tmpMatrix, *k); + + free(xi); free(zeta); free(Xprime); + return(1.0/sqrt(2.0)); // Gamma = 2^(-1/2) + } + + return(0.0); + +}