Skip to main contentIBM Quantum Documentation Mirror

ApplyLayout

class qiskit.transpiler.passes.ApplyLayout(*args, **kwargs)

GitHub

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:

  1. Standard operation: post_layout is not set. This takes in a DAGCircuit defined over virtual qubits, and rewrites it in terms of physical qubits. In this case, the layout field must have been chosen by a layout pass (for example SetLayout or VF2Layout), and both it and the DAGCircuit must have been expanded with ancillas (see EnlargeWithAncilla and FullAncillaAllocation).

  2. Improving a layout: post_layout is set (such as by VF2PostLayout). In this case, the post_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 input DAGCircuit.

    After the pass runs, the layout field will be updated to represent the composition of the two relabellings, as will the DAGCircuit and any final permutation. The post_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)

GitHub

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

name()

GitHub

Name of the pass.

Return type

str

run

run(dag)

GitHub

Run the ApplyLayout pass on dag.

Parameters

dag (DAGCircuit) – DAG to map.

Returns

A mapped DAG (with physical qubits).

Return type

DAGCircuit

Raises

TranspilerError – if no layout is found in property_set or no full physical qubits.

update_status

update_status(state, run_state)

GitHub

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

PassManagerState