In [1]:
from qiskit import *
In [2]:
from qiskit.visualization import *
In [3]:
from qiskit.circuit.library import QFT
In [4]:
from numpy import *
In [5]:
backend = BasicAer.get_backend('qasm_simulator')
In [6]:
peT = QuantumCircuit(3)
In [7]:
peT.add_register(QuantumRegister(1,'qr'))
In [ ]:
 
In [8]:
peT.x(3)
Out[8]:
<qiskit.circuit.instructionset.InstructionSet at 0x7f424103fe80>
In [9]:
for qubit in range(3):
    peT.h(qubit)
In [10]:
peT.draw()
Out[10]:
      ┌───┐
 q_0: ┤ H ├
      ├───┤
 q_1: ┤ H ├
      ├───┤
 q_2: ┤ H ├
      ├───┤
qr_0: ┤ X ├
      └───┘
In [11]:
repetitions = 1
In [12]:
for counting_qubit in range(3):
    for i in range(repetitions):
        peT.cp(pi/4, counting_qubit, 3)
    repetitions *= 2
In [13]:
peT.draw()
Out[13]:
      ┌───┐                                                               
 q_0: ┤ H ├─■─────────────────────────────────────────────────────────────
      ├───┤ │                                                             
 q_1: ┤ H ├─┼────────■────────■───────────────────────────────────────────
      ├───┤ │        │        │                                           
 q_2: ┤ H ├─┼────────┼────────┼────────■────────■────────■────────■───────
      ├───┤ │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4) 
qr_0: ┤ X ├─■────────■────────■────────■────────■────────■────────■───────
      └───┘                                                               
In [14]:
qftinv = QFT(3, inverse=True)
In [15]:
qftinv.draw()
Out[15]:
        ┌───┐                                        
q_0: ─X─┤ H ├─■──────────────■───────────────────────
      │ └───┘ │P(-π/2) ┌───┐ │                       
q_1: ─┼───────■────────┤ H ├─┼─────────■─────────────
      │                └───┘ │P(-π/4)  │P(-π/2) ┌───┐
q_2: ─X──────────────────────■─────────■────────┤ H ├
                                                └───┘
In [16]:
qftinv.add_register(QuantumRegister(1,'qr'))
In [17]:
qftinv.add_register(ClassicalRegister(3))
In [18]:
qftinv.draw()
Out[18]:
         ┌───┐                                        
 q_0: ─X─┤ H ├─■──────────────■───────────────────────
       │ └───┘ │P(-π/2) ┌───┐ │                       
 q_1: ─┼───────■────────┤ H ├─┼─────────■─────────────
       │                └───┘ │P(-π/4)  │P(-π/2) ┌───┐
 q_2: ─X──────────────────────■─────────■────────┤ H ├
                                                 └───┘
qr_0: ────────────────────────────────────────────────
                                                      
c0: 3/════════════════════════════════════════════════
                                                      
In [19]:
peT = peT + qftinv
/tmp/ipykernel_9164/1987650100.py:1: DeprecationWarning: The QuantumCircuit.__add__() method is being deprecated.Use the compose() method which is more flexible w.r.t circuit register compatibility.
  peT = peT + qftinv
/home/al/.local/lib/python3.9/site-packages/qiskit/circuit/quantumcircuit.py:869: DeprecationWarning: The QuantumCircuit.combine() method is being deprecated. Use the compose() method which is more flexible w.r.t circuit register compatibility.
  return self.combine(rhs)
In [20]:
peT.draw()
Out[20]:
      ┌───┐                                                                  »
 q_0: ┤ H ├─■──────────────────────────────────────────────────────────────X─»
      ├───┤ │                                                              │ »
 q_1: ┤ H ├─┼────────■────────■────────────────────────────────────────────┼─»
      ├───┤ │        │        │                                            │ »
 q_2: ┤ H ├─┼────────┼────────┼────────■────────■────────■────────■────────X─»
      ├───┤ │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)  │P(π/4)    »
qr_0: ┤ X ├─■────────■────────■────────■────────■────────■────────■──────────»
      └───┘                                                                  »
c0: 3/═══════════════════════════════════════════════════════════════════════»
                                                                             »
«      ┌───┐                                        
« q_0: ┤ H ├─■──────────────■───────────────────────
«      └───┘ │P(-π/2) ┌───┐ │                       
« q_1: ──────■────────┤ H ├─┼─────────■─────────────
«                     └───┘ │P(-π/4)  │P(-π/2) ┌───┐
« q_2: ─────────────────────■─────────■────────┤ H ├
«                                              └───┘
«qr_0: ─────────────────────────────────────────────
«                                                   
«c0: 3/═════════════════════════════════════════════
«                                                   
In [21]:
for i in range(3):
    peT.measure(i,i)
In [22]:
peT.draw(output='mpl')
Out[22]:
In [23]:
t_peT = transpile(peT, backend)
In [24]:
peTobj = assemble(t_peT, shots = 2048)
In [25]:
results = backend.run(peTobj).result()
In [26]:
plot_histogram(results.get_counts())
Out[26]:
In [ ]: