qiskit-documentation/docs/api/qiskit/0.25/qiskit.transpiler.passes.Me...

89 lines
4.3 KiB
Plaintext

---
title: MergeAdjacentBarriers
description: API reference for qiskit.transpiler.passes.MergeAdjacentBarriers
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.transpiler.passes.MergeAdjacentBarriers
---
# qiskit.transpiler.passes.MergeAdjacentBarriers
<Class id="qiskit.transpiler.passes.MergeAdjacentBarriers" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.17/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py" signature="MergeAdjacentBarriers(*args, **kwargs)" modifiers="class">
Return a circuit with any adjacent barriers merged together.
Only barriers which can be merged without affecting the barrier structure of the DAG will be merged.
Not all redundant barriers will necessarily be merged, only adjacent barriers are merged.
For example, the circuit:
```python
qr = QuantumRegister(3, 'q')
circuit = QuantumCircuit(qr)
circuit.barrier(qr[0])
circuit.barrier(qr[1])
circuit.barrier(qr)
```
Will be transformed into a circuit corresponding to:
```python
circuit.barrier(qr[0])
circuit.barrier(qr)
```
after one iteration of the pass. These two barriers were not merged by the first pass as they are not adjacent in the initial circuit.
The pass then can be reapplied to merge the newly adjacent barriers.
### \_\_init\_\_
<Function id="qiskit.transpiler.passes.MergeAdjacentBarriers.__init__" signature="__init__()">
Initialize self. See help(type(self)) for accurate signature.
</Function>
## Methods
| | |
| ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [`__init__`](#qiskit.transpiler.passes.MergeAdjacentBarriers.__init__ "qiskit.transpiler.passes.MergeAdjacentBarriers.__init__")() | Initialize self. |
| [`name`](#qiskit.transpiler.passes.MergeAdjacentBarriers.name "qiskit.transpiler.passes.MergeAdjacentBarriers.name")() | Return the name of the pass. |
| [`run`](#qiskit.transpiler.passes.MergeAdjacentBarriers.run "qiskit.transpiler.passes.MergeAdjacentBarriers.run")(dag) | Run the MergeAdjacentBarriers pass on dag. |
## Attributes
| | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| [`is_analysis_pass`](#qiskit.transpiler.passes.MergeAdjacentBarriers.is_analysis_pass "qiskit.transpiler.passes.MergeAdjacentBarriers.is_analysis_pass") | Check if the pass is an analysis pass. |
| [`is_transformation_pass`](#qiskit.transpiler.passes.MergeAdjacentBarriers.is_transformation_pass "qiskit.transpiler.passes.MergeAdjacentBarriers.is_transformation_pass") | Check if the pass is a transformation pass. |
### is\_analysis\_pass
<Attribute id="qiskit.transpiler.passes.MergeAdjacentBarriers.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.
</Attribute>
### is\_transformation\_pass
<Attribute id="qiskit.transpiler.passes.MergeAdjacentBarriers.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).
</Attribute>
### name
<Function id="qiskit.transpiler.passes.MergeAdjacentBarriers.name" signature="name()">
Return the name of the pass.
</Function>
### run
<Function id="qiskit.transpiler.passes.MergeAdjacentBarriers.run" signature="run(dag)">
Run the MergeAdjacentBarriers pass on dag.
</Function>
</Class>