A pulse schedule for one qubit is a list of gate names, such as ["h", "s"]. The gates are applied left to right: first the gate at index 0, then the one at index 1, and so on. Each gate is a 2\times 2 matrix U (a list of rows, U[row][col]) that turns the state [a, b] into [U[0][0]*a + U[0][1]*b, U[1][0]*a + U[1][1]*b]. The names are (i is 1j):
I=\begin{pmatrix}1&0\\0&1\end{pmatrix},\ X=\begin{pmatrix}0&1\\1&0\end{pmatrix},\ Y=\begin{pmatrix}0&-i\\i&0\end{pmatrix},\ Z=\begin{pmatrix}1&0\\0&-1\end{pmatrix},\ H=\tfrac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix},\ S=\begin{pmatrix}1&0\\0&i\end{pmatrix},\ T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}
written "i", "x", "y", "z", "h", "s", "t".
Write run_circuit(gates, state) that returns the state after the whole schedule. An empty schedule leaves the state as it is. Any global phase is accepted: [1j, 0] is the same state as [1, 0]; a different relative phase ([0.6, 0.8j] against [0.6, 0.8]) is a different state.
Examples
Input: gates = ["h", "s"], state = [1, 0]
Output: [0.7071067811865475, 0.7071067811865475j]
Explanation: H makes [0.7071..., 0.7071...], then S multiplies the second amplitude by i.
Input: gates = ["s", "h"], state = [1, 0]
Output: [0.7071067811865475, 0.7071067811865475]
Explanation: S first leaves [1, 0] unchanged, then H. Same gates, other order, other state.
Input: gates = [], state = [0.6, 0.8]
Output: [0.6, 0.8]
Constraints
0 <= len(gates) <= 1000- amplitudes are compared with a tolerance of
1e-6
Goals
- Simulate a one-qubit circuit by applying its gates one after another
- See that the order of the gates changes the result