I am currently running a simple algorithm using Qiskit and I am running it for various transpiler optimization levels (0-3). I wish to know what exactly occurs differently when for example I run the algorithm with optimization level 1 as compared to when the algorithm is run with optimization level 3. There is general information available on what a transpiler does, however, I cannot find what exactly happens differently in each optimization level.


These levels are provided via "preset passmanagers" in Qiskit. These are simple-to-use transpiler pipelines, but you can also build your own passmanager pipeline. You can see what each does by inspecting the documentation for those: https://github.com/Qiskit/qiskit-terra/tree/master/qiskit/transpiler/preset_passmanagers

But briefly, level 0 does no explicit optimization, it will just try to make a circuit runnable by transforming it to match a topology and basis gate set, if necessary.

Level 1, 2 and 3 do light, medium and heavy optimization, using a combination of passes, and by configuring the passes to search for better solutions. Typically more optimality comes at the cost of slower transpilation, as it spends more time searching for a good optimization.

For example if you look at the difference between level 2 and level 3, in level 2 the transpiler does some commutation analysis to see what gates can be collapsed. In level 3, in addition to that, it does peep-hole optimization by combining a chain of gates on the same qubits and re-synthesizing them with better cost. Also the routing stage of level 3 is more expensive than level 2 (it has a larger search space, as set by parameters of the StochasticSwap and LookaheadSwap passes).

It is important to keep in mind that these are heuristics. It is possible that, for a specific circuit, you will not see much improvement by increasing the level.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.