-
Notifications
You must be signed in to change notification settings - Fork 2
/
01_Cirq-Qiskit_QFT.Rmd
106 lines (85 loc) · 1.93 KB
/
01_Cirq-Qiskit_QFT.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
jupyter:
jupytext:
formats: ipynb,Rmd
text_representation:
extension: .Rmd
format_name: rmarkdown
format_version: '1.2'
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
name: python3
---
```{python}
#import necessary packages
import numpy as np
import matplotlib.pyplot as plt
# %config InlineBackend.figure_format = 'svg' # Makes the images look nice
#importing Cirq
import cirq
# importing Qiskit
from qiskit import QuantumCircuit, execute, Aer
from qiskit.circuit import library as lb
from qiskit.visualization import plot_histogram
import sys
sys.path.append("./")
```
# QFT - Cirq
```{python}
from MPS_QFT.gates import cphase_and_swap_cirq
from MPS_QFT.circuit import qft_circuit_swap_cirq
```
```{python}
from MPS_QFT.circuit import qft_circuit_swap_cirq
```
```{python}
N=4
qubits = cirq.LineQubit.range(N)
circuit = qft_circuit_swap_cirq(qubits, [])
print(circuit)
```
```{python}
type(qubits[1])
```
```{python}
ghz = np.zeros(2**N)
ghz[0] = 1
ghz[-1] = 1
ghz = ghz / np.sqrt(2)
```
```{python}
simulator = cirq.Simulator()
result = simulator.simulate(circuit, initial_state=ghz)
print(np.around(result.final_state_vector, 3))
```
# QFT - Qiskit
```{python}
from MPS_QFT.gates import cphase_swap_qiskit
from MPS_QFT.circuit import qft_circuit_qiskit
```
```{python}
qc = QuantumCircuit(4, 4)
qc.x(3)
qft_circuit_qiskit(qc, 4)
qc.measure(np.arange(0, 3), np.arange(0, 3))
qc.draw('mpl')
```
```{python}
simulator = Aer.get_backend('statevector_simulator')
# Execute and get counts
result = execute(qc, simulator).result()
statevector = result.get_statevector(qc)
print(statevector)
```
```{python}
# Select the QasmSimulator from the Aer provider
simulator = Aer.get_backend('qasm_simulator')
# Execute and get counts
result = execute(qc, simulator, shots=10000).result()
counts = result.get_counts()
plot_histogram(counts, title='Bell-State counts')
```
```{python}
```