-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
Description
There are a few compiler passes right now related to peephole optimization:
- Collect2qBlocks
- ConsolidateBlocks
- Optimize1qGates
- Optimize1qDecomposition
- Add CollectMultiQBlocks pass to find multiqubit blocks in a circuit #4747
We should unify these into one general pass which is able to walk the circuit and collect+consolidate these gates. This should rely on the DAGDependency
graph otherwise it will miss some opportunities when gates commute but are not next to each other. This should also accept a filter function that tells the pass to collect those gates that meet a certain condition (I believe retworkx can already do this). The filter functions could be:
- gate.num_qubits == 1
- gate.num_qubits <= 2
- gate.is_clifford
- etc.
Also I think we should just combine the collection phase with the consolidation phase. We can call it CollapseChains
. I haven't found a use case for collecting a chain of gates but not collapsing them into an equivalent unitary.