-
Notifications
You must be signed in to change notification settings - Fork 59
/
ch02_03_root_not.py
37 lines (31 loc) · 1019 Bytes
/
ch02_03_root_not.py
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
## Programming Quantum Computers
## by Eric Johnston, Nic Harrigan and Mercedes Gimeno-Segovia
## O'Reilly Media
##
## More samples like this can be found at http://oreilly-qc.github.io
## This sample demonstrates root-of-not.
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer, IBMQ, BasicAer
import math
#%matplotlib inline ## Uncomment this to see diagrams when running in a notebook
## Example 2-3: Root-of-not
# Set up the program
reg = QuantumRegister(1, name='reg')
reg_c = ClassicalRegister(1, name='regc')
qc = QuantumCircuit(reg, reg_c)
qc.reset(reg) # write the value 0
# One root-of-not gate
qc.h(reg)
qc.rz(math.radians(-90), reg)
qc.h(reg)
qc.barrier()
# One root-of-not gate
qc.h(reg)
qc.rz(math.radians(-90), reg)
qc.h(reg)
qc.barrier()
backend = BasicAer.get_backend('statevector_simulator')
job = execute(qc, backend)
result = job.result()
outputstate = result.get_statevector(qc, decimals=3)
print(outputstate)
qc.draw() # draw the circuit