Each qubit of a register is prepared on its own: qubit q is put in the state qubits[q] = [a_q, b_q] (two complex numbers with |a_q|^2+|b_q|^2=1). The register as a whole is then in a product state, a list of 2^n amplitudes. The amplitude of basis state |c_0 c_1 \dots c_{n-1}\rangle (each c_q is 0 or 1) is the product of qubit 0's amplitude for c_0, qubit 1's amplitude for c_1, and so on.
Bit order: basis state |c_0 c_1 \dots c_{n-1}\rangle has index int("c0c1...", 2), so qubit 0 is the leftmost bit, the most significant. In 3 qubits, |011\rangle is index 3. In the language of matrices, the register state is the Kronecker product kron(qubits[0], qubits[1], ..., qubits[n-1]) in exactly that order.
Write product_state(qubits) that returns the register state, a list (or numpy array) of 2^n amplitudes. Any global phase is accepted: [1j, 0] is the same state as [1, 0].
Examples
Input: qubits = [[1, 0], [0, 1]]
Output: [0, 1, 0, 0]
Explanation: qubit 0 reads 0 and qubit 1 reads 1: the basis state |01>, index 1.
Input: qubits = [[0.6, 0.8], [0.7071067811865475, 0.7071067811865475j]]
Output: [0.42426406871192845, 0.42426406871192845j, 0.565685424949238, 0.565685424949238j]
Explanation: index 2 is |10>, so its amplitude is 0.8 * 0.7071... (qubit 0 reads 1, qubit 1 reads 0).
Input: qubits = [[0.6, 0.8]]
Output: [0.6, 0.8]
Constraints
- amplitudes are compared with a tolerance of
1e-6
Goals
- Combine single-qubit states into one register state with the Kronecker product
- Keep the order: qubit 0 first, so it becomes the leftmost bit