From: Lucas Date: Wed, 2 Feb 2022 00:36:46 +0000 (-0800) Subject: final v1.0 files X-Git-Url: https://s3miclassical.com/gitweb/?a=commitdiff_plain;ds=sidebyside;p=weak_simulation_stab_extent.git final v1.0 files --- diff --git a/weaksim.c b/weaksim.c index 8ec6222..b2c93f4 100644 --- a/weaksim.c +++ b/weaksim.c @@ -11,6 +11,7 @@ #include "measurepauli.h" #include "innerproduct.h" #include "sparsify.h" +#include "omp.h" int readPaulicoeffs(int *omega, int *alpha, int *beta, int *gamma, int *delta, int numqubits); @@ -19,14 +20,18 @@ int readPaulicoeffs(int *omega, int *alpha, int *beta, int *gamma, int *delta, i int main(int argc, char *argv[]) { - if(argc != 4) { - printf("weaksim argument: \"additive error delta\" \"phi (times PI)\" \"coherent sampling (0=no; 1=yes)\"\n"); + if(argc != 5 && argc != 6) { + printf("weaksim argument: \"additive error delta\" \"phi (times PI)\" \"coherent sampling (0=no; 1=t; 2=2t-1; 3=xi^3t/2)\" \"seed\" \"(optional) sample number prefactor\"\n"); exit(0); } double additiveErrorDelta = atof(argv[1]); // additive error delta double phi = PI*atof(argv[2]);//PI/4.0; // PI/4.0 is the T gate magic state - int coherentSampling = atoi(argv[3]); // perform coherent sampling (true=1 or false=0) + int coherentSampling = atoi(argv[3]); // perform coherent sampling (false=0; linear t=1; linear 2t-1=2; exponential xi^3t/2=3) + int seed = atoi(argv[4]); // random number seed + double samplePrefactor = 1.0; + if(argc == 6) + samplePrefactor = atof(argv[5]); // factor that multiplies k, the number of samples used int N; // number of qubits scanf("%d", &N); @@ -57,16 +62,17 @@ int main(int argc, char *argv[]) long* stabStateIndices; int numStabStates; - srand((unsigned)time(NULL)); // seeding the random number generator for sparsify() + //srand((unsigned)time(NULL)); // seeding the random number generator for sparsify() + srand((unsigned)seed); // seeding the random number generator for sparsify() - if(sparsify(&stabStateIndices, &numStabStates, T, phi, additiveErrorDelta, coherentSampling)) + if(sparsify(&stabStateIndices, &numStabStates, T, phi, additiveErrorDelta, coherentSampling, samplePrefactor)) return 1; - //printf("checking: numStabStateIndices:\n"); - //for(i=0; i0?'+':'-' , cabs(cimag(lastamplitude))); + printf("amplitude: %lf %c %lf I\n", cabs(creal(amplitude)), cimag(amplitude+0.00000001)>0?'+':'-' , cabs(cimag(amplitude))); + + probability *= amplitude/lastamplitude; + //amplitude = amplitude/lastamplitude; // for NORMALIZE-SPARSIFY you normalize the algorithm after every Pauli measurement + + printf("probability = %lf\n", cabs(probability)); + printf("!\n"); } //printf("numStabStates=%d\n", numStabStates); @@ -295,6 +341,8 @@ int main(int argc, char *argv[]) printf("\nabs(amplitude):\n"); printf("%lf\n", cabs(amplitude)); + printf("probability = %lf\n", cabs(probability)); + return 0; } diff --git a/weaksim_relerr.c b/weaksim_relerr.c index 2cc45fb..09bf002 100644 --- a/weaksim_relerr.c +++ b/weaksim_relerr.c @@ -6,7 +6,7 @@ #include #include "matrix.h" #include "exponentialsum.h" -#include "shrinkstar.h" +#include "shrink.h" #include "extend.h" #include "measurepauli.h" #include "innerproduct.h" @@ -23,25 +23,25 @@ int main(int argc, char *argv[]) { if(argc != 5) { - printf("weaksim_rellerr argument: \"number of stabilizer state samples\" \"additive error delta\" \"phi (times PI)\" \"coherent sampling (0=no; 1=yes)\"\n"); + printf("weaksim_relerr argument: \"number of stabilizer state samples\" \"additive error delta\" \"phi (times PI)\" \"coherent sampling (0=no; 1=t; 2=2t-1; 3=xi^3t/2)\\n"); exit(0); } int NUMSTABSTATESAMPLES = atoi(argv[1]); // number of stabilizer state samples double additiveErrorDelta = atof(argv[2]); // additive error delta double phi = PI*atof(argv[3]);//PI/4.0; // PI/4.0 is the T gate magic state - int coherentSampling = atoi(argv[4]); // perform coherent sampling (true=1 or false=0) + int coherentSampling = atoi(argv[4]); // perform coherent sampling (false=0; linear t=1; linear 2t-1=2; exponential xi^3t/2=3) - int N; // number of qubits + int N; // number of qubits scanf("%d", &N); int T; // 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) - scanf("%d", &T); + scanf("%d", &T); printf("phi = %lf\n", phi); - int omega[N]; // max of N measurements - int alpha[N][N], beta[N][N], gamma[N][N], delta[N][N]; // max of N measurements of N Paulis + int omega; + int alpha[N], beta[N], gamma[N], delta[N]; int Paulicounter = 0; int i, j, k, l, m; @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) FILE *fp; char buff[255]; - srand((unsigned)time(NULL)); // seeding the random number generator for randomstabilizerstate() + srand((unsigned)time(NULL)); // seeding the random number generator for randomstabilizerstate _equatorial() fp = fopen("Pd.txt", "r"); @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) int PdN = atoi(buff); Pd = calloc(PdN, sizeof(double*)); - for(i=0; i = e^(pi*i/8)/2*sqrt(4-2*sqrt(2))* (sqrt(-i)*(|0>+i|1>)/sqrt(2) + (|0>+|1>)/sqrt(2)) + + //double additiveErrorDelta = 0.1; + double complex coeffa = cexp(I*carg(cexp(PI*I/8.0)*0.5*csqrt(4.0-2.0*csqrt(2.0))*cexp(-PI*I*0.25)*I/sqrt(2.0)*(-I+cexp(-0.25*PI*I))*(-I+cexp(I*phi)))); // factor of cexp(PI*I/8.0)*cexp(-PI*I*0.25) comes from converting (|0>+|1>)/sqrt(2) under e^(pi*i/8) H S^\dagger to take it from |H> to |T> double complex coeffb = cexp(I*carg(cexp(PI*I/8.0)*0.5*csqrt(4.0-2.0*csqrt(2.0))*I/sqrt(2.0)*(1.0+cexp(-0.25*PI*I))*(1.0-cexp(I*phi)))); // factor of cexp(PI*I/8.0) comes from converting |0> under e^(pi*i/8) H S^\dagger to take it from |H> to |T> // alternative coefficient to use instead of coeffb to get overall entangled state @@ -98,15 +100,14 @@ int main(int argc, char *argv[]) srand((unsigned)time(NULL)); // seeding the random number generator for sparsify() - if(sparsify(&stabStateIndices, &numStabStates, T, phi, additiveErrorDelta, coherentSampling)) return 1; - //printf("checking: numStabStateIndices:\n"); - //for(i=0; i 0) { + // origJ[j] = calloc(K[j], sizeof(int*)); origD[j] = calloc(K[j], sizeof(int)); + // for(k=0; k N) { + while(readPaulicoeffs(&omega, alpha, beta, gamma, delta, N)) { + + Paulicounter++; + if(Paulicounter > N) { printf("Error: Number of Paulis is greater than N!\n"); return 1; } @@ -287,116 +342,61 @@ int main(int argc, char *argv[]) // Let's break up the Ys into Xs and Zs in the order Z X, as required to pass to measurepauli() // Y_i = -I*Z*X for(i=0; i0?'+':'-' , cabs(cimag(lastamplitude))); + printf("amplitude: %lf %c %lf I\n", cabs(creal(amplitude)), cimag(amplitude+0.00000001)>0?'+':'-' , cabs(cimag(amplitude))); + + probability *= amplitude/lastamplitude; + //amplitude = amplitude/lastamplitude; // for NORMALIZE-SPARSIFY you normalize the algorithm after every Pauli measurement - deallocate_mem(&origG, N); - deallocate_mem(&origGBar, N); - free(origh); - deallocate_mem(&origJ, origK); - free(origD); + printf("probability = %lf\n", cabs(probability)); + printf("!\n"); } //printf("numStabStates=%d\n", numStabStates); printf("L1Norm=%lf\n", L1Norm); printf("\namplitude:\n"); - if(creal(amplitude+ZEROTHRESHOLD)>0) - printf("%.10lf %c %.10lf I\n", cabs(creal(amplitude)), cimag(amplitude+ZEROTHRESHOLD)>0?'+':'-' , cabs(cimag(amplitude))); + if(creal(amplitude+0.00000001)>0) + printf("%lf %c %lf I\n", cabs(creal(amplitude)), cimag(amplitude+0.00000001)>0?'+':'-' , cabs(cimag(amplitude))); else - printf("%.10lf %c %.10lf I\n", creal(amplitude), cimag(amplitude+ZEROTHRESHOLD)>0?'+':'-' , cabs(cimag(amplitude))); + printf("%lf %c %lf I\n", creal(amplitude), cimag(amplitude+0.00000001)>0?'+':'-' , cabs(cimag(amplitude))); + //printf("%lf %c %lf I\n", creal(amplitude), cimag(amplitude)>0?'+':'-' , cabs(cimag(amplitude))); printf("\nabs(amplitude):\n"); printf("%lf\n", cabs(amplitude)); - - for(i=0; i