Skip to content

Commit 608e678

Browse files
authored
Remove cirq.IonDevice.can_add_operation_into_moment (#4271)
Removes `cirq.IonDevice.can_add_operation_into_moment` as it doesn't add any value. I noticed that `cirq.IonDevice.can_add_operation_into_moment` implementation was doing a complicated version of a simple qubit overlap testing.
1 parent 534b951 commit 608e678

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

cirq-core/cirq/ion/ion_device.py

+1-28
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, cast, FrozenSet, Iterable, Optional, Set, TYPE_CHECKING
15+
from typing import Any, FrozenSet, Iterable, Optional, Set, TYPE_CHECKING
1616

1717
from cirq import circuits, value, devices, ops, protocols
1818
from cirq.ion import convert_to_ion_gates
@@ -104,37 +104,10 @@ def validate_operation(self, operation):
104104
if q not in self.qubits:
105105
raise ValueError(f'Qubit not on device: {q!r}')
106106

107-
def _check_if_XXPow_operation_interacts_with_any(
108-
self, XXPow_op: ops.GateOperation, others: Iterable[ops.GateOperation]
109-
) -> bool:
110-
return any(self._check_if_XXPow_operation_interacts(XXPow_op, op) for op in others)
111-
112-
def _check_if_XXPow_operation_interacts(
113-
self, XXPow_op: ops.GateOperation, other_op: ops.GateOperation
114-
) -> bool:
115-
if isinstance(
116-
other_op.gate,
117-
(ops.XPowGate, ops.YPowGate, ops.PhasedXPowGate, ops.MeasurementGate, ops.ZPowGate),
118-
):
119-
return False
120-
121-
return any(q == p for q in XXPow_op.qubits for p in other_op.qubits)
122-
123107
def validate_circuit(self, circuit: circuits.Circuit):
124108
super().validate_circuit(circuit)
125109
_verify_unique_measurement_keys(circuit.all_operations())
126110

127-
def can_add_operation_into_moment(self, operation: ops.Operation, moment: ops.Moment) -> bool:
128-
129-
if not super().can_add_operation_into_moment(operation, moment):
130-
return False
131-
if isinstance(operation.gate, ops.XXPowGate):
132-
return not self._check_if_XXPow_operation_interacts_with_any(
133-
cast(ops.GateOperation, operation),
134-
cast(Iterable[ops.GateOperation], moment.operations),
135-
)
136-
return True
137-
138111
def at(self, position: int) -> Optional[devices.LineQubit]:
139112
"""Returns the qubit at the given position, if there is one, else None."""
140113
q = devices.LineQubit(position)

cirq-core/cirq/ion/ion_device_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
from datetime import timedelta
16-
import pytest
1716

1817
import numpy as np
18+
import pytest
1919

2020
import cirq
2121
import cirq.ion as ci
@@ -160,6 +160,8 @@ def test_can_add_operation_into_moment():
160160
assert not d.can_add_operation_into_moment(cirq.XX(q1, q2), moment)
161161
assert d.can_add_operation_into_moment(cirq.XX(q2, q3), moment)
162162
assert d.can_add_operation_into_moment(cirq.Z(q3), moment)
163+
circuit = cirq.Circuit([cirq.X(q0)])
164+
assert d.can_add_operation_into_moment(cirq.XX(q1, q2), circuit[0])
163165

164166

165167
def test_ion_device_eq():

0 commit comments

Comments
 (0)