Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start making the transpiler Target aware (#7227)
* Start making the BasisTranslator Target/BackendV2 aware In #5885 we added the next version of the abstract Backend interface BackendV2 which added the concept of a Target which represents a compiler target for the transpiler. It contains all the information about the constraints of a backend for the compiler to use and replaces the combination of basis_gates, coupling_map, etc and expands the representation to model more complex devices. However, in #5885 we only introduced the interface and didn't modify the transpiler to use the Target natively or any of the extra information it contains. This commit is the start of the process of updated the transpiler to work with a target natively. To start if a backend has a target that is now passed through from transpile to the passmanager_config so we can start passing it directly to passes as we enable it. Then the basis translator is updated to work natively with a target instead of the basis gates list it used before. In addition to using a target directly support is added for heterogeneous gate sets so that target instructions can work on only a subset of qargs. Building off this in the future There are additional features in target that we might want to expand support for in the BasisTranslator in the future, such as supporting custom variants of the same gate, or handling fixed angle rotation gate variants, etc. * Deduplicate computation of non-global operations The modifications to the BasisTranslator needed to compute operations in the basis which weren't global for a particular target and accomplished this via a dedicated helper function in the pass module. However the BackendV2 class had an identical function for accomplishing this so it could log a warning when basis gates were queried. This commit deduplicates them and creates a dedicated method on the target for returning the list (and caches it so it's only computed once per target). * Add missing check for a dag calibration on the target path * Rename extra_basis_transforms -> qarg_local_basis_transforms * Make GateDirection and CheckGateDirection Target aware too In debugging the basis translator changes we realized that we should be relying on the GateDirection pass to fix directionality on non-symmetric 2q gates instead of trying to handle it natively in the basis translator for now. To do this with a target we need to make the GateDirection and CheckGateDirection passes target aware and update the basis translator to treat all 2q gates as symmetric. This commit makes this change and updates the preset pass managers to pass targets to GateDirection and CheckGateDirection (also updates the rule determining if we need to run them to leverage the target not the coupling map). * Handle working with a non-global 1q basis In the case of a non-global 1q basis where there are 1q gates only available on a subset of qubits the basis translator was not correctly able to translate multi-qubit gates. This was due to how the local basis search was done just on the global target basis gates and the local target basis gates for that argument, with multi-qubit gates the translations also typically involve a 1q rotation. But if there are no global 1q gates those rotation gates can't be translated and the search fails. To address this the 1q local gates for the individual qubits in the multi-qubit argument are added to the local search for non-global multi-qubit gates. * Also use target for gate direction in level 0 * Add release notes * Consider all non-local subset operations for multiqubit non local gates * Update qiskit/providers/backend.py Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Finish incomplete strict_direction docstring * Adjust tests to be fp precision tolerant * Relax tests further for windows * Update qiskit/transpiler/target.py Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Correct detection of non-global ops with strict_direction=False Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com> * Fix handling of non-local subset searching * Simplify target path in gate direction pass * Rename extra_source_basis -> local_source_basis * Rename incomplete_basis -> non_global_operations * Rename qarg_with_incomplete -> qargs_with_non_global_operation and incomplete_source_basis -> qargs_local_source_basis * Update target handling in transpile() This fixes 2 issues found in review with the the transpile() functions handling of target. First if a target kwarg is passed by a user that target will be used instead of the backend for not just the target but also all derived quantities (such as coupling_map and basis_gates). Also previously the backend_properties field was not being correctly built from a target (both for a backendv2 or a standalone target). So a converter helper function was added to go from a target and build a BackendPropeties object from the data contained in the target. This will enable noise aware transpilation until the transpiler passes are all target aware. * Calculate qargs with non global operation once per pass instance * Expand docstring to include non-global operation behavior description * Add test assertion that it matches the target * Add GateDirection to the optimization loop for level 3 Optimization level 3 is different from the other lower optimization levels because it uses unitary synthesis by default. The unitary synthesis pass is basis and coupling map to optimize the synthesized circuit for a unitary to be hardware efficient. However when using a target the basis gates and coupling map don't give a complete picture of the device constraints (mainly the non-global gates if any). To account for this we need to run the gate direction pass after unitary synthesis to correct an incorrect decision the unitary synthesis pass might make based on it's incomplete data. Once UnitarySynthesis is target aware we probably do not require this anymore. * Add tests of 5q ghz on non-linear non-global target with different entangling gates * Use frozenset instead of tuple for local search and transformation tracking * Fix copy paste error for gate error in _target_to_backend_properties * Apply suggestions from code review Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Only run gate direction in level 3 with a target * Move target overrides inside _parse_transpile_args() Co-authored-by: Kevin Krsulich <kevin@krsulich.net> Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
- Loading branch information