From: a <a@gmail.com>
Date: Sat, 7 Dec 2024 23:59:28 +0000 (-0500)
Subject: Sat 07 Dec 2024 06:59:28 PM EST
X-Git-Url: http://www.foleosoft.com/?a=commitdiff_plain;h=8f8df338352b8ba12a7328e4021f1fc978c002a2;p=QAnsel.git

Sat 07 Dec 2024 06:59:28 PM EST
---

diff --git a/examples/bellstate.txt b/examples/bellstate.txt
index 8ad1845..5520448 100644
--- a/examples/bellstate.txt
+++ b/examples/bellstate.txt
@@ -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
index 1d6b936..0000000
Binary files a/src/imports/Bloch-sphere-representation-of-a-qubit.jpg and /dev/null differ
diff --git a/src/imports/istina-editor.js b/src/imports/istina-editor.js
index f4d4f1b..6159c69 100644
--- a/src/imports/istina-editor.js
+++ b/src/imports/istina-editor.js
@@ -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 =>
diff --git a/src/index.html b/src/index.html
index ef5a4e5..3e45528 100644
--- a/src/index.html
+++ b/src/index.html
@@ -345,13 +345,33 @@
 							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) =>
@@ -530,6 +550,10 @@
 		
 		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%";
@@ -977,29 +1001,59 @@
 					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)