epelaaez
• 2.5k
• 1
• 5
• 27

First, note that the input (in vector form) will be $$\begin{bmatrix} 1 \\ 0 \end{bmatrix}$$. And you want the output to be $$\begin{bmatrix} \alpha \\ \beta \end{bmatrix}$$. Therefore, the matrix that represents the gate you want needs to have the vector you want as output on the first column.

To see what the second column needs to be, let’s look at the general expression of a unitary matrix. This is

$$\begin{bmatrix} a & b \\ -e^{i \phi}b^* & e^{i \phi}a^* \end{bmatrix}$$

Therefore, plugging in the first column and solving for the elements of the second column, the form of the matrix you want is

$$\begin{bmatrix} \alpha & -\beta \\ \beta & \alpha \end{bmatrix}$$$$\begin{bmatrix} \alpha & \beta^* \\ \beta & -\alpha^* \end{bmatrix}$$

Here we choose to eliminate$$a=\alpha$$, $$b=\beta^*$$ (to make sure the phase factor since it’s not presentcomplex conjugate one is in the questiontop row; but you poseddon't need to worry about this if $$\alpha, \beta \in \mathbb{R}$$) and $$\phi = \pi$$. An example of this type of matrix is the Hadamard, that you can get by making $$\alpha=\beta=\frac{1}{\sqrt{2}}$$.

$$H= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}$$

I’m not sure how to do it in Q#, but to do this in Qiskit, define an np.array with the matrix you want. Then, create the matrix by running gate = UnitaryGate(your_matrix). Then, just append the gate as you normally would: qc.append(gate, [qubits]). However, you need to look out for Qiskit’s indexing. For more info on this, checkout this answer.

Post Undeleted by epelaaez
Post Deleted by epelaaez
epelaaez
• 2.5k
• 1
• 5
• 27

First, note that the input (in vector form) will be $$\begin{bmatrix} 1 \\ 0 \end{bmatrix}$$. And you want the output to be $$\begin{bmatrix} \alpha \\ \beta \end{bmatrix}$$. Therefore, the matrix that represents the gate you want needs to have the vector you want as output on the first column.

To see what the second column needs to be, let’s look at the general expression of a unitary matrix. This is

$$\begin{bmatrix} a & b \\ -e^{i \phi}b^* & e^{i \phi}a^* \end{bmatrix}$$

Therefore, plugging in the first column and solving for the elements of the second column, the form of the matrix you want is

$$\begin{bmatrix} \alpha & -\beta \\ \beta & \alpha \end{bmatrix}$$

Here we choose to eliminate the phase factor since it’s not present in the question you posed.

I’m not sure how to do it in Q#, but to do this in Qiskit, define an np.array with the matrix you want. Then, create the matrix by running gate = UnitaryGate(your_matrix). Then, just append the gate as you normally would: qc.append(gate, [qubits]). However, you need to look out for Qiskit’s indexing. For more info on this, checkout this answer.

epelaaez
• 2.5k
• 1
• 5
• 27

First, note that the input (in vector form) will be $$\begin{bmatrix} 1 \\ 0 \end{bmatrix}$$. And you want the output to be $$\begin{bmatrix} \alpha \\ \beta \end{bmatrix}$$. Therefore, the matrix that represents the gate you want needs to have the vector you want as output on the first column.

To see what the second column needs to be, let’s look at the general expression of a unitary matrix. This is

$$\begin{bmatrix} a & b \\ -e^{i \phi}b^* & e^{i \phi}a^* \end{bmatrix}$$

Therefore, plugging in the first column and solving for the elements of the second column, the form of the matrix you want is

$$\begin{bmatrix} \alpha & -\beta \\ \beta & \alpha \end{bmatrix}$$

Here we choose to eliminate the phase factor since it’s not present in the question you posed.