ApplyLayout
class qiskit.transpiler.passes.ApplyLayout(*args, **kwargs)
Bases: TransformationPass
Apply or update the mapping of virtual qubits to physical qubits in the DAGCircuit
.
A “layout” in Qiskit is a mapping of virtual qubits (as the user typically creates circuits in terms of) to the physical qubits used to represent them on hardware.
This pass has two modes of operation, depending on the state of the layout
and post_layout
keys in the PropertySet
:
-
Standard operation:
post_layout
is not set. This takes in aDAGCircuit
defined over virtual qubits, and rewrites it in terms of physical qubits. In this case, thelayout
field must have been chosen by a layout pass (for exampleSetLayout
orVF2Layout
), and both it and theDAGCircuit
must have been expanded with ancillas (seeEnlargeWithAncilla
andFullAncillaAllocation
). -
Improving a layout:
post_layout
is set (such as byVF2PostLayout
). In this case, thepost_layout
must already be the correct size. It is interpreted as an _additional_ relabelling on top of the relabelling that is already applied to the inputDAGCircuit
.After the pass runs, the
layout
field will be updated to represent the composition of the two relabellings, as will theDAGCircuit
and any final permutation. Thepost_layout
field will be removed.
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)
Run the ApplyLayout pass on dag
.
Parameters
dag (DAGCircuit) – DAG to map.
Returns
A mapped DAG (with physical qubits).
Return type
Raises
TranspilerError – if no layout is found in property_set
or no full physical qubits.
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