Difference between revisions of "JQ Manual"
(→H(bit) [Hadamard Gate]) |
|||
(50 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<qu qubits="2" size="50" cols="4" init="0" bits="[0,1]" prog="yes"> | <qu qubits="2" size="50" cols="4" init="0" bits="[0,1]" prog="yes"> | ||
− | [ H(0), CNot(0,1), X(0)] | + | [H(0), CNot(0,1), X(0)] |
</qu> | </qu> | ||
Line 10: | Line 10: | ||
=== 1st input - init state === | === 1st input - init state === | ||
[[File:1st.png]] | [[File:1st.png]] | ||
− | You enter init state of qubits here. | + | You enter the init state of qubits here. A decimal integer is required here. Its binary representation defines the start states of the qubits in qregister. '''Qubit 0 is at the top'''. |
=== 2nd input - qubit signature === | === 2nd input - qubit signature === | ||
[[File:2nd.png]] | [[File:2nd.png]] | ||
− | You enter list of integers here in the following format: [qubit1, qubit2, ..., qubitn]. This qubit signature is used for displaying probabilities. | + | You enter a list of integers here in the following format: [qubit1, qubit2, ..., qubitn]. This qubit signature is used for displaying probabilities. |
− | + | Suppose you have entered [3,4] and that the list of probabilities is: | |
<pre> | <pre> | ||
Line 25: | Line 25: | ||
It simply means that a lot of hypothetical measurements would show that '''Prob(qubit 4 is in state 0 AND qubit 3 is in state 1) = 0.3''' and '''Prob(qubit 4 is in state 1 AND qubit 3 is in state 0) = 0.7'''. | It simply means that a lot of hypothetical measurements would show that '''Prob(qubit 4 is in state 0 AND qubit 3 is in state 1) = 0.3''' and '''Prob(qubit 4 is in state 1 AND qubit 3 is in state 0) = 0.7'''. | ||
− | Formally, | + | Formally, the result is a list of integers with a given probability. The n-th bit of the chosen integer (from the right) represents the state of the qubit which is listed as n-th in the qubit signature (from the left) after the hypothetical measurement. Note these integers are given in binary and in decimal in (). |
+ | |||
+ | The same result for the signature [4,3] would obviously be | ||
+ | <pre> | ||
+ | 01 : 0.7 (1) | ||
+ | 10 : 0.3 (2) | ||
+ | </pre> | ||
===3rd input - quantum circuit=== | ===3rd input - quantum circuit=== | ||
[[File:3rd.png]] | [[File:3rd.png]] | ||
− | You enter a list of quantum gates here in the following format [gate1, gate2, ..., gaten]. You can also add | + | You enter a list of quantum gates here in the following format [gate1, gate2, ..., gaten]. You can also add measurements to this list, they are represented by M(.). |
===Run Button=== | ===Run Button=== | ||
− | + | OK, after you've entered the initial state (if you don't, the default state is 0) and quantum circuit, you press the Run button, which applies the quantum circuit to the qregister and displays the end state and probabilities after a hypothetical measurement of the qubits listed in qubit signature (2nd input). For example: | |
<pre> | <pre> | ||
Line 43: | Line 49: | ||
</pre> | </pre> | ||
− | The first list | + | The first list shows the probabilities described in [[#2nd input - qubit signature|2nd input - qubit signature]] section. The second list is just a state of the qregister (a complex vector). |
===Load Button=== | ===Load Button=== | ||
− | When you create some more complex and long circuit you want to have it in saved text file. You can. Write your circuit in text file using your favorite editor, save it on your drive and then just press '''Load''' to load | + | When you create some more complex and long circuit, you want to have it in a saved text file. You can. Write your circuit in a text file using your favorite editor, save it on your drive and then just press '''Load''' to load it into the Quantum Simulator. |
Doesn't work under IE, so please use some other browser for this feature. | Doesn't work under IE, so please use some other browser for this feature. | ||
Line 62: | Line 68: | ||
<math>H|1\rangle = \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)</math> | <math>H|1\rangle = \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)</math> | ||
− | |||
<qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | <qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | ||
[H(0)] | [H(0)] | ||
Line 78: | Line 83: | ||
[X(0)] | [X(0)] | ||
</qu> | </qu> | ||
+ | |||
=== Y(bit) [Pauli Y-gate] === | === Y(bit) [Pauli Y-gate] === | ||
Line 83: | Line 89: | ||
Defined on base vectors <math>|[bit]\rangle</math>: | Defined on base vectors <math>|[bit]\rangle</math>: | ||
− | <math> | + | <math>Y|0\rangle = i|1\rangle</math> |
− | <math> | + | <math>Y|1\rangle = -i|0\rangle</math> |
<qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | <qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | ||
[Y(0)] | [Y(0)] | ||
</qu> | </qu> | ||
+ | |||
=== Z(bit) [Pauli Z-gate] === | === Z(bit) [Pauli Z-gate] === | ||
Line 95: | Line 102: | ||
Defined on base vectors <math>|[bit]\rangle</math>: | Defined on base vectors <math>|[bit]\rangle</math>: | ||
− | <math> | + | <math>Z|0\rangle = |0\rangle</math> |
− | <math> | + | <math>Z|1\rangle = -|1\rangle</math> |
<qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | <qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | ||
[Z(0)] | [Z(0)] | ||
</qu> | </qu> | ||
+ | |||
=== R(n, bit) [Phase Shift Gate] === | === R(n, bit) [Phase Shift Gate] === | ||
Line 113: | Line 121: | ||
<qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | <qu qubits="1" size="100" cols="1" init="0" bits="[0]" prog="yes"> | ||
[R(2,0)] | [R(2,0)] | ||
+ | </qu> | ||
+ | |||
+ | |||
+ | === Sw(bit1, bit2) [Swap Gate] === | ||
+ | |||
+ | Defined on base vectors <math>|[bit2][bit1]\rangle</math>: | ||
+ | |||
+ | <math>Sw|00\rangle = |00\rangle</math> | ||
+ | |||
+ | <math>Sw|01\rangle = |10\rangle</math> | ||
+ | |||
+ | <math>Sw|10\rangle = |01\rangle</math> | ||
+ | |||
+ | <math>Sw|11\rangle = |10\rangle</math> | ||
+ | <qu qubits="2" size="100" cols="1" init="0" bits="[0,1]" prog="yes"> | ||
+ | [Sw(0,1)] | ||
</qu> | </qu> | ||
Line 126: | Line 150: | ||
<math>CNot|11\rangle = |10\rangle</math> | <math>CNot|11\rangle = |10\rangle</math> | ||
− | |||
− | |||
<qu qubits="2" size="100" cols="1" init="0" bits="[0,1]" prog="yes"> | <qu qubits="2" size="100" cols="1" init="0" bits="[0,1]" prog="yes"> | ||
[CNot(1,0)] | [CNot(1,0)] | ||
Line 140: | Line 162: | ||
[CCNot(2,1,0)] | [CCNot(2,1,0)] | ||
</qu> | </qu> | ||
+ | |||
=== C(control, gate) [Universal Control Gate] === | === C(control, gate) [Universal Control Gate] === | ||
Line 145: | Line 168: | ||
Defined on base vectors <math>|[control]x\rangle</math>: | Defined on base vectors <math>|[control]x\rangle</math>: | ||
− | <math>C( | + | <math>C(gate)(|0\rangle|x\rangle) = |0\rangle|x\rangle</math> |
− | <math>C( | + | <math>C(gate)(|1\rangle|x\rangle) = |0\rangle gate|x\rangle</math> |
− | + | <qu qubits="2" size="50" cols="1" init="0" bits="[0,1]" prog="yes"> | |
− | <qu qubits=" | + | |
[C(1,H(0))] | [C(1,H(0))] | ||
</qu> | </qu> | ||
+ | |||
=== U([argbit<sub>0</sub>, ...,argbit<sub>n</sub>],[valbit<sub>0</sub>, ...,valbit<sub>m</sub>], function) [Universal Function Gate] === | === U([argbit<sub>0</sub>, ...,argbit<sub>n</sub>],[valbit<sub>0</sub>, ...,valbit<sub>m</sub>], function) [Universal Function Gate] === | ||
Line 158: | Line 181: | ||
<math>U_{function}|x\rangle|y\rangle = |x\rangle|y \oplus function(x)\rangle</math> | <math>U_{function}|x\rangle|y\rangle = |x\rangle|y \oplus function(x)\rangle</math> | ||
− | + | <qu qubits="7" size="40" cols="2" init="16" bits="[0,1,2,3,4,5,6]" prog="yes"> | |
− | <qu qubits="7" size="40" cols="2" init=" | + | |
[U([4,5,6],[0,1,2,3], function(x){return 2*x;})] | [U([4,5,6],[0,1,2,3], function(x){return 2*x;})] | ||
</qu> | </qu> | ||
+ | |||
+ | == Hidden Console == | ||
+ | |||
+ | [[File:Console.png]] | ||
+ | |||
+ | jQ has an additional advanced feature — Hidden Console. When you place the cursor in the last line of the black window in the left you can enter some special directives. | ||
+ | Bellow you will find a full list of Hidden Console directives: | ||
+ | |||
+ | === clr() === | ||
+ | |||
+ | Clears window. | ||
+ | |||
+ | ===load()=== | ||
+ | |||
+ | The same as button Load. | ||
+ | |||
+ | === measure(bit) === | ||
+ | |||
+ | Performs a measurement on a chosen bit. To see the result, you need to type '''<nowiki>prob([[bit]])</nowiki>'''. Changes the qregister state. | ||
+ | |||
+ | === prob([signature<sub>1</sub>, signature<sub>2</sub>, ..., signature<sub>n</sub>]) === | ||
+ | |||
+ | Displays the states of chosen qubits with probabilities after a series of hypothetical measurements. Doesn't change the qregister state. The value of state is binary grouped. Each group is defined by corresponding signature. | ||
+ | Consider following example. Assume that the qregister state is: | ||
+ | |||
+ | <pre> | ||
+ | (0.5,0)|0> | ||
+ | (0.5,0)|1> | ||
+ | (0.5,0)|4> | ||
+ | (0.5,0)|5> | ||
+ | </pre> | ||
+ | |||
+ | The corresponding probabilities are: | ||
+ | |||
+ | <pre> | ||
+ | 000 : 0.25 (0) | ||
+ | 001 : 0.25 (1) | ||
+ | 100 : 0.25 (4) | ||
+ | 101 : 0.25 (5) | ||
+ | </pre> | ||
+ | |||
+ | After typing in Hidden Console '''prob( [ [0], [1,2] ] )''' | ||
+ | |||
+ | You will see the same result in different representation: | ||
+ | |||
+ | <pre> | ||
+ | |0>|0>:0.25 | ||
+ | |0>|1>:0.25 | ||
+ | |2>|0>:0.25 | ||
+ | |2>|1>:0.25 | ||
+ | </pre> | ||
+ | |||
+ | For '''prob( [ [0,1], [2] ])''': | ||
+ | |||
+ | <pre> | ||
+ | |0>|0>:0.25 | ||
+ | |0>|1>:0.25 | ||
+ | |1>|0>:0.25 | ||
+ | |1>|1>:0.25 | ||
+ | </pre> | ||
+ | |||
+ | ===reset(n)=== | ||
+ | |||
+ | Set the initial state of qregister to n. | ||
+ | |||
+ | ===run()=== | ||
+ | |||
+ | The same as the Run button. | ||
+ | |||
+ | ===state()=== | ||
+ | |||
+ | Displays current state (complex vector) of qregister. | ||
+ | |||
+ | ===version()=== | ||
+ | |||
+ | Displays current version of jQ. | ||
+ | |||
+ | = Embeding jQ in your own webpage = | ||
+ | |||
+ | You can embed jQ in your own webpage. It's really easy. It is enough to place the following HTML code in your page | ||
+ | |||
+ | <pre> | ||
+ | <div class="_jq"></div> | ||
+ | </pre> | ||
+ | |||
+ | followed by | ||
+ | |||
+ | <pre> | ||
+ | <script src="http://qugate.org/jQ/jQ.js"></script> | ||
+ | </pre> | ||
+ | |||
+ | somwhere at the end of your page. | ||
+ | All together should look like that: | ||
+ | |||
+ | <pre> | ||
+ | <body> | ||
+ | |||
+ | ... | ||
+ | |||
+ | <div class="_jq"></div> | ||
+ | |||
+ | ... | ||
+ | |||
+ | <script src="http://qugate.org/jQ/jQ.js"></script> | ||
+ | </body> | ||
+ | </pre> | ||
+ | |||
+ | You can embed as many <nowiki><div class="_jq"></div></nowiki> as you need, but you must place <nowiki><script src="http://qugate.org/jQ/jQ.js"></nowiki> below all of them in HTML code. | ||
+ | |||
+ | If you want to place a qunatum circiut in your jQ, you just do the following | ||
+ | |||
+ | <pre> | ||
+ | <div class="_jq"> | ||
+ | <!-- | ||
+ | [ H(0), H(1), H(2), U([0,1,2],[3,4,5], function(x) {return Math.pow(7,x)%8; }, 'f'), H(2), C(1,R(1,2)), C(0, R(2,2)), H(1), C(0, R(1,1)), H(0) ] | ||
+ | --> | ||
+ | </div> | ||
+ | </pre> | ||
+ | |||
+ | === Supported attributes === | ||
+ | |||
+ | jQ div supports a few special attributes: | ||
+ | |||
+ | *'''data-jq-height''' — [int] height of qunatum circuit space in px (default: auto) | ||
+ | *'''data-jq-width''' — [int] width of qunatum circuit space in px(default: auto) | ||
+ | *'''data-jq-qubits''' — [int] number of qubits (default: 8) | ||
+ | *'''data-jq-bits''' — [array] list of numbers like in 2nd input (default: [0]) | ||
+ | *'''data-jq-size''' — [int] size of one qugate space in px (default: 50) | ||
+ | *'''data-jq-cols''' — [int] number of columns in qunatum circuit space (default: 10) | ||
+ | *'''data-jq-init''' - [int] intial value of qregister | ||
+ | *'''data-jq-prog''' - [string: yes|no] if data-jq-prog="yes" the 3rd input is displayed (default: yes) | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <pre> | ||
+ | <div class="_jq" data-jq-qubits="8" data-jq-bits="[0,1,2,3]" data-jq-size="40" data-jq-init="16" data-jq-prog="no"></div> | ||
+ | </pre> | ||
+ | |||
+ | ===License=== | ||
+ | Although jQ design and code remains my propriety and is copyrighted, I (Michal Stanislaw Wojcik) give you a permission (free of any charge) to embed jQ in your webpage, as defined in the above instruction, under the following conditions: | ||
+ | |||
+ | 1. You will use jQ code only as linked from location http://qugate.org/jQ/jQ.js in the form: <nowiki><script src="http://qugate.org/jQ/jQ.js"></script></nowiki> | ||
+ | |||
+ | 2. The link to gugate.org in jQ must be visible and clickable and must direct to qugate.org. | ||
+ | |||
+ | 3. You will not impose any charge in any form on using jQ on your website. It must be free for all of your users. | ||
+ | |||
+ | If my allowance for any case of usage in not clear from the above license, it is considered as prohibited. If you have any questions related to the following licence please email me: [[File:12573181.Png]] |
Latest revision as of 14:54, 1 July 2014
[edit] Quick Overview
For quick start, please note 3 inputs. We we will name them: 1st, 2nd and 3rd — from left to right. Please also note 2 buttons: Run and Load.
[edit] 1st input - init state
You enter the init state of qubits here. A decimal integer is required here. Its binary representation defines the start states of the qubits in qregister. Qubit 0 is at the top.
[edit] 2nd input - qubit signature
You enter a list of integers here in the following format: [qubit1, qubit2, ..., qubitn]. This qubit signature is used for displaying probabilities.
Suppose you have entered [3,4] and that the list of probabilities is:
01 : 0.3 (1) 10 : 0.7 (2)
It simply means that a lot of hypothetical measurements would show that Prob(qubit 4 is in state 0 AND qubit 3 is in state 1) = 0.3 and Prob(qubit 4 is in state 1 AND qubit 3 is in state 0) = 0.7.
Formally, the result is a list of integers with a given probability. The n-th bit of the chosen integer (from the right) represents the state of the qubit which is listed as n-th in the qubit signature (from the left) after the hypothetical measurement. Note these integers are given in binary and in decimal in ().
The same result for the signature [4,3] would obviously be
01 : 0.7 (1) 10 : 0.3 (2)
[edit] 3rd input - quantum circuit
You enter a list of quantum gates here in the following format [gate1, gate2, ..., gaten]. You can also add measurements to this list, they are represented by M(.).
[edit] Run Button
OK, after you've entered the initial state (if you don't, the default state is 0) and quantum circuit, you press the Run button, which applies the quantum circuit to the qregister and displays the end state and probabilities after a hypothetical measurement of the qubits listed in qubit signature (2nd input). For example:
01 : 0.5 (1) 10 : 0.5 (2) (0.707106781187,0)|1> (0.707106781187,0)|2>
The first list shows the probabilities described in 2nd input - qubit signature section. The second list is just a state of the qregister (a complex vector).
[edit] Load Button
When you create some more complex and long circuit, you want to have it in a saved text file. You can. Write your circuit in a text file using your favorite editor, save it on your drive and then just press Load to load it into the Quantum Simulator.
Doesn't work under IE, so please use some other browser for this feature.
[edit] Specification
[edit] Supported gates
[edit] H(bit) [Hadamard Gate]
Defined on base vectors :
[edit] X(bit) [Pauli X-gate]
Defined on base vectors :
[edit] Y(bit) [Pauli Y-gate]
Defined on base vectors :
[edit] Z(bit) [Pauli Z-gate]
Defined on base vectors :
[edit] R(n, bit) [Phase Shift Gate]
Defined on base vectors :
[edit] Sw(bit1, bit2) [Swap Gate]
Defined on base vectors :
[edit] CNot(control, bit) [Controled Not Gate]
Defined on base vectors :
[edit] CCNot(control1, control2, bit) [Toffoli Gate]
Defined on base vectors :
[edit] C(control, gate) [Universal Control Gate]
Defined on base vectors :
[edit] U([argbit0, ...,argbitn],[valbit0, ...,valbitm], function) [Universal Function Gate]
Defined on base vectors :
[edit] Hidden Console
jQ has an additional advanced feature — Hidden Console. When you place the cursor in the last line of the black window in the left you can enter some special directives. Bellow you will find a full list of Hidden Console directives:
[edit] clr()
Clears window.
[edit] load()
The same as button Load.
[edit] measure(bit)
Performs a measurement on a chosen bit. To see the result, you need to type prob([[bit]]). Changes the qregister state.
[edit] prob([signature1, signature2, ..., signaturen])
Displays the states of chosen qubits with probabilities after a series of hypothetical measurements. Doesn't change the qregister state. The value of state is binary grouped. Each group is defined by corresponding signature. Consider following example. Assume that the qregister state is:
(0.5,0)|0> (0.5,0)|1> (0.5,0)|4> (0.5,0)|5>
The corresponding probabilities are:
000 : 0.25 (0) 001 : 0.25 (1) 100 : 0.25 (4) 101 : 0.25 (5)
After typing in Hidden Console prob( [ [0], [1,2] ] )
You will see the same result in different representation:
|0>|0>:0.25 |0>|1>:0.25 |2>|0>:0.25 |2>|1>:0.25
For prob( [ [0,1], [2] ]):
|0>|0>:0.25 |0>|1>:0.25 |1>|0>:0.25 |1>|1>:0.25
[edit] reset(n)
Set the initial state of qregister to n.
[edit] run()
The same as the Run button.
[edit] state()
Displays current state (complex vector) of qregister.
[edit] version()
Displays current version of jQ.
[edit] Embeding jQ in your own webpage
You can embed jQ in your own webpage. It's really easy. It is enough to place the following HTML code in your page
<div class="_jq"></div>
followed by
<script src="http://qugate.org/jQ/jQ.js"></script>
somwhere at the end of your page. All together should look like that:
<body> ... <div class="_jq"></div> ... <script src="http://qugate.org/jQ/jQ.js"></script> </body>
You can embed as many <div class="_jq"></div> as you need, but you must place <script src="http://qugate.org/jQ/jQ.js"> below all of them in HTML code.
If you want to place a qunatum circiut in your jQ, you just do the following
<div class="_jq"> <!-- [ H(0), H(1), H(2), U([0,1,2],[3,4,5], function(x) {return Math.pow(7,x)%8; }, 'f'), H(2), C(1,R(1,2)), C(0, R(2,2)), H(1), C(0, R(1,1)), H(0) ] --> </div>
[edit] Supported attributes
jQ div supports a few special attributes:
- data-jq-height — [int] height of qunatum circuit space in px (default: auto)
- data-jq-width — [int] width of qunatum circuit space in px(default: auto)
- data-jq-qubits — [int] number of qubits (default: 8)
- data-jq-bits — [array] list of numbers like in 2nd input (default: [0])
- data-jq-size — [int] size of one qugate space in px (default: 50)
- data-jq-cols — [int] number of columns in qunatum circuit space (default: 10)
- data-jq-init - [int] intial value of qregister
- data-jq-prog - [string: yes|no] if data-jq-prog="yes" the 3rd input is displayed (default: yes)
Example:
<div class="_jq" data-jq-qubits="8" data-jq-bits="[0,1,2,3]" data-jq-size="40" data-jq-init="16" data-jq-prog="no"></div>
[edit] License
Although jQ design and code remains my propriety and is copyrighted, I (Michal Stanislaw Wojcik) give you a permission (free of any charge) to embed jQ in your webpage, as defined in the above instruction, under the following conditions:
1. You will use jQ code only as linked from location http://qugate.org/jQ/jQ.js in the form: <script src="http://qugate.org/jQ/jQ.js"></script>
2. The link to gugate.org in jQ must be visible and clickable and must direct to qugate.org.
3. You will not impose any charge in any form on using jQ on your website. It must be free for all of your users.
If my allowance for any case of usage in not clear from the above license, it is considered as prohibited. If you have any questions related to the following licence please email me: