0
$\begingroup$

Let's say we are given two probability values $p_1 > 0$ and $p_2 > 0$, with $p_1+p_2 \leq 1$ but not necessarily equals to $1$. We are asked to create a 2-qubit quantum circuit with state $|01\rangle$ probability as $p_1$ and state $|10\rangle$ probability as $p_2$. How to approach this type of problems? I think entanglement would help here but not sure how to come up with exact probabilities.

Also, is there a way to generalize this (e.g., build a n-qubit quantum circuit from given $k$ probabilities exactly for $k$ out of its $2^n$ superposition states)?

$\endgroup$
2
  • $\begingroup$ Do you mean your qubits are initialized in the all $|0\rangle$ state? $\endgroup$
    – Will Yang
    May 6, 2022 at 22:29
  • $\begingroup$ Yes I assumed that pre-condition $\endgroup$ May 7, 2022 at 17:59

2 Answers 2

2
$\begingroup$

Qiskit has a function which initializes a circuit to a certain given state:

https://qiskit.org/documentation/stubs/qiskit.extensions.Initialize.html

The paper that they use to implement the code apparently is:

https://arxiv.org/abs/quant-ph/0406176v5

A small example of code to implement the function is:


from qiskit.circuit import QuantumCircuit
from qiskit.circuit import QuantumRegister

nbqbits = 2 # Number of qubits

qr = QuantumRegister(nbqbits)
qc = QuantumCircuit(qr)


##In psi_0 you define the amplitudes of the state. These amplitudes are the square root
## of the probabilites you want to get for each state.

## Each state of the computational basis binary(i) get the amplitude psi_0[i], i.e:
## The state |00> get the amplitude psi_0[0]
## The state |01> get the amplitude psi_0[1]
## and so on.

psi_0 = [1, 2, 3, 4] # This state is not yet normalized

psi_0 = psi_0/np.linalg.norm(psi_0) # Normalization of the state

qc.initialize(psi_0) # Initialize function. Make sure that the vector you enter has 2**nbqbits entries.

qc.draw(output='mpl')

You should get something like:

initialize state

If you decompose the circuit, you can get more information about what gates are inside:

d_c = qc.decompose().decompose().decompose().decompose()

d_c.draw(output='mpl')

and you would get:

decomposed initialize

$\endgroup$
1
  • $\begingroup$ Thanks, so in order to obtain the same result, we could have the initialization as psi_0 = [np.sqrt(0.1), np.sqrt(0.3), np.sqrt(0.6), 0] $\endgroup$ May 7, 2022 at 17:58
0
$\begingroup$

With qiskit I could solve the first part for a 2-qubit quantum circuit:

from math import asin, sqrt
from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram

p1, p2 = 0.3, 0.6 # given probabilities

def prob_to_angle(prob):
   return 2*asin(sqrt(prob))


backend = Aer.get_backend('statevector_simulator')
qc = QuantumCircuit(2)

# Apply prior to qubit 0
qc.ry(prob_to_angle(p1), 0)

# Apply prior to qubit 1
qc.x(0)
qc.cry(prob_to_angle(p2/(1-p1)), 0, 1)
qc.x(0)

# execute the qc
results = execute(qc,backend).result().get_counts()

# plot the results
plot_histogram(results)

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.