Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use VF2Layout in all preset passmanagers (#7213)
* Use VF2Layout in all preset passmanagers With the introduction of the VF2Layout pass we now have a very fast method of searching for a perfect layout. Previously we only had the CSPLayout method for doing this which could be quite slow and we only used in level 2 and level 3. Since VF2Layout operates quickly adding the pass to each preset pass manager makes sense so we always use a perfect layout if available (or unless a user explicitly specifies an initial layout or layout method). This commit makes this change and adds VF2Layout to each optimization level and uses a perfect layout if found by default. Fixes #7156 * Revert changes to level 0 For optimization level 0 we don't actually want to use VF2Layout because while it can find a perfect layout it would be potentially surprising to users that the level which is supposed to have no optimizations picks a non-trivial layout. * Set seed on perfect layout test * Fix test failures and unexpected change in behavior This commit makes several changes to fix both unexpected changes in behavior and also update the default behavior of the vf2 layout pass. The first issues is that the vf2 pass was raising an exception if it was run with >2 qubit gates. This caused issues if we run with calibrations (or backends that support >2q gates) as vf2 layout is used as an opportunistic thing and if there is for example a 5q gate being used we shouldn't fail the entire transpile just because vf2 can't deal with it. It's only an issue if the later passes can't either, it just means vf2 won't be able to find a perfect layout. The second change is around the default seeding. For the preset pass managers to have a consistent output this removed the randomization if no seed is specified and just use an in order comparison. This is necessary to have a consistent layout for testing and reproducability, while we can set a seed everywhere, the previous behavior was more stable as it would default to trivial layout most of the time (assuming that was perfect). When we add multiple vf2 trials and are picking the best choice among those for a given time budget we can add back in the default seed randomization. The last change made here is that several tests implicitly expected a trivial layout (mainly around device aware transpilation or calibrations). In those cases the transpile wasn't valid for an arbitrary layout, for example if a calibrated gate is only defined on a single qubit. Using vf2 layout in those cases doesn't work because the gate is only defined on a single qubit so picking a non-trivial layout correctly errors. To fix these cases the tests are updated to explicitly state they require a trivial layout instead of assuming the transpiler will implicitly give them that if it's a perfect layout. * Add missing release note * Apply suggestions from code review in release note Co-authored-by: Jake Lishman <jake@binhbar.com> * Make vf2 layout stop reason an Enum * Update releasenotes/notes/vf2layout-preset-passmanager-db46513a24e79aa9.yaml Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Add back initial layout to level1 Since there seems to be a pretty baked in asumption for level 1 that it will use the trivial layout by default if it's a perfect mapping. This was causing the majority of the test failures and might be an unexpected breakage for people. However, in a future release we should remove this (likely when vf2layout is made noise aware). To anticipate this a FutureWarning is emitted when a trivial layout is used to indicate that this behavior will change in the future for level 1 and if you're relying on it you should explicitly set the layout_method='trivial'. * Tweak seeds to reduce effect of noise on fake_yorktown with aer * Update release note * Use id_order=True on vf2_mapping() for VF2Layout pass Using id_order=False orders the nodes by degree which biases the mapping found by vf2 towards nodes with higher connectivity which typically have higher error rates. Until the pass is made noise aware to counter this bias we should just use id_order=True which uses the node id for the order (which roughly matches insertion order) which won't have this bias in the results. * Revert "Use id_order=True on vf2_mapping() for VF2Layout pass" VF2 without the Vf2++ heuristic is too slow for some common use cases that we probably don't want to use it by default. Instead we should use some techniques to improve the quality of the results. The first approach will be applying a score heuristic to a found mapping. A potential follow on after that could be to do some pre-filtering of noisy nodes. This reverts commit 53d54c3. * Set real limits on calling vf2 and add quality heuristic This commit adds options to set limits on the vf2 pass, both the internal call limit for the vf2 execution in retworkx, a total time spent in the pass trying multiple layouts, and the number of trials to attempt. These are then set in the preset pass manager to ensure we don't sit spinning on vf2 forever in the real world. While the pass is generally fast there are edge cases where it can get stuck. At the same time this adds a rough quality heuristic (based on readout error falling back to connectivity) to select between multiple mappings found by retworkx. This addresses the poor quality results we were getting with vf2++ in earlier revisions as we can find the best from multiple mappings. * Remove initial layout default from level 1 Now that vf2 layout has limited noise awareness and multiple trials it no longer will be defaulting to the worst qubits like it was with only a single sample when vf2++ is used. This commit removes the implicit trivial layout attempt as it's no longer needed. * Remove unused imports * Use vigo instead of yorktown for oracle tests * Revert "Remove initial layout default from level 1" This is breaking the pulse tutorials, as fixing that is a more involved change and probably indicates we should continue to assume trivial layout by default if perfect for level 1 and raise a warning to users that it's going away to give everyone who needs a default trivial layout time to adjust their code. This commit reverts only using vf2 for level 1 and adds back in a trivial layout stage. This reverts commit df47835. This reverts commit 65ae6ee. * Fix warning and update docs to not emit one This commit fixes the warning so it's only emitted if the trivial layout is used, previously it would also be emitted if an initial layout was set. The the docs are updated to not emit the warning, in some cases code examples are updated to explicitly use a trivial layout if that's what's needed. In others there were needless jupyter-execute directives being used when there was no visualization and a code-block is just as effective (which avoids the execution during doc builds). * Add debug logging and fix heurstic usage * Add better test coverage of new pass features * Only run a single trial if the graphs are the same size If the interaction graph and the coupling graph are the same size currently the score heuristic will produce the same results since they just look at the sum of qubit noise (or degree). We don't need to run multiple trials or bother scoring things since we'll just pick the first mapping anyway. * Fix rebase error * Use enum type for stop reason condition * Add comment about call_limit value * Undo unecessary seed change * Add back default seed randomization After all the improvements to the VF2Layout pass in #7276 this was no longer needed. It was added back prior to #7276 where the vf2 layout pass was not behaving well for simple cases. * Permute operator bits based on layout The backendv2 transpilation tests were failing with vf2 layout enabled by default because we were no longer guaranteed to get an initial layout by default. The tests were checking for an equivalent operator between the output circuit and the input one. However, the use of vf2layout was potentially changing the bit order (especially at higher optimization levels) in the operator because a non trivial layout was selected. This caused the tests to fail. This commit fixes the test failures by adding a helper function to permute the qubits back based on the layout property in the transpiled circuit. * Fix docs build * Remove warning on use of TrivialLayout in opt level 1 The warning which was being emitted by an optimization level 1 transpile() if a trivial layout was used was decided to be too potentially noisy for users, especially because it wasn't directly actionable. For the first step of using vf2 layout everywhere we decided to leave level1 as trying a trivial layout first and then falling back to vf2 layout if the trivial layout isn't a perfect match. We'll investigate whether it makes sense in the future to change this behavior and come up with a migration plan when that happens. * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * Cleanup inline comment numbering in preset pass manager modules * Fix lint * Remove operator_permuted_layout() from backendv2 tests This commit removes the custom operator_permuted_layout() function from the backendv2 tests. This function was written to permute the qubits based on the output layout from transpile() so it can be compared to the input circuit for equivalence. However, since this PR was first opened a new constructor method Operator.from_circuit() was added in #7616 to handle this directly in the Operator construction instead of doing it out of band. THis commit just leverages the new constructor instead of having a duplicate local test function. * Remove unused import Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Kevin Krsulich <kevin@krsulich.net> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information