B3: Generate State i(cosTi0+sinTi1)\bigotimes_i\lparen\cos{T_i}\ket{0}+\sin{T_i}\ket{1}\rparen

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Writer: Not_Leonian

Editorial

To implement the solution, we need to prepare the state cosTi0+sinTi1\cos T_i\ket{0} + \sin T_i\ket{1} from 0\ket{0} independently for each qubit.

Here, when the Ry(θ)Ry(\theta) gate is applied to 0\ket{0}, it results in the state cosθ20+sinθ21\cos\frac{\theta}{2}\ket{0} + \sin\frac{\theta}{2}\ket{1}.

Therefore, by setting θ=2Ti\theta = 2T_i and applying the Ry(θ)Ry(\theta) gate to each qubit, we can solve this problem.

For the case where n=3n = 3 and (T0,T1,T2)=(π/6,π/3,π/2)(T_0, T_1, T_2) = (\pi / 6, \pi / 3, \pi / 2), the circuit diagram is shown below.

Sample Code

Below is a sample program:

from qiskit import QuantumCircuit
 
 
def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
 
    for i in range(n):
        qc.ry(T[i] * 2, i)
 
    return qc