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);
+ //add any error skew if desired
+ if (ctx->noise > 0)
+ {
+ float probtot;
+ float prob1 = 1 - prob0;
+ prob0 += ctx->noise;
+ prob1 += ctx->noise;
+ probtot = prob0 + prob1;
+ prob0 /= probtot;
+ prob1 /= probtot;
+ }
unsigned char newBit = r < prob0 ? 0 : 1;
float probTot = 0;
for (unsigned int i = 0; i < qubitCountPow2; i++)
float *psisquared = malloc(sizeof(float) * qubitCountPow2);
for (unsigned int j = 0; j < qubitCountPow2; j++)
{
- if (mode == 0)
+ cpx_t n;
+ cpx_mtx_get(stateVector, 0, j, &n);
+ psisquared[j] = cpx_magsqr(&n);
+ }
+ //add any error skew if desired
+ if (ctx->noise > 0)
+ {
+ float totalprob = 0;
+ for (unsigned int j = 0; j < qubitCountPow2; j++)
+ {
+ psisquared[j] += ctx->noise;
+ totalprob += psisquared[j];
+ }
+ for (unsigned int j = 0; j < qubitCountPow2; j++)
+ {
+ psisquared[j] /= totalprob;
+ }
+ }
+ if (mode == 0)
+ {
+ for (unsigned int j = 0; j < qubitCountPow2; j++)
{
unsigned int tmp = j;
for (unsigned char k = 0; k < qubitCount; k++)
putchar('0' + (tmp >> (qubitCount - 1) & 1));
tmp <<= 1;
}
- }
- cpx_t n;
- cpx_mtx_get(stateVector, 0, j, &n);
- psisquared[j] = cpx_magsqr(&n);
- if (mode == 0)
- {
printf("\t%.2f%%\n", psisquared[j] * 100);
}
- }
- if (mode == 0)
- {
free(psisquared);
return;
}
memcpy(tmp, chunk + strbeg, strlen);
tmp[strlen] = 0;
if (strcmp(tmp, "hvar") == 0) instr = 1;
+ if (strcmp(tmp, "noise") == 0) instr = 2;
}
{
int strbeg = regmatches[rmp].rm_so;
switch (instr)
{
case 1: ctx->hidden_variable = d0; break;
+ case 2: ctx->noise = d0; break;
}
}
else if (index == 12) //lone instructions
"^[ ]*(cx|cnot|swap)[ ]*q[ ]*\\[[ ]*([0-9][0-9]*)[ ]*\\][ ]*,[ ]*q[ ]*\\[[ ]*([0-9]*)[ ]*\\][ ]*$",
"^[ ]*(ccx|toffoli|cswap|fredkin)[ ]*q[ ]*\\[[ ]*([0-9][0-9]*)[ ]*\\][ ]*,[ ]*q[ ]*\\[[ ]*([0-9][0-9]*)[ ]*\\][ ]*,[ ]*q[ ]*\\[[ ]*([0-9][0-9]*)[ ]*\\][ ]*$",
"^[ ]*if[ ]*\\([ ]*c[ ]*(\\[[ ]*([0-9][0-9]*)[ ]*\\]|)[ ]*(==|!=|<>|>=|<=|>|<)[ ]*([0-9][0-9]*)[ ]*\\).*[ ]*$",
- "^[ ]*(hvar)[ ]*([-/0-9PI.]*)[ ]*$",
+ "^[ ]*(hvar|noise)[ ][ ]*([-/0-9PI.][-/0-9PI.]*)[ ]*$",
"^[ ]*(rand|exit)[ ]*$",
};
int ret, status = 0, found;