|
16 | 16 | from cmath import exp
|
17 | 17 | import numpy
|
18 | 18 | from qiskit.circuit.controlledgate import ControlledGate
|
19 |
| -from qiskit.circuit.annotated_operation import AnnotatedOperation, ControlModifier |
20 | 19 | from qiskit.circuit.gate import Gate
|
21 | 20 | from qiskit.circuit.quantumregister import QuantumRegister
|
22 | 21 | from qiskit.circuit.parameterexpression import ParameterValueType
|
@@ -112,23 +111,18 @@ def control(
|
112 | 111 | Returns:
|
113 | 112 | ControlledGate: controlled version of this gate.
|
114 | 113 | """
|
115 |
| - if not annotated: |
116 |
| - if num_ctrl_qubits == 1: |
117 |
| - gate = CPhaseGate(self.params[0], label=label, ctrl_state=ctrl_state) |
118 |
| - gate.base_gate.label = self.label |
119 |
| - elif ctrl_state is None and num_ctrl_qubits > 1: |
120 |
| - gate = MCPhaseGate(self.params[0], num_ctrl_qubits, label=label) |
121 |
| - gate.base_gate.label = self.label |
122 |
| - else: |
123 |
| - gate = super().control( |
124 |
| - num_ctrl_qubits=num_ctrl_qubits, |
125 |
| - label=label, |
126 |
| - ctrl_state=ctrl_state, |
127 |
| - annotated=annotated, |
128 |
| - ) |
| 114 | + if not annotated and num_ctrl_qubits == 1: |
| 115 | + gate = CPhaseGate(self.params[0], label=label, ctrl_state=ctrl_state) |
| 116 | + gate.base_gate.label = self.label |
| 117 | + elif not annotated and ctrl_state is None and num_ctrl_qubits > 1: |
| 118 | + gate = MCPhaseGate(self.params[0], num_ctrl_qubits, label=label) |
| 119 | + gate.base_gate.label = self.label |
129 | 120 | else:
|
130 |
| - gate = AnnotatedOperation( |
131 |
| - self, ControlModifier(num_ctrl_qubits=num_ctrl_qubits, ctrl_state=ctrl_state) |
| 121 | + gate = super().control( |
| 122 | + num_ctrl_qubits=num_ctrl_qubits, |
| 123 | + label=label, |
| 124 | + ctrl_state=ctrl_state, |
| 125 | + annotated=annotated, |
132 | 126 | )
|
133 | 127 | return gate
|
134 | 128 |
|
@@ -255,20 +249,15 @@ def control(
|
255 | 249 | Returns:
|
256 | 250 | ControlledGate: controlled version of this gate.
|
257 | 251 | """
|
258 |
| - if not annotated: |
259 |
| - if ctrl_state is None: |
260 |
| - gate = MCPhaseGate(self.params[0], num_ctrl_qubits=num_ctrl_qubits + 1, label=label) |
261 |
| - gate.base_gate.label = self.label |
262 |
| - else: |
263 |
| - gate = super().control( |
264 |
| - num_ctrl_qubits=num_ctrl_qubits, |
265 |
| - label=label, |
266 |
| - ctrl_state=ctrl_state, |
267 |
| - annotated=annotated, |
268 |
| - ) |
| 252 | + if not annotated and ctrl_state is None: |
| 253 | + gate = MCPhaseGate(self.params[0], num_ctrl_qubits=num_ctrl_qubits + 1, label=label) |
| 254 | + gate.base_gate.label = self.label |
269 | 255 | else:
|
270 |
| - gate = AnnotatedOperation( |
271 |
| - self, ControlModifier(num_ctrl_qubits=num_ctrl_qubits, ctrl_state=ctrl_state) |
| 256 | + gate = super().control( |
| 257 | + num_ctrl_qubits=num_ctrl_qubits, |
| 258 | + label=label, |
| 259 | + ctrl_state=ctrl_state, |
| 260 | + annotated=annotated, |
272 | 261 | )
|
273 | 262 | return gate
|
274 | 263 |
|
@@ -381,24 +370,19 @@ def control(
|
381 | 370 | Returns:
|
382 | 371 | ControlledGate: controlled version of this gate.
|
383 | 372 | """
|
384 |
| - if not annotated: |
385 |
| - if ctrl_state is None: |
386 |
| - gate = MCPhaseGate( |
387 |
| - self.params[0], |
388 |
| - num_ctrl_qubits=num_ctrl_qubits + self.num_ctrl_qubits, |
389 |
| - label=label, |
390 |
| - ) |
391 |
| - gate.base_gate.label = self.label |
392 |
| - else: |
393 |
| - gate = super().control( |
394 |
| - num_ctrl_qubits=num_ctrl_qubits, |
395 |
| - label=label, |
396 |
| - ctrl_state=ctrl_state, |
397 |
| - annotated=annotated, |
398 |
| - ) |
| 373 | + if not annotated and ctrl_state is None: |
| 374 | + gate = MCPhaseGate( |
| 375 | + self.params[0], |
| 376 | + num_ctrl_qubits=num_ctrl_qubits + self.num_ctrl_qubits, |
| 377 | + label=label, |
| 378 | + ) |
| 379 | + gate.base_gate.label = self.label |
399 | 380 | else:
|
400 |
| - gate = AnnotatedOperation( |
401 |
| - self, ControlModifier(num_ctrl_qubits=num_ctrl_qubits, ctrl_state=ctrl_state) |
| 381 | + gate = super().control( |
| 382 | + num_ctrl_qubits=num_ctrl_qubits, |
| 383 | + label=label, |
| 384 | + ctrl_state=ctrl_state, |
| 385 | + annotated=annotated, |
402 | 386 | )
|
403 | 387 | return gate
|
404 | 388 |
|
|
0 commit comments