<jupyter_start><jupyter_text>_Modeling of Qubit Chain_  Contributor<NAME>*** The model may be illustrated using images from composer.First image is for one step of quantum walk. Each step uses two partitions described earlier.For five qubits each partition includes two two-qubit gates denoted here as m1 and m2Two (or more) steps of quantum walk should repeat the sequences of gates described above The program below uses QISKit with the similar purposes.Parameter `n_nodes` is used for number of nodes and should be odd due to implementation of partitions.Parameter `n_step` is number of steps.Boolean parameter `hist` provides two method of simulation. The example below uses `hist = True`. In such a case simulator produces probabilities of different outcomes with `qasm_simulator` backend. The `hist = False` uses `statevector_simulator` backend to calculate amplitudes.It may be useful sometimes, but `unitary_simulator` may be more convenient (see link and comments below).<jupyter_code>from pprint import pprint
import math
import numpy as np

# importing the Qiskit
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import Aer, execute
# import state tomography functions
from qiskit.tools.visualization import plot_histogram, plot_state

# Definition of matchgate

def gate_mu3(qcirc,theta,phi,lam,a,b):
    qcirc.cx(a,b)
    qcirc.cu3(theta,phi,lam,b,a)
    qcirc.cx(a,b)
    
# Number of qubits (should be odd)
n_nodes = 5 

# Number of steps
n_step = 2

# Histogram
hist = True
# Quantum Sphere
# hist = False


# Creating Registers
qr = QuantumRegister(n_nodes) 
cr = ClassicalRegister(n_nodes)

# Creating Circuits
qc = QuantumCircuit(qr,cr)

# Initial state
qc.x(qr[0])

# Creating of two partitions with M1' and M2
# Repeating that n_step times

for k in range(0,n_step):
    for i in range(0,n_nodes-1,2):
        gate_mu3(qc,math.pi, math.pi, 0, qr[i], qr[i+1])
    for i in range(1,n_nodes,2):
        gate_mu3(qc,math.pi/2, 0, 0, qr[i], qr[i+1])

if hist:
    for i in range(0,n_nodes):
        qc.measure(qr[i], cr[i])


# To print the circuit  
# QASM_source = qc.qasm()
# print(QASM_source)


if hist:
    backend = 'qasm_simulator' 
    shots = 4096
else:
    backend = 'statevector_simulator' 
    shots = 1   # amplitudes instead of probabilities
    
job = execute(qc, Aer.get_backend(backend), shots = shots ) # Execute quantum walk 
result = job.result()

print(result)<jupyter_output>COMPLETED<jupyter_text>The result of simulation represented below as histogram if `hist=True` (or as Quantum Sphere if `hist=False`)<jupyter_code>if hist:
    plot_histogram(result.get_counts(qc))
else:    
    data_ampl = result.get_data(qc)
    state_walk = data_ampl['statevector']
    rho_walk = np.outer(state_walk,state_walk.conj())
    plot_state(rho_walk,'qsphere')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08736842105263158, 'fraction_numerical': 0.010175438596491228, 'mean_word_length': 4.645544554455445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '70473', 'license': 'Apache-2.0', 'n_tokens_mistral': 971, 'n_tokens_neox': 908, 'n_words': 310, 'path': 'community/awards/teach_me_qiskit_2018/state_distribution_in_qubit_chains/qubit_chain_mod.ipynb', 'repo_name': 'Chibikuri/qiskit-tutorials', 'size': '2864'}