LayoutTransformation
class qiskit.transpiler.passes.LayoutTransformation(*args, **kwargs)
Bases: TransformationPass
Adds a Swap circuit for a given (partial) permutation to the circuit.
This circuit is found by a 4-approximation algorithm for Token Swapping. More details are available in the routing code.
LayoutTransformation initializer.
Parameters
- coupling_map – Directed graph representing a coupling map.
- from_layout (Union[Layout, str]) – The starting layout of qubits onto physical qubits. If the type is str, look up property_set when this pass runs.
- to_layout (Union[Layout, str]) – The final layout of qubits on physical qubits. If the type is str, look up
property_set
when this pass runs. - seed (Union[int, np.random.default_rng]) – Seed to use for random trials.
- trials (int) – How many randomized trials to perform, taking the best circuit as output.
Attributes
is_analysis_pass
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.
is_transformation_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).
Methods
execute
execute(passmanager_ir, state, callback=None)
Execute optimization task for input Qiskit IR.
Parameters
- passmanager_ir (Any) – Qiskit IR to optimize.
- state (PassManagerState) – State associated with workflow execution by the pass manager itself.
- callback (Callable | None) – A callback function which is caller per execution of optimization task.
Returns
Optimized Qiskit IR and state of the workflow.
Return type
tuple[Any, qiskit.passmanager.compilation_status.PassManagerState]
name
run
run(dag)
Apply the specified partial permutation to the circuit.
Parameters
dag (DAGCircuit) – DAG to transform the layout of.
Returns
The DAG with transformed layout.
Return type
Raises
TranspilerError – if the coupling map or the layout are not compatible with the DAG. Or if either of string from/to_layout is not found in property_set.
update_status
update_status(state, run_state)
Update workflow status.
Parameters
- state (PassManagerState) – Pass manager state to update.
- run_state (RunState) – Completion status of current task.
Returns
Updated pass manager state.
Return type