]> foleosoft.com Git - QAnsel.git/commitdiff
Sat 07 Dec 2024 07:11:32 PM EST
authora <[email protected]>
Sun, 8 Dec 2024 00:11:32 +0000 (19:11 -0500)
committera <[email protected]>
Sun, 8 Dec 2024 00:11:32 +0000 (19:11 -0500)
src/bytecode.c
src/context.c
src/context.h
src/openqasm.c
src/src.zip

index ac7a6700554153b8224bd561048287b97aeb5092..8212addfa027e76f26e32d354b722626c67bb577 100644 (file)
@@ -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));
index 78333d093036cd20e988e85e4d4f20ec4c25eadb..a4c05acfa0f725d1c8a4f06d3db0e7d57d9f9a71 100644 (file)
@@ -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;
index 4c42b29680578c020c85a9a5e7b1e0738fd1b296..f831c8680637860105d9ea8345251cf38677f7b5 100644 (file)
@@ -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;
index 10d725d9e0839240dd181aeb09e19007252c2459..4ff2adb563529b21aa389bf38e43632b68381188 100644 (file)
@@ -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;
index 8d965cd7ef7dc0dcad1393c30fd9e0f0526593f3..b3f594e838e432c8f244fdd3cda72dc8bc4f001f 100644 (file)
Binary files a/src/src.zip and b/src/src.zip differ