From bf00311fd2b90d8edf23613beeed271dca8b677a Mon Sep 17 00:00:00 2001
From: chaakudaaku
Date: Mon, 28 Sep 2020 16:37:38 +0530
Subject: [PATCH 1/4] Increased z-index
Increased z-index to fix the loss of upper or left edge of operations
---
Q/Q-Circuit-Editor.css | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Q/Q-Circuit-Editor.css b/Q/Q-Circuit-Editor.css
index af97203..be4ee16 100644
--- a/Q/Q-Circuit-Editor.css
+++ b/Q/Q-Circuit-Editor.css
@@ -768,7 +768,7 @@
bottom: 0;
left: 0;
display: block;
- z-index: -10;
+ z-index: 2;
box-shadow:
0 0 1rem rgba( 0, 0, 0, 0.2 ),
0.4rem 0.4rem 0.2rem rgba( 0, 0, 0, 0.2 );
From 68338ca2345a6cdc41fda3afcce56e59b3975074 Mon Sep 17 00:00:00 2001
From: chaakudaaku
Date: Tue, 29 Sep 2020 16:56:19 +0530
Subject: [PATCH 2/4] Feature Completion - Add new Registers and Moments
Now user can add new registers and moments to the circuit directly from the UI. The feature was left incomplete, which has been completed with a caveat. The caveat is that, all the circuits on the website has been named 'playground'. If someone could show how to dynamically pickup name of the circuit then it would make this feature truly complete
---
Q/Q-Circuit-Editor.css | 2 +-
Q/Q-Circuit-Editor.js | 68 ++++++++++++++++++++++++++++++++++++++++--
index.html | 8 ++---
3 files changed, 71 insertions(+), 7 deletions(-)
diff --git a/Q/Q-Circuit-Editor.css b/Q/Q-Circuit-Editor.css
index be4ee16..4e6bc01 100644
--- a/Q/Q-Circuit-Editor.css
+++ b/Q/Q-Circuit-Editor.css
@@ -446,7 +446,7 @@
.Q-circuit-moment-add,
.Q-circuit-register-add {
- display: none;
+ /* display: none; */
}
.Q-circuit-selectall,
.Q-circuit-moment-label,
diff --git a/Q/Q-Circuit-Editor.js b/Q/Q-Circuit-Editor.js
index 4b8549a..2c47725 100644
--- a/Q/Q-Circuit-Editor.js
+++ b/Q/Q-Circuit-Editor.js
@@ -1319,8 +1319,72 @@ Q.Circuit.Editor.onPointerPress = function( event ){
}
if( controlEl ) Q.Circuit.Editor.createControl( circuitEl )
if( swapEl ) Q.Circuit.Editor.createSwap( circuitEl )
- if( addMomentEl ) console.log( '→ Add moment' )
- if( addRegisterEl ) console.log( '→ Add register' )
+
+ function updateCircuitComponents(circuit) {
+
+ // The same block of code which is
+ // used in playground.html to dynamically
+ // update the text block and circuit at the same time.
+
+ if( text !== playgroundInputText ){
+ playgroundInputText = circuit.toText()
+ }
+
+ if( circuit instanceof Q.Circuit ){
+
+ circuit.name = 'playground'
+ const domEl = document.getElementById( 'playground' )
+ const inputEl = document.getElementById( circuit.name +'-input' )
+ if( domEl ){
+
+ while( domEl.lastChild ){
+
+ domEl.removeChild( domEl.lastChild )
+ }
+ circuit.toDom( domEl )
+ }
+ if( inputEl ){
+ inputEl.value = circuit.toText().trimStart()
+ }
+ circuit.evaluate$()
+ }
+ else {
+
+ updateCircuitParts( Q`I` )
+ console.log( 'There’s an error in your circuit!!' )
+ }
+ }
+
+ if( addMomentEl ) {
+
+ // The approach here is to pick up the state of the circuit
+ // using the toText() function and replacing all the line breaks
+ // with -I. Thus increasing the moments for all the registers.
+
+ // Addidtion of "\n" is crucial to get it replaced with '-I' in the nextline
+ text = document.getElementById('playground').circuit.toText() + "\n"
+ text = text.trimStart().replaceAll("\n", "-I\n").trimEnd()
+ const circuit = Q(text)
+ updateCircuitComponents(circuit)
+
+ }
+
+ if( addRegisterEl ) {
+
+ // I took an empty wire and appended with I's equal to timeWidth of the circuit
+ // Need to find a more dynamic approach to this, as this will only work
+ // on the circuits named 'playground'. If someone could help me with this,
+ // it would be just amazing!!
+
+
+ wire = ""
+ timewidth = document.getElementById('playground').circuit.timewidth
+ text = document.getElementById('playground').circuit.toText()
+ for (i = 0; i < timewidth; i++) wire += "I "
+ text += '\n' + wire
+ const circuit = Q(text)
+ updateCircuitComponents(circuit)
+ }
// We’re done dealing with external buttons.
diff --git a/index.html b/index.html
index 1aa2898..4213184 100644
--- a/index.html
+++ b/index.html
@@ -96,13 +96,13 @@
-
+
Live probability results
Edit the code above
and watch the probability results update in realtime.
-
+
Free and open-source
Q is free to use,
@@ -676,8 +676,8 @@
Import and export
I I X#1 I I I
I I I I I I
`
-.setName$( 'example' )
-.toDom( 'example' )
+.setName$( 'playground' )
+.toDom( 'playground' )
.circuit.evaluate$()
From e54483e011cdb0a1a5460845cba62043c9d16129 Mon Sep 17 00:00:00 2001
From: chaakudaaku
Date: Tue, 29 Sep 2020 17:34:19 +0530
Subject: [PATCH 3/4] Fixed the playgroundInputText variable issue
---
Q/Q-Circuit-Editor.js | 4 ----
1 file changed, 4 deletions(-)
diff --git a/Q/Q-Circuit-Editor.js b/Q/Q-Circuit-Editor.js
index 2c47725..cf45afb 100644
--- a/Q/Q-Circuit-Editor.js
+++ b/Q/Q-Circuit-Editor.js
@@ -1326,10 +1326,6 @@ Q.Circuit.Editor.onPointerPress = function( event ){
// used in playground.html to dynamically
// update the text block and circuit at the same time.
- if( text !== playgroundInputText ){
- playgroundInputText = circuit.toText()
- }
-
if( circuit instanceof Q.Circuit ){
circuit.name = 'playground'
From 33fdc4c38b1884402ef4116dbca7abf894110000 Mon Sep 17 00:00:00 2001
From: chaakudaaku
Date: Sun, 4 Oct 2020 21:49:40 +0530
Subject: [PATCH 4/4] Fixed result probabilities on homepage
---
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/index.html b/index.html
index 4213184..f068693 100644
--- a/index.html
+++ b/index.html
@@ -102,7 +102,7 @@ Live probability results
Edit the code above
and watch the probability results update in realtime.
-
+
Free and open-source
Q is free to use,