# imports
import numpy as np
from qiskit import QuantumRegister, QuantumCircuit

####################################
#  Depolarizing channel on IBMQX2  #
####################################

# Quantum register
q = QuantumRegister(4, name="q")

# Quantum circuit
depolarizing = QuantumCircuit(q)

# Depolarizing channel acting on q_2
## Qubit identification
system = 0
a_0 = 1
a_1 = 2
a_2 = 3

## Define rotation angle
theta = 0.0

## Construct circuit
depolarizing.ry(theta, q[a_0])
depolarizing.ry(theta, q[a_1])
depolarizing.ry(theta, q[a_2])
depolarizing.cx(q[a_0], q[system])
depolarizing.cy(q[a_1], q[system])
depolarizing.cz(q[a_2], q[system])

# Draw circuit
depolarizing.draw(output='mpl')

def depolarizing_channel(q, p, system, ancillae):
    """Returns a QuantumCircuit implementing depolarizing channel on q[system]
    
    Args:
        q (QuantumRegister): the register to use for the circuit
        p (float): the probability for the channel between 0 and 1
        system (int): index of the system qubit
        ancillae (list): list of indices for the ancillary qubits
        
    Returns:
        A QuantumCircuit object
    """
    
    # Write the code here...

# Let's fix the quantum register and the qubit assignments

# We create the quantum circuit
q = QuantumRegister(5, name='q')

# Index of the system qubit
system = 2

# Indices of the ancillary qubits
ancillae = [1, 3, 4]

# For example, let's consider 10 equally spaced values of p
p_values = np.linspace(0, 1, 10)