Lecture 2.1 - Quantum Circuit Compilation with Qiskit
Lecture 2.1 - Quantum Circuit Compilation with Qiskit
Quantum Circuit
Compilation with
Qiskit
Matthew Treinish
Senior Software Engineer
IBM
Note on terminology
– In Qiskit the quantum circuit compiler is called the "transpiler"
– This is a historical name and doesn't accurately represent its capabilities or function
– Typically, when you look up the term "transpiler" it refers to a source-to-source compiler. Such
as a compiler that translates Python to Rust.
– There are numerous constraints with hardware that need to be accounted for
– The compiler's job is to take the high-level abstract circuit and output an
optimized circuit that is capable of running on a given quantum computer
Good compilation:
Better compilation:
– Gate Errors
– Decoherence
• T1: Energy Relaxation, the time for a qubit at |1⟩
to decay to ground state |0⟩
• T2: dephasing of a qubit in superposition state
decoherence is the measure of how long a
– Readout Error quantum state can be maintained
error during measuring
Target
Number of qubits: 5
https://docs.quantum.ibm.com/api/qiskit/qiskit.transp sx
(0,):
Duration: 3.5555555555555554e-08 sec.
- Helps to track data flow from a qubit until we reach the output node
- Pass Manager is a way of scheduling execution of passes
- Transpiler is built up of Passes that operate on these DAGs; Pass
Managers job is to schedule these passes
https://docs.quantum.ibm.com/transpile/transpiler-plugins
o Logical optimizations
– At the end of the stage, we are able to run layout (which models the circuit as
a graph)
logical optimisations
o Logical optimizations Logical optimisations are optimisations done before we have any idea about the hardware
– At the end of the stage, we are able to run layout (which models the circuit as
a graph)
pick best layouts that use best qubits and finally, have minimum usage of
SWAP gates
– Layout is of critical importance because not all qubits perform the same.
– This stage typically tries multiple techniques to find the best layout. In Qiskit
we use two passes by default: VF2Layout and Sabre
we have reordered qubits and we have assigned them each a target from
which they have been connected
https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.pa
sses.VF2Layout represents 2 qubit operations
this pass tries to match the interaction graph to the connectivity graph
which is a computationally hard problem to solve. This is where rustworkx
comes in as it hs the features to implement this job
https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.passes.SabreLayout
- heuristic pass that picks a layer that will have the lowest use of number of
SWAP gates
- starts with a bunch of random starting points; each starting point
produces a different mapping for each one of these; picks the one which
produces the lowest no. of SWAP gates
https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.passes.SabreLayout
– If running with defaults however this pass is skipped for efficiency, and it's
run as part of SabreLayout in the Layout stage.
https://journals.aps.org/prxquantum/abstract/10.1103/PRXQuantum.4.010327
https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.passes.VF2PostLayout
https://journals.aps.org/prxquantum/abstract/10.1103/PRXQuantum.4.010327
https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.passes.VF2PostLayout
• This stage runs the same passes we used in the first phase of the init stage
but for all operations instead of just those with >= 3 qubits
– This stage runs in a loop to repeatedly run the optimization passes until a
minimum point in depth and size is found
up until Translation
stage, we have circuit
that could be executed
on hardware; all the
constraints have been
made up for; but this
will not give a good
result; thus we have
this stage to optimise
the circuit by reducing
the no. of operations
• It will then insert explicit operations to account for all the time in the circuit
- Delay Gates
- Dynamic Decoupling: where we insert gates to supress them and reduce errors
• It will then insert explicit operations to account for all the time in the circuit