]> foleosoft.com Git - QAnsel.git/commitdiff
Sat 07 Dec 2024 06:59:28 PM EST
authora <[email protected]>
Sat, 7 Dec 2024 23:59:28 +0000 (18:59 -0500)
committera <[email protected]>
Sat, 7 Dec 2024 23:59:28 +0000 (18:59 -0500)
examples/bellstate.txt
src/imports/Bloch-sphere-representation-of-a-qubit.jpg [deleted file]
src/imports/istina-editor.js
src/index.html

index 8ad184584abcd3edede3c6b7f7e8b8e5876da609..5520448f7904a29457e9d5d74b8386d2a1228f61 100644 (file)
@@ -1,5 +1,8 @@
 //entanglement
 qreg q[2];
+creg c[2];
 h q[0];
 cx q[0], q[1];
-born q;
+measure q[0] -> c[0];
+measure q[1] -> c[1];
+sample c;
diff --git a/src/imports/Bloch-sphere-representation-of-a-qubit.jpg b/src/imports/Bloch-sphere-representation-of-a-qubit.jpg
deleted file mode 100644 (file)
index 1d6b936..0000000
Binary files a/src/imports/Bloch-sphere-representation-of-a-qubit.jpg and /dev/null differ
index f4d4f1b475faa5eb82543db26362e74c6056721a..6159c692dda4066950c0ac2b4e90820b15cf4d82 100644 (file)
@@ -253,6 +253,7 @@ IstinaEditor.highlightForQAnsel = function(txt)
                
        for (var i = 0; i < keywords.length; i++)
        {
+               if (keywords[i] == "hvar" || keywords[i] == "noise") continue;
                var tmp = new RegExp("(^|[ ]|[;]|[>])" + keywords[i] + "($|[ ]|[<]|[&])", "g");
                txt = txt.replaceAll(tmp, x =>
                {
@@ -288,6 +289,20 @@ IstinaEditor.highlightForQAnsel = function(txt)
                }
        );
        txt = txt.replaceAll
+       (
+               /(noise|hvar)( |&nbsp;)[.\-0-9][.\-0-9]*/g,
+               x =>
+               {
+                       x = x.replace(" ", "&nbsp;");
+                       var lhs = x.split("&nbsp;")[0].trim();
+                       var rhs = x.split("&nbsp;")[1].trim();
+                       x = "<span class='istina-keyword'>" + lhs + "</span>";
+                       x += " ";
+                       x += "<span class='istina-number'>" + rhs + "</span>";
+                       return x;
+               }
+       );
+       txt = txt.replaceAll
        (
                /if[(].*?[)]/g,
                x =>
index ef5a4e5a1abf5b4e042febd2b35907d7f57b4a97..3e455284fd260c245b4a36fa9e01cd55b252bca0 100644 (file)
                                                        ret += "sample q;\n";
                                                }
                                        }
-                                       
                                }
                                if (ProgramTrack.STATE[0].length == 0)
                                {
                                        ret = "qreg q[" + (ProgramTrack.STATE.length - 1) + "];\n";
                                        ret += "sample q;\n";
                                }
+
+                               if (!ret.includes("Duplicate") && !ret.includes("Incomplete"))
+                               {
+                                       if (localStorage.getItem("hvar") != null)
+                                       {
+                                               if (!isNaN(parseFloat(localStorage.getItem("hvar"))))
+                                               {
+                                                       ret = "hvar " + localStorage.getItem("hvar") + ";\n" + ret;
+                                               }
+                                       }
+                                       if (localStorage.getItem("noise") != null)
+                                       {
+                                               if (!isNaN(parseFloat(localStorage.getItem("noise"))))
+                                               {
+                                                       if (parseFloat(localStorage.getItem("noise")) != 0)
+                                                       {
+                                                               ret = "noise " + localStorage.getItem("noise") + ";\n" + ret;
+                                                       }
+                                               }
+                                       }
+                               }
                                return ret;
                        },
                        drag: (e, erase, evt, dodrag) =>
                
                window.onload = function()
                {
+                       if (localStorage.getItem("noise") == null)
+                               localStorage.setItem("noise", 0);                               
+                       if (localStorage.getItem("hvar") == null)
+                               localStorage.setItem("hvar", "");                               
                        ProgramTrack.draw();
                        //$(".program-track")[0].parentNode.style.height = Math.round($(".program-instr")[0].getBoundingClientRect().height) + "px";
                        $(".program-track")[0].parentNode.style.width = "100%";
                                        var apikey = localStorage.getItem("apikey");
                                        apikey = (apikey ? apikey : "").replace("'", "").replace("\"", "").replace("\n", "");
                                        $(".modal__container")[0].style.width = "500px";
-                                       $("#modal-main-title")[0].innerHTML = "API Settings";
-                                       $("#modal-main-content")[0].innerHTML = "<p>Please enter your API key: </p><input type='text' id='apikey' />";
+                                       $("#modal-main-title")[0].innerHTML = "Settings";
+                                       $("#modal-main-content")[0].innerHTML = `
+                                               <p>API key: </p><input type='text' id='apikey' />
+                                               <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%";
                                        $("#apikey")[0].addEventListener("click", () =>
                                        {
                                                $("#apikey")[0].selectionStart = 0;
                                                $("#apikey")[0].selectionEnd = $("#apikey")[0].value.length;
                                        });
-                                       $("#apikey")[0].addEventListener("keydown", e =>
+                                       $("#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(); } });
+                                       var noiseChange = () =>
                                        {
-                                               if (e.key == "Enter")
-                                               {
-                                                       $("#modal-main-confirm")[0].click();
-                                               }
-                                       });
+                                               var v = parseFloat($("#noise")[0].value);
+                                               if (isNaN(v)) v = 0;
+                                               if (v < 0) v = 0;
+                                               if (v > 100) v = 100;
+                                               $("#noise")[0].value = v;
+                                       };
+                                       var hvarChange = () =>
+                                       {
+                                               var v = parseFloat($("#hvar")[0].value);
+                                               if (isNaN(v)) v = "";
+                                               $("#hvar")[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(); });
+                                       }
                                        $("#apikey")[0].value = apikey;
+                                       $("#noise")[0].value = localStorage.getItem("noise");
+                                       $("#hvar")[0].value = localStorage.getItem("hvar");
                                        $("#modal-main-confirm")[0].style.display = "";
                                        $("#modal-main-cancel")[0].style.display = "";
-                                       $("#modal-main-confirm")[0].setAttribute("onclick", "localStorage.setItem('apikey', $('#modal-main-content input')[0].value); closeModal();");
+                                       $("#modal-main-confirm")[0].setAttribute("onclick",
+                                       `
+                                               localStorage.setItem('apikey', $('#apikey')[0].value);
+                                               localStorage.setItem('noise', $('#noise')[0].value);
+                                               localStorage.setItem('hvar', $('#hvar')[0].value);
+                                               closeModal();
+                                               ProgramTrack.draw();
+                                       `);
                                        MicroModal.show("modal-main");
-                                       $("#apikey")[0].focus();
-                                       $("#apikey")[0].selectionStart = 0;
-                                       $("#apikey")[0].selectionEnd = $("#apikey")[0].value.length;
                                break;
                                case "save":
                                        if (ProgramTrack.STATE[0].length == 0)