]> foleosoft.com Git - QAnsel.git/commitdiff
Fri Aug 2 05:38:44 PM EDT 2024
authormiha-q <>
Fri, 2 Aug 2024 21:38:44 +0000 (17:38 -0400)
committermiha-q <>
Fri, 2 Aug 2024 21:38:44 +0000 (17:38 -0400)
examples/ghz.txt
src/bytecode.c

index 8bd66a2bb0d912061a476b11700f767bf92c50f2..1b3d772c3e12b277361c7b51d627de717cc2bccd 100644 (file)
@@ -1,3 +1,4 @@
 qreg q[2];
 h q[0];
-sample q;
+cx q[0], q[1];
+sample q;
\ No newline at end of file
index 7033c3a1918a869d5105c4e6c55cc5a400816f2c..ae45856d057267dbf799d11f314cd168f635b9a4 100644 (file)
@@ -724,6 +724,7 @@ void qansel_born(QAnselContext* ctx, cpx_mtx_t* stateVector, int PC, int qubitCo
                }
                float *psisquared_sorted = malloc(sizeof(float) * qubitCountPow2);
                unsigned short *sorting = malloc(sizeof(unsigned short) * qubitCountPow2);
+               unsigned short *rsorting = malloc(sizeof(unsigned short) * qubitCountPow2);
                for (int i = 0; i < qubitCountPow2; i++) psisquared_sorted[i] = 0;
                for (int i = 0; i < qubitCountPow2; i++)
                {
@@ -739,8 +740,10 @@ void qansel_born(QAnselContext* ctx, cpx_mtx_t* stateVector, int PC, int qubitCo
                        }
                        psisquared_sorted[i] = max;
                        sorting[i] = maxi;
+                       rsorting[maxi] = i;
                        psisquared[maxi] = -1;
                }
+               for (int i = 0; i < qubitCountPow2; i++) printf("]%i -> %i: %f[\n", rsorting[i], sorting[i], psisquared_sorted[i]);
                free(psisquared);
                unsigned short *stats = malloc(sizeof(unsigned short) * qubitCountPow2);
                for (int i = 0; i < qubitCountPow2; i++) stats[i] = 0;
@@ -748,17 +751,21 @@ void qansel_born(QAnselContext* ctx, cpx_mtx_t* stateVector, int PC, int qubitCo
                {
                        float r = (ctx->hidden_variable) ? qansel_rand_h() : qansel_rand_t(ctx);
                        float j = 0;
+                       //printf("--------------------------------\n");
                        for (unsigned int j = 0; j < qubitCountPow2; j++)
                        {
+                               //printf("%f >= %f\n", psisquared_sorted[j], r);
                                if (psisquared_sorted[j] >= r)
                                {
                                        stats[j]++;
+                                       //printf("%i _/\n", j);
                                        break;
                                }
                                r -= psisquared_sorted[j];
                                if (j == qubitCountPow2 - 1)
                                {
                                        stats[j]++;
+                                       //printf("%i _/\n", j);
                                }
                        }
                }
@@ -770,11 +777,13 @@ void qansel_born(QAnselContext* ctx, cpx_mtx_t* stateVector, int PC, int qubitCo
                                putchar('0' + (tmp >> (qubitCount - 1) & 1));
                                tmp <<= 1;
                        }
-                       printf("\t%i\t%.2f%%\n", stats[sorting[j]], ((float)stats[sorting[j]] / (float)(ctx->bsampling_shots)) * (float)100);
+                       //printf("%i -> %i\n", j, sorting[j]);
+                       printf("\t%i\t%.2f%%\n", stats[rsorting[j]], ((float)stats[rsorting[j]] / (float)(ctx->bsampling_shots)) * (float)100);
                }
                free(psisquared_sorted);
                free(stats);
                free(sorting);
+               free(rsorting);
        }
        else if (q0 <= QANSEL_QBOUND_UPPER)
        {