Instantly share code, notes, and snippets.

# zabirauf/qc_for_cs_notebook.html

Created January 10, 2021 06:06
Julia notebook for "Quantum computing for Computer scientist"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 ⚡ Pluto.jl ⚡

Quantum Computing

40.8 μs
1.6 ms
3.4 ms
8.1 μs

In this notebook we will be going over the lecture and creating some necessary functions and math to play around with qbits and operations for it. Feel free to play around and change variable or apply operations to see what actually happens.

5.7 μs

Definitions of qubits and other concepts

10.2 μs

Defining classical bits

6.8 μs
cb_0
1.2 μs
cb_1
1.5 μs

Basic operation on classical bits

6.4 μs
const_one (generic function with 1 method)
42.5 μs
3.0 μs

Reversible computing

If you know the result and the operation then you can reverse it to get the original input. For example in above negation is a reversible function as if you negate twice then you get the original input. On the other hand things that remove state/info are not reversible e.g. const_one always sets to one so you can't know what the original input can be.

Quantum computing only uses reversible operations.

Fun fact: All quantum operations are their own inverses.

9.0 μs
36.4 ms

Tensor product

7.5 μs

Currently I'm using the library Tensors which has the \otimes [/itex] operation which indicates a tensor product. It changes the dimensions of the vector and the left matrix multiply with all on the right.

6.8 μs
kron (generic function with 32 methods)
42.0 ns
1.4 μs
1.9 μs
1.7 μs

Multiple classic bits can be represented using tensor product e.g.

5.4 μs
cb_00
27.7 μs
cb_01
3.2 μs
cb_10
3.0 μs
cb_11
3.3 μs

Hence to represent any classic bit as the vector, we can take tensor product e.g.

6.6 μs
3.2 μs
3.6 μs

Defining the control not operation

6.1 μs

Similar to how in classic computing NAND gate is like the universal gate which you can use to construct all other gates, for reversible operations CNOT does something similar.

Though it's not totally universal as there are some gates which need the Toffoli gate to build.

8.0 μs
control_not (generic function with 1 method)
20.4 μs
3.1 μs
3.6 ms

Defining QBits and superposition

6.6 μs

All along we have been using qbits. The cbit vectors we have been using are just special cases of qbits.

A qbit is represented by (ab)[/itex] where a[/itex] and b[/itex] are complext number and it holds this property

a2+b2=1[/itex]

The cbits also satisfy this property along with a lot of other varients e.g.

(1212)122+122=1[/itex]

(1232)122+322=1[/itex] (10)12+02=1[/itex]

(1212)122+122=1[/itex]

9.5 μs

As both a[/itex] and b[/itex] can be non zero e.g. (1212)[/itex] so that is an example of superposition. When we measure they collapse to a known value we generally see in cbits. (ab)[/itex] collapses to 0[/itex] with probability a2[/itex] and collapses to 1[/itex] with probability b2[/itex]

11.6 μs

4.3 μs

Similar to cbits, multiple qbits are also represented by tensor product [/itex]

7.0 μs
3.6 μs

The above also shows that there is 14[/itex] probability of collapsing to |00,|01,|10,|11[/itex]

6.9 μs

The rule we had can hold for any probability state representing qbit e.g.

(abn)a2+b2n2=1[/itex]

7.9 μs
sum_quantum_state (generic function with 1 method)
27.8 μs

6.3 μs

Hadamard is a special gate which takes in the classic bit i.e. qbit in a state |0[/itex] or |1[/itex] and then puts it into superposition. The mathematical representation of it is

(12121212)(ab)[/itex]

(12121212)(10)=(1212)[/itex]

and for |1[/itex] this leads to

(12121212)(01)=(1212)[/itex]

The reason we have 1[/itex] in the last element is so that we can differentiate when running the hadamard gate from |0[/itex] or |1[/itex] and make it a reversible operation. This is also representative of what happens in real world as the state of when running the gate through |0[/itex] or |1[/itex] is different and that info is carried on to further operations.

12.3 μs
hadamard (generic function with 1 method)
6.2 ms
2.7 ms
22.6 μs

As it's reversible so you can go from superposition back to out of superposition and without measurement.

6.8 μs
2.0 ms
4.1 μs

You can also compose Hadamard operation to process bigger states e.g. for 2[/itex] and 3[/itex] qubits

6.7 μs
2.6 μs
Float641
0.353553
2
-0.353553
3
-0.353553
4
0.353553
5
0.353553
6
-0.353553
7
-0.353553
8
0.353553
4.4 μs
20.2 μs
749 ns

The Deutsch oracle

5.1 μs
8.4 μs

For the basic operations that we descrived earlier i.e. identity, negation, constant-0 and constant-1 if we had a blackbox which contained either of those and we can input something and see only its output then how would we know what function is in there?

In classical computing we would have to pass in first 0, see its output and then pass in 1, see its output to figure out. In quantum its the same as the state space required 2 bits to differentiate between 4 different functions.

If the question becomes that see if it has a constant function or variable (i.e. identity or negation), now the state we need to distinguish are 2 requiring 1 bit. In this case classical computing still needs two operations but quantum computing needs only one operation. This is what the power of quantum computing is.

Though the problem is that as in quantum would we can only work with operations that are reversible so how would we solve that for constant functions. The way is to pass in two wires one marked as output which the blackbox will write the output to and the other as input which the blackbox can use but it won't change. In this way you always know what the input was and the operation so you have a reversible operations.

10.6 μs
blackbox_cnot
8.9 μs
17.1 μs

This example might be contrived but somebody found the generallization of it where for n[/itex] bits in classical computer we would need to perform 2n[/itex] operations but in quantum computing we can limit it to only few operations to figure it out. This leads to more foundation building and eventually also help build the Shor's algorithm.

10.1 μs

Quantum entaglement

5.6 μs

If the product state of 2[/itex] qbits can't be factored then they are considred to be entangled.

Following is an example where it can't be factored as you can take the ad=0[/itex] and for that to be right either a=0[/itex] or d=0[/itex] but that will invalidate the other values hence it can't be factored.

7.8 μs

As in the following product state

(120012)[/itex]

As for the above there is 50%[/itex] probability for it to be in state |00[/itex] or |11[/itex] which means when measured both the qbits will have the exact same value i.e. 0[/itex] or 1[/itex].

The following is how to put two qbits into entangled state

9.6 μs
entangle (generic function with 1 method)
20.5 μs
10.8 μs

Quantum teleportation

7.4 μs

Quantum teleportation allows you to send the state of an arbitrary qbit from one location to another by way of two other entangled qbits. You can transfer qbit states (cut and paste) but not clone them and it is called no-cloning theorem.

The teleportation is not faster-than-light because some classical information must be sent.

Question: If classical information must be sent then what's the use?

6.6 μs