# Code to sample from a quantum circuit in Python or Qiskit

I am trying to implement the following task using Python and Qiskit, but I am not sure of the code that I need to write. The task is as follows.

Input to the code: $$n$$ qubits.

Here is an illustration of the output of the code. For purposes of illustration, let $$n$$ be $$4$$:

• Start from the state $$|0\rangle^{\otimes 4}.$$
• Apply a random two-qubit unitary to qubits $$1$$ and $$2$$, and then to $$3$$ and $$4$$.
• Apply a random two-qubit unitary to qubits $$2$$ and $$3$$.

Measure the output in the standard basis. Do this many times and calculate the probability of $$\mathbb{E}\big[p_{0^{4}}^{2}\big],$$ where the expectation is taken over the random gates and $$p_{0^{4}}$$ is the probability of getting $$0000$$.

For each run of this code, I also want a plot of the probability distribution for each of the $$2^{4}$$ strings possible in the output.

• Please indicate an example of the code and the functions you already know. Have you ever worked with Qiskit? How deep is the answer would depend on this. Jul 15 at 16:34
• I think all the components you need can be found in Qiskit textbook: qiskit.org/textbook/ch-quantum-hardware/… Jul 15 at 16:37