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
  • 27,510
  • 7
  • 37
  • 125

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
  • 6,084
  • 1
  • 13
  • 34
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