2
$\begingroup$

We are programming with Qiskit and for our research project we need to insert non-unitary gates within a quantum circuit.

  1. Is the unitarity of gates a mandatory property required to run the code without raising errors?
  2. Are there specific parts of the Qiskit source code that can be modified in order to implement non-unitary gates without the need to change the whole Qiskit framework?
$\endgroup$
2

2 Answers 2

4
$\begingroup$

Non-unitary gate is a bit of an oxymoron for reasons explained here and here. Qiskit support non-unitary instructions. Gates are Instructions subclasses. A gate, like XGate is an instruction, but not every instruction, such as Reset, is a gate:

from qiskit.circuit import Gate, Instruction, Reset
issubclass(Reset, Instruction)  # True
issubclass(Reset, Gate)  # False

issubclass(XGate, Instruction)  # True
issubclass(XGate, Gate)  # True

So Qiskit already supports the notion of non-unitary instruction. You can create your own instruction with to_instruction. For example, this is a "reset to 1" instruction:

  1. Create a circuit:
from qiskit import QuantumCircuit
reset_to_one = QuantumCircuit(1, name="reset to 1")
reset_to_one.reset(0)
reset_to_one.x(0)
print(reset_to_one)
        ┌───┐
q: ─|0>─┤ X ├
        └───┘
  1. Convert that circuit into a instruction:
reset_to_one_inst = reset_to_one.to_instruction()
  1. Add your instruction into a circuit:
circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.append(reset_to_one, [1])
circuit.measure_all()
print(circuit)
        ┌───┐                    ░ ┌─┐   
   q_0: ┤ H ├──■─────────────────░─┤M├───
        └───┘┌─┴─┐┌────────────┐ ░ └╥┘┌─┐
   q_1: ─────┤ X ├┤ reset to 1 ├─░──╫─┤M├
             └───┘└────────────┘ ░  ║ └╥┘
meas: 2/════════════════════════════╩══╩═
                                    0  1 

In this case, $q_1$ will be reset to 1 before being measured into $meas_1$. reset to 1 is a non-unitary instruction.

$\endgroup$
4
  • 1
    $\begingroup$ Thanks @luciano, your answer was really helpful! It seems that with your solution, one can define a new instruction as a composition of predefined Qiskit instructions. We are facing a slightly different problem: we know the entries of a non-unitary matrix and we want to define the instruction that corresponds to this matrix. Is this possible? $\endgroup$ Jan 31, 2022 at 8:34
  • $\begingroup$ Also interested to see if this is possible. Need to define non-unitary instructions from a matrix. $\endgroup$
    – Bebotron
    Aug 28, 2023 at 20:05
  • $\begingroup$ Qiskit does not support non-unitary-matrix-defined operations (yet?). What's your use-case for them? Synthesis? Simulation? Feel free to make a case as a feature request github.com/Qiskit/qiskit/issues/… $\endgroup$
    – luciano
    Sep 5, 2023 at 13:20
  • $\begingroup$ I'm looking at implementing the trajectories method for simulating a noisy circuit (quantumcomputing.stackexchange.com/a/23400/19585), and have Kraus operators that are not necessarily unitary. $\endgroup$
    – Bebotron
    Oct 9, 2023 at 23:46
1
$\begingroup$

One can define a non-unitary matrix as a density matrix, in the case it is hermitian positive-definite. It seems qiskit does not check the trace condition. However, it would be nice to know a way of building an instruction from a non-unitary matrix. All examples I found of non-unitary instructions where built from circuits.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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