"barrier",
"hvar",
"noise",
+ "shots",
"rand",
"born"
];
for (var i = 0; i < keywords.length; i++)
{
- if (keywords[i] == "hvar" || keywords[i] == "noise") continue;
+ if (keywords[i] == "hvar" || keywords[i] == "noise" || keywords[i] == "shots") continue;
var tmp = new RegExp("(^|[ ]|[;]|[>])" + keywords[i] + "($|[ ]|[<]|[&])", "g");
txt = txt.replaceAll(tmp, x =>
{
);
txt = txt.replaceAll
(
- /(noise|hvar)( | )[.\-0-9][.\-0-9]*/g,
+ /(noise|hvar|shots)( | )[.\-0-9][.\-0-9]*/g,
x =>
{
x = x.replace(" ", " ");
<table border=1 class="program-instr" oncontextmenu="return false;" style="display: none;" cellspacing="0" cellpadding="0"></table>
<table border=1 class="program-drag" oncontextmenu="return false;" style="pointer-events: none; touch-action: none; visibility: hidden;"></table>
<script>
+ var shotsmax = 10000;
var ismobile = typeof(document.body.ontouchstart) == "object";
$ = x => { return document.querySelectorAll(x); };
if (window.location.href.includes("apikey="))
}
}
}
+ ret = "shots " + localStorage.getItem("shots") + ";\n" + ret;
}
return ret;
},
window.onload = function()
{
if (localStorage.getItem("noise") == null)
- localStorage.setItem("noise", 0);
+ localStorage.setItem("noise", 0);
if (localStorage.getItem("hvar") == null)
- localStorage.setItem("hvar", "");
+ localStorage.setItem("hvar", "");
+ if (localStorage.getItem("shots") == null)
+ localStorage.setItem("shots", shotsmax);
ProgramTrack.draw();
//$(".program-track")[0].parentNode.style.height = Math.round($(".program-instr")[0].getBoundingClientRect().height) + "px";
$(".program-track")[0].parentNode.style.width = "100%";
$("#modal-main-content")[0].innerHTML = `
<p>API key: </p><input type='text' id='apikey' />
<br />
+ <p>Shots: <p/><input type='number' id='shots' step='1' />
+ <br />
<p>Noise: <p/><input type='number' id='noise' step='0.01' />
<br />
<p>Hidden variable: <p/><input type='number' id='hvar' step='0.01' />
$("#apikey")[0].style.width = "100%";
$("#noise")[0].style.width = "100%";
$("#hvar")[0].style.width = "100%";
+ $("#shots")[0].style.width = "100%";
$("#apikey")[0].addEventListener("click", () =>
{
$("#apikey")[0].selectionStart = 0;
$("#apikey")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } })
$("#noise")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } });
$("#hvar")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } });
+ $("#shots")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } });
var noiseChange = () =>
{
var v = parseFloat($("#noise")[0].value);
if (isNaN(v)) v = "";
$("#hvar")[0].value = v;
}
+ var shotsChange = () =>
+ {
+ var v = parseInt($("#shots")[0].value);
+ if (isNaN(v)) v = shotsmax;
+ if (v <= 0) v = 1;
+ if (v > shotsmax) v = shotsmax;
+ $("#shots")[0].value = v;
+ };
var changeEvents = ["change", "keydown", "keyup", "mouseenter", "mouseleave"];
for (var i = 0; i < changeEvents.length; i++)
{
$("#noise")[0].addEventListener(changeEvents[i], e => { noiseChange(); });
$("#hvar")[0].addEventListener(changeEvents[i], e => { hvarChange(); });
+ $("#shots")[0].addEventListener(changeEvents[i], e => { shotsChange(); });
}
$("#apikey")[0].value = apikey;
$("#noise")[0].value = localStorage.getItem("noise");
$("#hvar")[0].value = localStorage.getItem("hvar");
+ $("#shots")[0].value = localStorage.getItem("shots");
$("#modal-main-confirm")[0].style.display = "";
$("#modal-main-cancel")[0].style.display = "";
$("#modal-main-confirm")[0].setAttribute("onclick",
localStorage.setItem('apikey', $('#apikey')[0].value);
localStorage.setItem('noise', $('#noise')[0].value);
localStorage.setItem('hvar', $('#hvar')[0].value);
+ localStorage.setItem('shots', $('#shots')[0].value);
closeModal();
ProgramTrack.draw();
`);
return 1;
}
-int qansel_process_chunk(int index, char* chunk, int line, regmatch_t* regmatches, int* qubitCount, int* bitCount, unsigned char** binary, int* binarySize, QAnselContext* ctx, int samplingshots)
+int qansel_process_chunk(int index, char* chunk, int line, regmatch_t* regmatches, int* qubitCount, int* bitCount, unsigned char** binary, int* binarySize, QAnselContext* ctx, int* samplingshots)
{
unsigned short s0;
float d0, d1, d2;
if (a0 == QANSEL_ALL_CLASSIC) a0 = QANSEL_ALL;
else a0 = a0 - QANSEL_CBOUND_LOWER;
ctx->sampling_bit = a0;
- ctx->sampling_shots = samplingshots;
+ ctx->sampling_shots = *samplingshots;
}
else
{
tmp[strlen] = 0;
if (strcmp(tmp, "hvar") == 0) instr = 1;
if (strcmp(tmp, "noise") == 0) instr = 2;
+ if (strcmp(tmp, "shots") == 0) instr = 3;
}
{
int strbeg = regmatches[rmp].rm_so;
{
case 1: ctx->hidden_variable_set = 1; ctx->hidden_variable = d0; break;
case 2: ctx->noise = d0; break;
+ case 3:
+ if (d0 <= 0 || d0 > *samplingshots)
+ {
+ fprintf(stderr, "QAnsel on line %i: Invalid number of shots.\n", line);
+ return 0;
+ }
+ *samplingshots = d0;
+ break;
}
}
else if (index == 12) //lone instructions
return 1;
}
-int qansel_process_chunks(char** chunks, int* associatedLines, int count, unsigned char** retBinary, int* retSize, QAnselContext* ctx, int samplingshots)
+int qansel_process_chunks(char** chunks, int* associatedLines, int count, unsigned char** retBinary, int* retSize, QAnselContext* ctx, int* samplingshots)
{
unsigned char* binary = malloc(0);
int binarySize = 0;
"^[ ]*(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|noise)[ ][ ]*([-/0-9PI.][-/0-9PI.]*)[ ]*$",
+ "^[ ]*(hvar|noise|shots)[ ][ ]*([-/0-9PI.][-/0-9PI.]*)[ ]*$",
"^[ ]*(rand|exit)[ ]*$",
};
int ret, status = 0, found;
fprintf(stderr, "QAnsel: Read script failure.\n");
return 0;
}
- status = qansel_process_chunks(chunks, chunksAssociatedLines, chunksCount, binary, binarySize, ctx, samplingshots);
+ status = qansel_process_chunks(chunks, chunksAssociatedLines, chunksCount, binary, binarySize, ctx, &samplingshots);
for (int i = 0; i < chunksCount; i++) free(chunks[i]);
free(chunks);
free(chunksAssociatedLines);
int qansel_read_script(char* script, char*** chunksReturn, int** chunkLinesReturn, int* countReturn);
float qansel_parse_float_part(char* neg, char* str);
int qansel_parse_float(char* str, float* returnFloat);
-int qansel_process_chunk(int index, char* chunk, int line, regmatch_t* regmatches, int* qubitCount, int* bitCount, unsigned char** binary, int* binarySize, QAnselContext* ctx, int samplingshots);
-int qansel_process_chunks(char** chunks, int* associatedLines, int count, unsigned char** retBinary, int* retSize, QAnselContext* ctx, int samplingshots);
+int qansel_process_chunk(int index, char* chunk, int line, regmatch_t* regmatches, int* qubitCount, int* bitCount, unsigned char** binary, int* binarySize, QAnselContext* ctx, int* samplingshots);
+int qansel_process_chunks(char** chunks, int* associatedLines, int count, unsigned char** retBinary, int* retSize, QAnselContext* ctx, int* samplingshots);
int qanselBuildFromSource(char* source, unsigned char** binary, int* binarySize, QAnselContext* ctx);
#endif