2

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?
glS
  • 24,708
  • 5
  • 34
  • 108

2 Answers2

4

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.

luciano
  • 5,763
  • 1
  • 12
  • 34
  • 1
    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? – Mr Anderson Jan 31 '22 at 08:34
  • Also interested to see if this is possible. Need to define non-unitary instructions from a matrix. – Bebotron Aug 28 '23 at 20:05
  • 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 https://github.com/Qiskit/qiskit/issues/new?template=FEATURE_REQUEST.yaml – luciano Sep 05 '23 at 13:20
  • I'm looking at implementing the trajectories method for simulating a noisy circuit (https://quantumcomputing.stackexchange.com/a/23400/19585), and have Kraus operators that are not necessarily unitary. – Bebotron Oct 09 '23 at 23:46
1

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.

fresneda
  • 11
  • 3