class SabreLayout(*args, **kwargs)[source]

Bases: TransformationPass

Choose a Layout via iterative bidirectional routing of the input circuit.

Starting with a random initial Layout, the algorithm does a full routing of the circuit (via the routing_pass method) to end up with a final_layout. This final_layout is then used as the initial_layout for routing the reverse circuit. The algorithm iterates a number of times until it finds an initial_layout that reduces full routing cost.

This method exploits the reversibility of quantum circuits, and tries to include global circuit information in the choice of initial_layout.

By default this pass will run both layout and routing and will transform the circuit so that the layout is applied to the input dag (meaning that the output circuit will have ancilla qubits allocated for unused qubits on the coupling map and the qubits will be reordered to match the mapped physical qubits) and then routing will be applied (inserting AnalysisPass objects and just find an initial layout and set that on the property set. This is done because by default the pass will run parallel seed trials with different random seeds for selecting the random initial layout and then selecting the routed output which results in the least number of swap gates needed.

You can use the routing_pass argument to have this pass operate as a typical layout pass. When specified this will use the specified routing pass to select an initial layout only and will not run multiple seed trials.


[1] Li, Gushu, Yufei Ding, and Yuan Xie. "Tackling the qubit mapping problem for NISQ-era quantum devices." ASPLOS 2019. arXiv:1809.02573

SabreLayout initializer.

  • coupling_map (Coupling) -- directed graph representing a coupling map.

  • routing_pass (BasePass) -- the routing pass to use while iterating. If specified this pass operates as an AnalysisPass and will only populate the layout field in the property set and the input dag is returned unmodified. This argument is mutually exclusive with the swap_trials and the layout_trials arguments and if this is specified at the same time as either argument an error will be raised.

  • seed (int) -- seed for setting a random first trial layout.

  • max_iterations (int) -- number of forward-backward iterations.

  • swap_trials (int) -- The number of trials to run of SabreSwap for each iteration. This is equivalent to the trials argument on SabreSwap. If this is not specified (and routing_pass isn't set) by default the number of physical CPUs on your local system will be used. For reproducibility between environments it is best to set this to an explicit number because the output will potentially depend on the number of trials run. This option is mutually exclusive with the routing_pass argument and an error will be raised if both are used.

  • layout_trials (int) -- The number of random seed trials to run layout with. When > 1 the trial that resuls in the output with the fewest swap gates will be selected. If this is not specified (and routing_pass is not set) then the number of local physical CPUs will be used as the default value. This option is mutually exclusive with the routing_pass argument and an error will be raised if both are used.

  • skip_routing (bool) -- If this is set True and routing_pass is not used then routing will not be applied to the output circuit. Only the layout will be returned in the property set. This is a tradeoff to run custom routing with multiple layout trials, as using this option will cause SabreLayout to run the routing stage internally but not use that result.

  • TranspilerError -- If both routing_pass and swap_trials or

  • both routing_pass and layout_trials are specified --



Return the name of the pass.


Run the SabreLayout pass on dag.



Check if the pass is an analysis pass.

If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write the results of that analysis in the property set. Modifications on the DAG are not allowed by this kind of pass.


Check if the pass is a transformation pass.

If the pass is a TransformationPass, that means that the pass can manipulate the DAG, but cannot modify the property set (but it can be read).