QuantumCore

Hands-on lab · 1 step

Amplitude-encode the vector (1, 2, 3, 4)

Prepare the amplitude encoding ∣x⟩=130(∣00⟩+2∣01⟩+3∣10⟩+4∣11⟩)\lvert x\rangle=\tfrac1{\sqrt{30}}\big(\lvert00\rangle+2\lvert01\rangle+3\lvert10\rangle+4\lvert11\rangle\big) of x=(1,2,3,4)x=(1,2,3,4) on two qubits with at most five gates from {RY,CNOT}\{R_Y,\mathrm{CNOT}\}: one rotation for the split on qubit 00 and a uniformly controlled RYR_Y on qubit 11, compiled into two rotations and two CNOTs.

0/1 step passedBest score 0/100

Step 1: Prepare (1, 2, 3, 4)/√30

Starting from ∣00⟩\lvert00\rangle, prepare the normalised amplitude encoding of x=(x0,x1,x2,x3)=(1,2,3,4)x=(x_0,x_1,x_2,x_3)=(1,2,3,4):

∣x⟩=1∥x∥∑i=03xi∣i⟩=130(1⋅∣00⟩+2⋅∣01⟩+3⋅∣10⟩+4⋅∣11⟩),∥x∥=1+4+9+16=30.\lvert x\rangle=\frac{1}{\lVert x\rVert}\sum_{i=0}^{3}x_i\lvert i\rangle=\frac{1}{\sqrt{30}}\big(1\cdot\lvert00\rangle+2\cdot\lvert01\rangle+3\cdot\lvert10\rangle+4\cdot\lvert11\rangle\big),\qquad\lVert x\rVert=\sqrt{1+4+9+16}=\sqrt{30}.

The index of ∣q0q1⟩\lvert q_0q_1\rangle is k=2q0+q1k=2q_0+q_1: qubit 0 is the most significant bit, so x0,x1x_0,x_1 sit in the half q0=0q_0=0 and x2,x3x_2,x_3 in the half q0=1q_0=1.

Allowed gates: RY(θ)=e−iθY/2=(cos⁡θ2−sin⁡θ2sin⁡θ2cos⁡θ2)R_Y(\theta)=e^{-i\theta Y/2}=\begin{pmatrix}\cos\frac\theta2&-\sin\frac\theta2\\\sin\frac\theta2&\cos\frac\theta2\end{pmatrix} and CNOT\mathrm{CNOT}, at most five gates in total. Angles are entered in radians. The grader computes the fidelity F=∣⟨x∣ψ⟩∣2F=\lvert\langle x\vert\psi\rangle\rvert^2 of your final state ∣ψ⟩\lvert\psi\rangle and requires F≥1−10−6F\ge1-10^{-6}, so give each angle to at least seven significant digits.

  • 2 qubits
  • allowed gates: RY, CNOT
  • at most 5 gates
  • no measurements

One gate per line or separated by ;, e.g. H(0); CNOT(0,1); RY(1, pi/3); measure(1 -> 0). Qubit 0 is the top wire (most significant bit); controls come first. # starts a comment.

Measure into a classical bit with measure(q -> c); apply a gate only when a bit is set with X(2) if c1==1 (several bits, first = most significant: if c[0,1]==3).

Circuit diagram of your answerEmpty circuitq0q1
Statevector amplitudes
BasisAmplitude α|α|Phase arg αProbability
|00⟩1
1.0000
0
100.00%
3 basis states with zero amplitude hidden