0
$\begingroup$

From what I understand, any circuit can be combined to make a gate, which has a square, unitary matrix form that acts on the $2^n$ row of the qubits state column vector. For example, the circuit

     ┌───┐     
q_0: ┤ H ├──■──
     ├───┤┌─┴─┐
q_1: ┤ H ├┤ X ├
     └───┘└───┘

has the matrix form $\begin{bmatrix} \tfrac{1}{2} & \tfrac{1}{2} & \tfrac{1}{2} & \tfrac{1}{2} \\ \tfrac{1}{2} & -\tfrac{1}{2} & -\tfrac{1}{2} & \tfrac{1}{2} \\ \tfrac{1}{2} & \tfrac{1}{2} & -\tfrac{1}{2} & -\tfrac{1}{2} \\ \tfrac{1}{2} & -\tfrac{1}{2} & \tfrac{1}{2} & -\tfrac{1}{2} \\ \end{bmatrix}$ which acts on the vector $\begin{bmatrix}1 \\ 0 \\ 0 \\ 0 \end{bmatrix}$ of the initial $|0\rangle$ state. But when I try to get_unitary() a circuit with a reset gate, Qiskit tells me that reset instruction is not unitary and therefore it cannot give me any matrix form. My question is, in general, how do a reset gate affect the matrix form of a multi-qubit gate/circuit?

Thank you!

Edit: The circuit I'm trying to find the matrix form for is i.e. like this:

     ┌───┐          
q_0: ┤ H ├──■───────
     ├───┤┌─┴─┐     
q_1: ┤ H ├┤ X ├─|0>─
     └───┘└───┘     
$\endgroup$
1
$\begingroup$

The reset isn't unitary, so there is no unitary matrix for the circuit. You need to switch to looking at the general channel of the circuit (e.g. described by Krauss operators).

Alternatively, you can introduce environment qubits and replace the reset with unitary operations acting on the environment (e.g. the reset could swap a zero'd qubit in the environment for the qubit you want to reset). You can then look at the unitary of the system+environment circuit, although keep in mind that there are multiple ways to translate a reset so there is some ambiguity in which unitary you get.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Can you introduce me to where I can learn to describe the circuit like that, that can include even non-unitary instructions (book, paper)? $\endgroup$ – Kim Dong Nov 17 at 18:46
  • 1
    $\begingroup$ It's covered in nielsen and Chiang when they describe channels iirc $\endgroup$ – Craig Gidney Nov 17 at 21:28
0
$\begingroup$

You can use:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit,  execute, BasicAer, Aer
qreg_q = QuantumRegister(2, 'q')
creg_c = ClassicalRegister(2, 'c')
circuit = QuantumCircuit(qreg_q, creg_c)
circuit.h(qreg_q[0])
circuit.h(qreg_q[1])
circuit.cx(qreg_q[0], qreg_q[1])
print(circuit)

backend = Aer.get_backend('unitary_simulator')
job = execute(circuit, backend)
result = job.result()
print(result.get_unitary(circuit, decimals=3))

and you will get the output

     ┌───┐     
q_0: ┤ H ├──■──
     ├───┤┌─┴─┐
q_1: ┤ H ├┤ X ├
     └───┘└───┘
c: 2/══════════
               
[[ 0.5+0.0000000e+00j  0.5-6.1232340e-17j  0.5-6.1232340e-17j
   0.5-1.2246468e-16j]
 [ 0.5+0.0000000e+00j -0.5+6.1232340e-17j -0.5+6.1232340e-17j
   0.5-1.2246468e-16j]
 [ 0.5+0.0000000e+00j  0.5-6.1232340e-17j -0.5+6.1232340e-17j
  -0.5+1.2246468e-16j]
 [ 0.5+0.0000000e+00j -0.5+6.1232340e-17j  0.5-6.1232340e-17j
  -0.5+1.2246468e-16j]]

But you can also use the quantum_info option.. by running the following code using the above circuit:

import qiskit.quantum_info as qi
operator = qi.Operator(circuit)

The output of operator will be:

Operator([[ 0.5+0.j,  0.5+0.j,  0.5+0.j,  0.5+0.j],
          [ 0.5+0.j, -0.5+0.j, -0.5+0.j,  0.5+0.j],
          [ 0.5+0.j,  0.5+0.j, -0.5+0.j, -0.5+0.j],
          [ 0.5+0.j, -0.5+0.j,  0.5+0.j, -0.5+0.j]],
         input_dims=(2, 2), output_dims=(2, 2))

Hope this is what you are looking for.


update: The above description is of course without having the reset operation being applied. Resetting a qubit is not a unitary operation as $U|0\rangle = |0\rangle$ and $U|1\rangle = |0\rangle$, hence it is not a reversible operation.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I just tried but sadly it didn't work. It said 'Cannot apply Instruction: reset' $\endgroup$ – Kim Dong Nov 17 at 11:18
  • $\begingroup$ I see your edited version of the circuit. So the reset option is not unitary hence the reason you can't generate the unitary matrix from your circuit. Reset a qubit to the state $|0\rangle$ can be done by applying measurement (in the computational basis as usual) then apply a bit-flip (X-gate) if the qubit is a $|1\rangle$ and do nothing if it is $|0\rangle$. And we know that measurement is not a unitary operation as well. $\endgroup$ – KAJ226 Nov 17 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.