Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support control flow in ConsolidateBlocks (Qiskit#10355)
* Support control flow in ConsolidateBlocks * Add release note for support control flow in ConsolidateBlocks * Move imports from inside function to top level * Make construction of ConsolidateBlocks for control flow ops more efficient * Do IfElseOp test without builder interface Before, we used the builder interface for an ifelse op. Some details of the circuit built, in particular the mapping of wires is not deterministic. We could have used canonicalize_control_flow. But instead we construct the IfElseOp manually. This removes the complexity of the builder interface from this test. * Linting * Avoid cyclic import * Try to fix cyclic import (in lint tool only) * Reuse top-level consolidation pass and add tests * Before, we created an new ConsolidationPass when descending into control flow blocks. With this commit, we use the existing pass. * Add some tests for cases where consolidation should not happen. * Remove argument `decomposer` from constructor of ConsolidateBlocks This was added in a previous commit in the series of commits for this PR. The code has been redesigned so that this argument is no longer necessary. * Remove cruft accidentally left In the first version of the associated PR, we created a new pass when descending into control flow blocks. These lines were included to support that construction and are no longer needed. * Move function-level import to module level Remove unused import in tests * Write loop more concisely * Update releasenotes/notes/add-control-flow-to-consolidate-blocks-e013e28007170377.yaml Co-authored-by: Jake Lishman <[email protected]> * Use assertion in tests with better diagnostics * Remove reference to decomposer from docstring to ConsolidateBlocks The previous doc string was a bit imprecise. It also referred to a decomposer which although implied, is not meant to be accessible by the user. * Use more informative tests for ConsolidateBlocks with control flow * Simplify test in test_consolidate_blocks and factor * Gates used in testing ConsolidateBlocks with control flow ops were copied from another test in the file. They complicate the test, and removing them does not weaken the test at all. * Factor some code within a test into a function * Factor more code in test * Use clbit in circuit as test bit when appending IfElse This has no effect on the test. But, previously, we used a clbit taken from an unrelated circuit. This might give the impression that there is some significance to this unexpected choice. * In test, use bits in circuit as specifiers when appending gate to that circuit Previously we used qubits and clbits from an unrelated circuit to specify which bits to apply an IfElse to when appending. Here, we use bits from the same circuit that we are appending the gate to. This does not change the test. But again, one might look for significance in the previous unusual choice. Qiskit considers two registers of the same length and the same name to be the same register. The previous behavior depended on this choice. * In a test, don't use qubits from unrelated circuit when constructing circuit This has no effect on the test. As in the previous commits, the choice was unusual and might imply some significance. The more natural choice is to create new qubits by specifying the number. * Factor code in test to simplify test * Simplify remaining control flow op tests for ConsolidateBlocks These simplifications are similar to those made for the first test. * Run black * Update test/python/transpiler/test_consolidate_blocks.py Co-authored-by: Jake Lishman <[email protected]> --------- Co-authored-by: Jake Lishman <[email protected]>
- Loading branch information