|
28 | 28 | FoldRzzAngle, |
29 | 29 | ) |
30 | 30 |
|
| 31 | +from ..utils.deprecation import issue_deprecation_msg |
| 32 | + |
31 | 33 | _TERRA_VERSION = tuple( |
32 | 34 | int(x) for x in re.match(r"\d+\.\d+\.\d", _terra_version_string).group(0).split(".")[:3] |
33 | 35 | ) |
@@ -114,13 +116,22 @@ def pass_manager( |
114 | 116 |
|
115 | 117 |
|
116 | 118 | class IBMFractionalTranslationPlugin(PassManagerStagePlugin): |
117 | | - """A translation stage plugin for targeting Qiskit circuits |
| 119 | + """(DEPRECATED) A translation stage plugin for targeting Qiskit circuits |
118 | 120 | to IBM Quantum systems with fractional gate support. |
119 | 121 |
|
120 | 122 | Currently coexistence of fractional gate operations and |
121 | 123 | dynamic circuits is not assumed. |
122 | 124 | """ |
123 | 125 |
|
| 126 | + def __new__(cls, *args, **kwargs): |
| 127 | + issue_deprecation_msg( |
| 128 | + msg="Since backends now support running jobs that contain both " |
| 129 | + "fractional gates and dynamic circuit, IBMFractionalTranslationPlugin is deprecated", |
| 130 | + version="0.42.0", |
| 131 | + remedy="Use IBMDynamicFractionalTranslationPlugin instead.", |
| 132 | + ) |
| 133 | + return super().__new__(cls, *args, **kwargs) |
| 134 | + |
124 | 135 | def pass_manager( |
125 | 136 | self, |
126 | 137 | pass_manager_config: PassManagerConfig, |
@@ -154,3 +165,47 @@ def pass_manager( |
154 | 165 | # Apply this pass after SU4 is translated. |
155 | 166 | post_passes.append(FoldRzzAngle()) |
156 | 167 | return PassManager(pre_passes) + translator_pm + PassManager(post_passes) |
| 168 | + |
| 169 | + |
| 170 | +class IBMDynamicFractionalTranslationPlugin(PassManagerStagePlugin): |
| 171 | + """A translation stage plugin for targeting Qiskit circuits |
| 172 | + to IBM Quantum systems with both dynamic circuits and fractional gate support. |
| 173 | + """ |
| 174 | + |
| 175 | + def pass_manager( |
| 176 | + self, |
| 177 | + pass_manager_config: PassManagerConfig, |
| 178 | + optimization_level: Optional[int] = None, |
| 179 | + ) -> PassManager: |
| 180 | + """Build IBMTranslationPlugin PassManager.""" |
| 181 | + |
| 182 | + if _TERRA_VERSION[0] == 1: |
| 183 | + legacy_options = {"backend_props": pass_manager_config.backend_properties} |
| 184 | + else: |
| 185 | + legacy_options = {} |
| 186 | + |
| 187 | + translator_pm = common.generate_translation_passmanager( |
| 188 | + target=pass_manager_config.target, |
| 189 | + basis_gates=pass_manager_config.basis_gates, |
| 190 | + approximation_degree=pass_manager_config.approximation_degree, |
| 191 | + coupling_map=pass_manager_config.coupling_map, |
| 192 | + unitary_synthesis_method=pass_manager_config.unitary_synthesis_method, |
| 193 | + unitary_synthesis_plugin_config=pass_manager_config.unitary_synthesis_plugin_config, |
| 194 | + hls_config=pass_manager_config.hls_config, |
| 195 | + **legacy_options, |
| 196 | + ) |
| 197 | + |
| 198 | + instruction_durations = pass_manager_config.instruction_durations |
| 199 | + pre_passes = [] |
| 200 | + post_passes = [] |
| 201 | + target = pass_manager_config.target or pass_manager_config.basis_gates |
| 202 | + if instruction_durations and not "id" in target: |
| 203 | + pre_passes.append(ConvertIdToDelay(instruction_durations)) |
| 204 | + if "rzz" in target: |
| 205 | + # Apply this pass after SU4 is translated. |
| 206 | + post_passes.append(FoldRzzAngle()) |
| 207 | + |
| 208 | + if (convert_pass := getattr(passes, "ConvertConditionsToIfOps", None)) is not None: |
| 209 | + # If `None`, we're dealing with Qiskit 2.0+ where it's unnecessary anyway. |
| 210 | + pre_passes += [convert_pass()] # pylint: disable=not-callable |
| 211 | + return PassManager(pre_passes) + translator_pm + PassManager(post_passes) |
0 commit comments