<jupyter_start><jupyter_text><jupyter_code>#!pip install qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer, execute, dagcircuit 
import numpy as np

from qiskit.visualization import plot_histogram
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
"""
we need to input how many steps the quantum system will take in total similar to CRW
if no of qubits is n then then the graph will have 2^(n-1) nodes or points to shift. here the first qubit will play the role of coin as in CRW.
"""
n_steps = 1 #Number of iterations
qubits= QuantumRegister(4, name = 'qubits')
cbits= ClassicalRegister(4, name= 'cbits')

#increment gate
print(len(qubits))
inc = QuantumCircuit (qubits,name='inc') #Circuit for inc operator
inc.rcccx( qubits[0],qubits[1],qubits[2],qubits[3])
inc.ccx(qubits[0],qubits[1],qubits[2])
inc.cx(qubits[0],qubits[1])
inc.draw()














inc= inc.to_instruction()
#decrement gate
dec= QuantumCircuit (qubits,name='dec') #Circuit for dec operator
dec.x(qubits[0])
dec.x(qubits[1])
dec.x(qubits[2])
dec.rcccx( qubits[0],qubits[1],qubits[2],qubits[3])
dec.x(qubits[2])
dec.ccx(qubits[0],qubits[1],qubits[2])
dec.x(qubits[1])
dec.cx(qubits[0],qubits[1])
dec.x(qubits[0])
dec.draw()



dec= dec.to_instruction()
#Main Circuit

circ = QuantumCircuit (qubits, cbits) #Main circuit
#Fixing the coin spin either 0 or 1
#circ.x(qubits[0])

for i in range(n_steps):
 
 circ.h (qubits[0]) #Coin step
 circ.append (inc, [qubits[0],qubits[1],qubits[2],qubits[3]]) #Shift step
 circ.append (dec, [qubits[0],qubits[1],qubits[2],qubits[3]]) #Shift step

circ.measure ([qubits[0],qubits[1],qubits[2],qubits[3]], [cbits[0],cbits[1],cbits[2],cbits[3]])

# Draw the circuit
circ.draw()

simulator = Aer.get_backend('qasm_simulator')
job = execute(circ, simulator, shots=1000)
result = job.result()
counts = result.get_counts(circ)
print("\nTotal counts are:",counts)
# Plot a histogram
plot_histogram(counts)<jupyter_output>Total counts are: {'0011': 494, '1110': 506}
{'fraction_non_alphanumeric': 0.15214180206794684, 'fraction_numerical': 0.032988675529295915, 'mean_word_length': 6.639097744360902, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '462223', 'license': 'MIT', 'n_tokens_mistral': 810, 'n_tokens_neox': 754, 'n_words': 194, 'path': 'qiskit/Random_walk/QRW_Final.ipynb', 'repo_name': 'aryashah2k/QPowerAlgo', 'size': '2031'}