]> foleosoft.com Git - QAnsel.git/commitdiff
Fri Aug 2 06:39:33 PM EDT 2024
authormiha-q <>
Fri, 2 Aug 2024 22:39:33 +0000 (18:39 -0400)
committermiha-q <>
Fri, 2 Aug 2024 22:39:33 +0000 (18:39 -0400)
examples/ghz.txt
src/gui.html

index 1b3d772c3e12b277361c7b51d627de717cc2bccd..173645749892d639a27c907d8cbce78d7b0562bc 100644 (file)
@@ -1,4 +1,9 @@
-qreg q[2];
+qreg q[3];
 h q[0];
 cx q[0], q[1];
+sdg q[1];
+sdg q[2];
+h q[0];
+h q[1];
+h q[2];
 sample q;
\ No newline at end of file
index b0ac8d3d306e892c0a83ec56a7733161d4118865..40115693c3cc08459e52a7c03237d6dbf2dfbfe1 100644 (file)
        <script>
                $ = x => { return document.querySelectorAll(x); };
                IstinaEditor.init();
-               function overline(instr, pos)
+               function overline(instr, pos, compare)
                {
+                       var r;
                        switch (instr)
                        {
                                case "CX":
                                        switch (pos)
                                        {
-                                               case "10": return "<span style='text-decoration:overline;'>C</span>X"; break;
-                                               case "01": return "C<span style='text-decoration:overline;'>X</span>"; break;
+                                               case "10": r = "<span style='text-decoration:overline;'>C</span>X"; break;
+                                               case "01": r = "C<span style='text-decoration:overline;'>X</span>"; break;
                                        }
                                break;
                                case "SW":
                                        switch (pos)
                                        {
-                                               case "10": return "<span style='text-decoration:overline;'>S</span>W"; break;
-                                               case "01": return "S<span style='text-decoration:overline;'>W</span>"; break;
+                                               case "10": r = "<span style='text-decoration:overline;'>S</span>W"; break;
+                                               case "01": r = "S<span style='text-decoration:overline;'>W</span>"; break;
                                        }
                                break;
                                case "CCX":
                                        switch (pos)
                                        {
-                                               case "100": return "<span style='text-decoration:overline;'>C</span>CX"; break;
-                                               case "010": return "C<span style='text-decoration:overline;'>C</span>X"; break;
-                                               case "001": return "CC<span style='text-decoration:overline;'>X</span>"; break;
+                                               case "100": r = "<span style='text-decoration:overline;'>C</span>CX"; break;
+                                               case "010": r = "C<span style='text-decoration:overline;'>C</span>X"; break;
+                                               case "001": r = "CC<span style='text-decoration:overline;'>X</span>"; break;
                                        }
                                break;
                                case "CSW":
                                        switch (pos)
                                        {
-                                               case "100": return "<span style='text-decoration:overline;'>C</span>SW"; break;
-                                               case "010": return "C<span style='text-decoration:overline;'>S</span>W"; break;
-                                               case "001": return "CS<span style='text-decoration:overline;'>W</span>"; break;
+                                               case "100": r = "<span style='text-decoration:overline;'>C</span>SW"; break;
+                                               case "010": r = "C<span style='text-decoration:overline;'>S</span>W"; break;
+                                               case "001": r = "CS<span style='text-decoration:overline;'>W</span>"; break;
                                        }
                                break;
                        }
+                       if (compare == undefined) return r;
+                       compare = compare.replace(/[\"]/g, "'").trim();
+                       return compare == r;
                }
 
                var INSTRUCTIONS =
                                        {
                                                var instr = ProgramTrack.STATE[j][i].trim();
                                                if (instr.length == 0) continue;
-                                               console.log(instr);
                                                if (j > maxQ) maxQ = j;
                                                switch (instr)
                                                {
                                                                        ret += ifblk + "measure q[" + j + "] -> c[" + num + "];\n";
                                                                }
                                                }
-                                               if (instr == overline("CX", "10")) { if (cx[1] != -1) { cx[0] = 1; } cx[1] = j; }
-                                               if (instr == overline("CX", "01")) { if (cx[2] != -1) { cx[0] = 1; } cx[2] = j; }
-                                               if (instr == overline("SW", "10")) { if (sw[1] != -1) { sw[0] = 1; } sw[1] = j; }
-                                               if (instr == overline("SW", "01")) { if (sw[2] != -1) { sw[0] = 1; } sw[2] = j; }
+                                               if (overline("CX", "10", instr)) { if (cx[1] != -1) { cx[0] = 1; } cx[1] = j; }
+                                               if (overline("CX", "01", instr)) { if (cx[2] != -1) { cx[0] = 1; } cx[2] = j; }
+                                               if (overline("SW", "10", instr)) { if (sw[1] != -1) { sw[0] = 1; } sw[1] = j; }
+                                               if (overline("SW", "01", instr)) { if (sw[2] != -1) { sw[0] = 1; } sw[2] = j; }
 
-                                               if (instr == overline("CCX", "100")) { if (ccx[1] != -1) { ccx[0] = 1; } ccx[1] = j; }
-                                               if (instr == overline("CCX", "010")) { if (ccx[2] != -1) { ccx[0] = 1; } ccx[2] = j; }
-                                               if (instr == overline("CCX", "001")) { if (ccx[3] != -1) { ccx[0] = 1; } ccx[3] = j; }
-                                               if (instr == overline("CSW", "100")) { if (csw[1] != -1) { csw[0] = 1; } csw[1] = j; }
-                                               if (instr == overline("CSW", "010")) { if (csw[2] != -1) { csw[0] = 1; } csw[2] = j; }
-                                               if (instr == overline("CSW", "001")) { if (csw[3] != -1) { csw[0] = 1; } csw[3] = j; }
+                                               if (overline("CCX", "100", instr)) { if (ccx[1] != -1) { ccx[0] = 1; } ccx[1] = j; }
+                                               if (overline("CCX", "010", instr)) { if (ccx[2] != -1) { ccx[0] = 1; } ccx[2] = j; }
+                                               if (overline("CCX", "001", instr)) { if (ccx[3] != -1) { ccx[0] = 1; } ccx[3] = j; }
+                                               if (overline("CSW", "100", instr)) { if (csw[1] != -1) { csw[0] = 1; } csw[1] = j; }
+                                               if (overline("CSW", "010", instr)) { if (csw[2] != -1) { csw[0] = 1; } csw[2] = j; }
+                                               if (overline("CSW", "001", instr)) { if (csw[3] != -1) { csw[0] = 1; } csw[3] = j; }
                                        }
 
                                        if (cx[0]) { ret = "Duplicate `CX` at column " + (i + 1) + "."; break; }
                                                var s = e.getAttribute("pidx").split(",");
                                                s[0] = parseInt(s[0]);
                                                s[1] = parseInt(s[1]);
-                                               var state = ProgramTrack.STATE[s[0]][s[1]].replace(/[\"]/g, "'");
-                                               switch (state)
-                                               {
-                                                       case overline("CX", "10"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CX", "01"); break;
-                                                       case overline("CX", "01"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CX", "10"); break;
-                                                       case overline("SW", "10"):  ProgramTrack.STATE[s[0]][s[1]] = overline("SW", "01"); break;
-                                                       case overline("SW", "01"):  ProgramTrack.STATE[s[0]][s[1]] = overline("SW", "10"); break;
-                                                       case overline("CCX", "100"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CCX", "010"); break;
-                                                       case overline("CCX", "010"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CCX", "001"); break;
-                                                       case overline("CCX", "001"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CCX", "100"); break;
-                                                       case overline("CSW", "100"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CSW", "010"); break;
-                                                       case overline("CSW", "010"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CSW", "001"); break;
-                                                       case overline("CSW", "001"):  ProgramTrack.STATE[s[0]][s[1]] = overline("CSW", "100"); break;
-                                               }
+                                               var state = ProgramTrack.STATE[s[0]][s[1]];
+                                               if (overline("CX", "10", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CX", "01");
+                                               if (overline("CX", "01", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CX", "10");
+                                               if (overline("SW", "10", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("SW", "01");
+                                               if (overline("SW", "01", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("SW", "10");
+                                               if (overline("CCX", "100", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CCX", "010");
+                                               if (overline("CCX", "010", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CCX", "001");
+                                               if (overline("CCX", "001", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CCX", "100");
+                                               if (overline("CSW", "100", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CSW", "010");
+                                               if (overline("CSW", "010", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CSW", "001");
+                                               if (overline("CSW", "001", state)) ProgramTrack.STATE[s[0]][s[1]] = overline("CSW", "100");
                                                var instr = ProgramTrack.STATE[s[0]][s[1]].split("<")[0];
                                                switch (instr)
                                                {