From 4ce6ef0037228a2d14ca91f892ffb854549fc797 Mon Sep 17 00:00:00 2001 From: miha-q <> Date: Fri, 2 Aug 2024 17:38:44 -0400 Subject: [PATCH] Fri Aug 2 05:38:44 PM EDT 2024 --- examples/ghz.txt | 3 ++- src/bytecode.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/ghz.txt b/examples/ghz.txt index 8bd66a2..1b3d772 100644 --- a/examples/ghz.txt +++ b/examples/ghz.txt @@ -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 diff --git a/src/bytecode.c b/src/bytecode.c index 7033c3a..ae45856 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -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) { -- 2.39.5