Compiler

Each syntax has its corresponding compiler. The get_compiler method is used to choose the compiler. The three options are “native”, “qasm”, and “qiskit”. All the compilers have a compile method with two arguments, and the second argument is always the optimization level, but the first argument is different.

The native compiler takes a Circuit instance in SpinQit as the first argument.

circ = Circuit()
...
comp = get_compiler("native")
exe = comp.compile(circ, optimization_level)

The qasm compiler takes the path to a qasm file as the first argument.

comp = get_compiler('qasm')
exe = comp.compile("test/spinq/callee.qasm", optimization_level)

The qiskit compiler takes a Qiskit QuantumCircuit instance as the first argument.

circ = QuantumCircuit(3)
...
comp = get_compiler("qiskit")
exe1 = comp.compile(circ, optimization_level)

Compilation Optimization

SpinQit provides basic circuit optimization features. There are four optimization levels in SpinQit compilers, each associated with distinct combinations of optimization algorithms.

Level 0 means no optimization algorithm is applied.

Level 1 contains two passes and two algorithms are applied in order. The first algorithm cancels consecutive redundant gates. Certain gates can be removed when they are repeated an even number of times on the same qubit(s) without affecting the final result. The gates that satisfy this property include the Pauli-X gate (X gate), Hadamard gate (H gate), and CNOT gate (CX gate). This algorithm will remove these redundant gates from the circuit. Similarly, if a number of rotation gates rotates the same qubit around the same axis, this algorithm will combine them into one rotation gate. The second algorithm collapses more than 3 consecutive single-qubit gates on the same qubit into several basic gates. The algorithm calculates the matrix that represents the consecutive gates and decomposes the matrix to basic gates. Currently, SpinQit uses ZYZ decomposition.

Level 2 contains the two algorithms in Level 1 and then applies a third algorithm. The third algorithm collapses more than 6 consecutive two-qubit gates on the same two qubits into certain Ry, Rz, and CX gates. The algorithm also calculates the matrix that represents the original gates and then decomposes the matrix.

Level 3 first cancels redundant gates and then applies two optimization algorithms based on quantum state analysis introduced in https://arxiv.org/abs/2012.07711v1. The two algorithms are reported to perform better than the most aggressive optimization level in Qiskit. After the two algorithm, the collapsing single-qubit gates and collapsing two-qubit gates passes are applied.

The optimization features in SpinQit are still experimental. More algorithms are will be added in the future. Please let us know if you find any issue.

Circuit Visualization

SpinQit provides a helper function to draw the intermediate representation after compilation. The output drawing shows the quantum circuit.

spinqit.view.draw (ir, filename, clbit_extend, decompose_level)

Draw an image for the intermediate representation of a circuit and save it to a png file.

Parameters

ir - IntermediateRepresentation, ir of the circuit to draw

filename - str, the name of the output png file

clbit_extend - bool, False by default, show each classic bit in a row, or collapse all classic bits into one row

decompose_level - int, 0 by default, for decompose_level = n > 0, decompose caller gates in ir recursively by n levels