Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.64 KB

README.md

File metadata and controls

49 lines (36 loc) · 1.64 KB

Tool for decomposing unitary matrix into quantum gates

PyPI version

This is a Python tool which takes a unitary matrix and returns a quantum circuit implementing it as Q# code, Cirq circuit, or Qiskit circuit.

Installing

pip install quantum-decomp

Example

>>> import numpy, quantum_decomp
>>> SWAP = numpy.array([[1,0,0,0],[0,0,1,0],[0,1,0,0], [0,0,0,1]])
>>> print(quantum_decomp.matrix_to_qsharp(SWAP, op_name='Swap'))
operation Swap (qs : Qubit[]) : Unit {
  CNOT(qs[1], qs[0]);
  CNOT(qs[0], qs[1]);
  CNOT(qs[1], qs[0]);
}

>>> print(quantum_decomp.matrix_to_cirq_circuit(SWAP))
0: ───@───X───@───
      │   │   │
1: ───X───@───X───

>>> print(quantum_decomp.matrix_to_qiskit_circuit(SWAP))
     ┌───┐     ┌───┐
q_0: ┤ X ├──■──┤ X ├
     └─┬─┘┌─┴─┐└─┬─┘
q_1: ──■──┤ X ├──■──
          └───┘

See example.ipynb for more examples and instructions how to use this tool.

References