Skip to main contentIBM Quantum Documentation

StarPreRouting

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

GitHub(opens in a new tab)

Bases: TransformationPass

Run star to linear pre-routing

This pass is a logical optimization pass that rewrites any solely 2q gate star connectivity subcircuit as a linear connectivity equivalent with swaps.

For example:

from qiskit.circuit import QuantumCircuit
from qiskit.transpiler.passes import StarPreRouting
 
qc = QuantumCircuit(10)
qc.h(0)
qc.cx(0, range(1, 5))
qc.h(9)
qc.cx(9, range(8, 4, -1))
qc.measure_all()
StarPreRouting()(qc).draw("mpl")
../_images/qiskit-transpiler-passes-StarPreRouting-1.png

This pass was inspired by a similar pass described in Section IV of: C. Campbell et al., “Superstaq: Deep Optimization of Quantum Programs,” 2023 IEEE International Conference on Quantum Computing and Engineering (QCE), Bellevue, WA, USA, 2023, pp. 1020-1032, doi: 10.1109/QCE57702.2023.00116.


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

collect_all_matching_blocks

collect_all_matching_blocks(dag, min_block_size=2)

GitHub(opens in a new tab)

Collects all blocks that match a given filtering function filter_fn. This iteratively finds the largest block that does not match filter_fn, then the largest block that matches filter_fn, and so on, until no more uncollected nodes remain. Intuitively, finding larger blocks of non-matching nodes helps to find larger blocks of matching nodes later on. The option min_block_size specifies the minimum number of gates in the block for the block to be collected.

By default, blocks are collected in the direction from the inputs towards the outputs of the circuit. The option collect_from_back allows to change this direction, that is collect blocks from the outputs towards the inputs of the circuit.

Returns the list of matching blocks only.

collect_matching_block

collect_matching_block(dag, filter_fn)

GitHub(opens in a new tab)

Iteratively collects the largest block of input nodes (that is, nodes with _in_degree equal to 0) that match a given filtering function. Examples of this include collecting blocks of swap gates, blocks of linear gates (CXs and SWAPs), blocks of Clifford gates, blocks of single-qubit gates, blocks of two-qubit gates, etc. Here ‘iteratively’ means that once a node is collected, the _in_degree of each of its immediate successor is decreased by 1, allowing more nodes to become input and to be eligible for collecting into the current block. Returns the block of collected nodes.

determine_star_blocks_processing

determine_star_blocks_processing(dag, min_block_size)

GitHub(opens in a new tab)

Returns star blocks in dag and the processing order of nodes within these star blocks :param dag: a dag on which star blocks should be determined. :type dag: DAGCircuit or DAGDependency :param min_block_size: minimum number of two-qubit gates in a star block. :type min_block_size: int

Returns

a list of star blocks in the given dag Union[List[DAGOpNode], List[DAGDepNode]]: a list of operations specifying processing order

Return type

List[StarBlock]

execute

execute(passmanager_ir, state, callback=None)

GitHub(opens in a new tab)

Execute optimization task for input Qiskit IR.

Parameters

Returns

Optimized Qiskit IR and state of the workflow.

Return type

tuple(opens in a new tab)[Any(opens in a new tab), qiskit.passmanager.compilation_status.PassManagerState]

name

name()

GitHub(opens in a new tab)

Name of the pass.

Return type

str(opens in a new tab)

run

run(dag)

GitHub(opens in a new tab)

Run a pass on the DAGCircuit. This is implemented by the pass developer.

Parameters

dag – the dag on which the pass is run.

Raises

NotImplementedError(opens in a new tab) – when this is left unimplemented for a pass.

star_preroute

star_preroute(dag, blocks, processing_order)

GitHub(opens in a new tab)

Returns star blocks in dag and the processing order of nodes within these star blocks :param dag: a dag on which star prerouting should be performed. :type dag: DAGCircuit or DAGDependency :param blocks: a list of star blocks in the given dag. :type blocks: List[StarBlock] :param processing_order: a list of operations specifying :type processing_order: Union[List[DAGOpNode], List[DAGDepNode]] :param processing order:

Returns

a dag specifying the pre-routed circuit qubit_mapping: the final qubit mapping after pre-routing

Return type

new_dag

update_status

update_status(state, run_state)

GitHub(opens in a new tab)

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

Was this page helpful?
Report a bug or request content on GitHub.