from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from math import pi
def cpc(n):
= QuantumCircuit(n, name=' CPC')
qc for k in range(1, n):
/(2**k), n-1, n-1-k)
qc.cp(pireturn qc
5).draw(output='mpl', reverse_bits=True) cpc(
def rev(n):
= QuantumCircuit(n, name=' Rev')
qc for i in range(n//2):
-i-1)
qc.swap(i, nreturn qc
7).draw(output='mpl', reverse_bits=True) rev(
def qft(n):
= QuantumCircuit(n, name=f' QFT')
qc -1)
qc.h(nif n == 1:
return qc
range(n))
qc.append(cpc(n), -1), range(n-1))
qc.append(qft(n-1), range(n-1))
qc.append(rev(nrange(n))
qc.append(rev(n),
return qc
5).draw(output='mpl', reverse_bits=True, style={
qft("displaycolor": {
" Rev": [ # gate name
"#555555", # box color (grey)
"#FFFFFF" # box text color (white)
]," QFT": [ # gate name
"#da1e28", # box color (red)
"#FFFFFF" # box text color (white)
], }})
from qiskit import Aer, execute, transpile
# Run the quantum circuit on a statevector simulator backend
#backend = Aer.get_backend('statevector_simulator')
# create circuit with measurement
= 2
n = QuantumCircuit(n, n-1)
circ
= QuantumCircuit(n)
qc # qc.y(0)
range(n))
circ.append(qc, range(1,n), range(n-1))
circ.measure(='mpl', reverse_bits=True) circ.draw(output
from qiskit import Aer, transpile, QuantumCircuit
= QuantumCircuit(2)
circ 0)
circ.h(
circ.measure_all()
# Transpile for simulator
= Aer.get_backend('aer_simulator')
simulator = transpile(circ, simulator)
circ
# Run and get counts
= simulator.run(circ).result()
result = result.get_counts(circ)
counts print(counts)
import qiskit.tools.jupyter
%qiskit_version_table
Version Information
Qiskit Software | Version |
---|---|
qiskit-terra | 0.22.3 |
qiskit-aer | 0.11.2 |
qiskit-ibmq-provider | 0.19.2 |
qiskit | 0.39.3 |
System information | |
Python version | 3.9.12 |
Python compiler | Clang 12.0.0 |
Python build | main, Apr 5 2022 01:53:17 |
OS | Darwin |
CPUs | 8 |
Memory (Gb) | 8.0 |
Mon Dec 12 12:27:38 2022 MST |