From: a Date: Sun, 8 Dec 2024 00:11:32 +0000 (-0500) Subject: Sat 07 Dec 2024 07:11:32 PM EST X-Git-Url: http://www.foleosoft.com/?a=commitdiff_plain;h=1ea92b066a6cc96d8225474bcce9b7775de20048;p=QAnsel.git Sat 07 Dec 2024 07:11:32 PM EST --- diff --git a/src/bytecode.c b/src/bytecode.c index ac7a670..8212add 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -456,7 +456,7 @@ unsigned char qansel_measure(QAnselContext* ctx, cpx_mtx_t* stateVector, unsigne cpx_mtx_get(stateVector, 0, i, &n); if (bit == 0) prob0 += cpx_magsqr(&n); } - float r = (ctx->hidden_variable) ? qansel_rand_h() : qansel_rand_t(ctx); + float r = (ctx->hidden_variable_set) ? qansel_rand_h() : qansel_rand_t(ctx); //add any error skew if desired if (ctx->noise > 0) { @@ -780,7 +780,7 @@ void qansel_born(QAnselContext* ctx, cpx_mtx_t* stateVector, int PC, int qubitCo for (int i = 0; i < qubitCountPow2; i++) stats[i] = 0; for (int i = 0; i < (ctx->bsampling_shots); i++) { - float r = (ctx->hidden_variable) ? qansel_rand_h() : qansel_rand_t(ctx); + float r = (ctx->hidden_variable_set) ? qansel_rand_h() : qansel_rand_t(ctx); float j = 0; //printf("--------------------------------\n"); for (unsigned int j = 0; j < qubitCountPow2; j++) @@ -838,7 +838,7 @@ void qansel_born(QAnselContext* ctx, cpx_mtx_t* stateVector, int PC, int qubitCo unsigned short stats = 0; for (int i = 0; i < (ctx->bsampling_shots); i++) { - float r = (ctx->hidden_variable) ? qansel_rand_h() : qansel_rand_t(ctx); + float r = (ctx->hidden_variable_set) ? qansel_rand_h() : qansel_rand_t(ctx); stats += r < prob ? 1 : 0; } printf("0\t%i\t%.2f%%\n", (ctx->bsampling_shots) - stats, (((float)(ctx->bsampling_shots) - (float)stats) / (float)(ctx->bsampling_shots)) * (float)100); @@ -1676,7 +1676,7 @@ int qanselExecuteBytecode(unsigned char* buff, int sizeofbuff, QAnselContext* ct if (!qanselContextValidate(ctx)) return 0; qansel_rand_s(qansel_hardware_getseed()); - if (ctx != NULL && ctx->hidden_variable != 0) + if (ctx != NULL && ctx->hidden_variable_set) { unsigned int tmp; memcpy(&tmp, &(ctx->hidden_variable), sizeof(unsigned int)); diff --git a/src/context.c b/src/context.c index 78333d0..a4c05ac 100644 --- a/src/context.c +++ b/src/context.c @@ -43,6 +43,8 @@ int qanselContextValidate(QAnselContext* ctx) int qanselContextBegin(QAnselContext* ctx) { + ctx->hidden_variable = 0; + ctx->hidden_variable_set = 0; ctx->noise = 0; ctx->chunk = NULL; if (ctx->memory_limit == 0) ctx->memory_limit = QANSEL_QUBITS_MAX; diff --git a/src/context.h b/src/context.h index 4c42b29..f831c86 100644 --- a/src/context.h +++ b/src/context.h @@ -13,6 +13,7 @@ typedef struct unsigned char verbose; unsigned char optimization_level; unsigned char sampling_bit; + unsigned char hidden_variable_set; float hidden_variable; float noise; int display_delay; diff --git a/src/openqasm.c b/src/openqasm.c index 10d725d..4ff2adb 100644 --- a/src/openqasm.c +++ b/src/openqasm.c @@ -684,7 +684,7 @@ int qansel_process_chunk(int index, char* chunk, int line, regmatch_t* regmatche } switch (instr) { - case 1: ctx->hidden_variable = d0; break; + case 1: ctx->hidden_variable_set = 1; ctx->hidden_variable = d0; break; case 2: ctx->noise = d0; break; } } @@ -700,7 +700,7 @@ int qansel_process_chunk(int index, char* chunk, int line, regmatch_t* regmatche tmp[strlen] = 0; if (strcmp(tmp, "rand") == 0) { - ctx->hidden_variable = 0; + ctx->hidden_variable_set = 0; return 1; } else if (strcmp(tmp, "exit") == 0) instr = QANSEL_INSTRUCTION_EXIT; diff --git a/src/src.zip b/src/src.zip index 8d965cd..b3f594e 100644 Binary files a/src/src.zip and b/src/src.zip differ