ashutosh1919 commited on
Commit
8a8c32e
1 Parent(s): 9e01caf
Files changed (4) hide show
  1. .DS_Store +0 -0
  2. .gitignore +1 -0
  3. README.md +98 -1
  4. images/checkboard_626.png +0 -0
.DS_Store DELETED
Binary file (6.15 kB)
 
.gitignore CHANGED
@@ -1,6 +1,7 @@
1
  # Extra
2
  flagged
3
  wandb
 
4
 
5
  # Byte-compiled / optimized / DLL files
6
  __pycache__/
 
1
  # Extra
2
  flagged
3
  wandb
4
+ .DS_Store
5
 
6
  # Byte-compiled / optimized / DLL files
7
  __pycache__/
README.md CHANGED
@@ -12,4 +12,101 @@ license: apache-2.0
12
 
13
  # Quantum Perceptron
14
 
15
- Implementation of Quantum Perceptron: An Artificial Neuron Implemented on an Actual Quantum Processor.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Quantum Perceptron
14
 
15
+ [![Python Version](https://img.shields.io/badge/python->=3.8-blue.svg?style=flat-square)](#python) [![Price](https://img.shields.io/badge/price-free-ff69b4.svg?style=flat-square)](#price) [![Maintained](https://img.shields.io/badge/maintained-yes-green.svg?style=flat-square)](#maintained)
16
+
17
+ **Implementation of Quantum Perceptron: An Artificial Neuron Implemented on an Actual Quantum Processor.**
18
+
19
+ This project implements McCullogh-Pitts Perceptron as described in [An Artificial Neuron Implemented on an Actual Quantum Processor](https://arxiv.org/abs/1811.02266) on IBM's [Qiskit](https://qiskit.org/) quantum simulator.
20
+
21
+ The repository contains the extensive codebase to create quantum perceptron circuit based on specific weight and input data. Moreover, we created training data as shown in the paper (checkboard patterns for different numbers) and simulated the training using single perceptron to update the weight. You can have a look at perceptron training in [`TrainPerceptron.ipynb`](./TrainPerceptron.ipynb). We have used training details from [this article on nature](https://www.nature.com/articles/s41534-019-0140-4) by the authors of the original paper.
22
+
23
+ Moreover, the authors of the paper evaluates single perceptron for different weight-input pairs and generate visualization. They prove that the probability (output of perceptron) is 1 when `weight = input`. We have simulated the same thing and created visualization in [`PerceptronSimulator.ipynb`](./PerceptronSimulator.ipynb).
24
+
25
+
26
+ ## Usage
27
+
28
+ We have created the codebase such that the perceptron circuit can be utilized directly for any other usage. The code is scalable and takes the most possibilities into account. Note that we are deliberately raising error in case the perceptron with more than 9 qubits is initialized.
29
+
30
+ To use the perceptron, you will need to clone this repository and add the repository directory to `$PATH`:
31
+
32
+ ```bash
33
+ git clone https://github.com/ashutosh1919/quantum-perceptron.git
34
+ export PATH=./quantum_perceptron:$PATH
35
+ ```
36
+
37
+ Now, you can use the perceptron codebase in your own project. To get started with experimenting on quantum perceptron, you can use below starter code:
38
+
39
+ ```python
40
+ from quantum_perceptron import Perceptron
41
+ from quantum_perceptron.utils import (
42
+ calculate_succ_probability,
43
+ plot_img_from_data
44
+ )
45
+
46
+ # Define perceptron initial parameter
47
+ num_qubits = 4
48
+ input_data = 12
49
+ weight_data = 626
50
+
51
+ # You can visualize input/weight data in checkboard pattern
52
+ plot_img_from_data(
53
+ data=weight,
54
+ num_qubits=num_qubits
55
+ )
56
+
57
+ # Intialize perceptron object
58
+ perceptron = Perceptron(
59
+ num_qubits=num_qubits,
60
+ weight=weight_data,
61
+ input=input
62
+ )
63
+
64
+ # Generate measurement outcomes for 3000 number of iterations
65
+ counts = perceptron.measure_circuit(
66
+ num_iters=3000
67
+ )
68
+
69
+ # Find the success probability (Number of 1s)/(Total iterations)
70
+ prob = calculate_succ_probability(counts)
71
+
72
+ # Draw circuit
73
+ perceptron.save_circuit_image(
74
+ file_path='qubit_4_circ.png',
75
+ output_format="mpl"
76
+ )
77
+ ```
78
+
79
+ The checkboard pattern image generated by the above code will look something like this:
80
+
81
+ ![](./images/checkboard_626.png)
82
+
83
+ The saved image for the perceptron circuit of 4 qubits looks something like this:
84
+
85
+ ![](./images/circuit_4qubit.png)
86
+
87
+ In the above circuit, we can see two components `U_i` and `U_w`. These components are specifically to process input and weight data values respectively. The circuit is different for different values of input and weight. For more information, please take a look at the descriptions in the paper. For implementation, you can take a look at [`perceptron.py`](./quantum_perceptron/perceptron.py).
88
+
89
+
90
+ ## Reference
91
+
92
+ An Artificial Neuron Implemented on an Actual Quantum Processor -- https://arxiv.org/abs/1811.02266
93
+
94
+ ```
95
+ @article{Tacchino_2019,
96
+ doi = {10.1038/s41534-019-0140-4},
97
+ url = {https://doi.org/10.1038%2Fs41534-019-0140-4},
98
+ year = 2019,
99
+ month = {mar},
100
+ publisher = {Springer Science and Business Media {LLC}
101
+ },
102
+ volume = {5},
103
+ number = {1},
104
+ author = {Francesco Tacchino and Chiara Macchiavello and Dario Gerace and Daniele Bajoni},
105
+ title = {An artificial neuron implemented on an actual quantum processor},
106
+ journal = {npj Quantum Information}
107
+ }
108
+ ```
109
+
110
+ ## License
111
+
112
+ See the [LICENSE](LICENSE) file.
images/checkboard_626.png ADDED