From 83e164c096ff7a05480e0f8ac830b5d52f0bd8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Pat=C3=B3?= Date: Mon, 28 Jun 2021 18:17:01 -0400 Subject: [PATCH 1/2] coverage --- cirq-core/cirq/ion/ion_device_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cirq-core/cirq/ion/ion_device_test.py b/cirq-core/cirq/ion/ion_device_test.py index 8d04c083ab6..22e57a6fffc 100644 --- a/cirq-core/cirq/ion/ion_device_test.py +++ b/cirq-core/cirq/ion/ion_device_test.py @@ -160,6 +160,9 @@ def test_can_add_operation_into_moment(): assert not d.can_add_operation_into_moment(cirq.XX(q1, q2), moment) assert d.can_add_operation_into_moment(cirq.XX(q2, q3), moment) assert d.can_add_operation_into_moment(cirq.Z(q3), moment) + circuit = cirq.Circuit([cirq.X(q0)]) + assert d.can_add_operation_into_moment(cirq.XX(q1, q2), circuit[0]) + def test_ion_device_eq(): From dd2c3772e8c32e93011cf1c396fbe5f84e7189b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Pat=C3=B3?= Date: Tue, 29 Jun 2021 13:46:45 -0400 Subject: [PATCH 2/2] simplify ion device --- cirq-core/cirq/ion/ion_device.py | 29 +-------------------------- cirq-core/cirq/ion/ion_device_test.py | 3 +-- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/cirq-core/cirq/ion/ion_device.py b/cirq-core/cirq/ion/ion_device.py index 82625425f9d..0643012df26 100644 --- a/cirq-core/cirq/ion/ion_device.py +++ b/cirq-core/cirq/ion/ion_device.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, cast, FrozenSet, Iterable, Optional, Set, TYPE_CHECKING +from typing import Any, FrozenSet, Iterable, Optional, Set, TYPE_CHECKING from cirq import circuits, value, devices, ops, protocols from cirq.ion import convert_to_ion_gates @@ -104,37 +104,10 @@ def validate_operation(self, operation): if q not in self.qubits: raise ValueError(f'Qubit not on device: {q!r}') - def _check_if_XXPow_operation_interacts_with_any( - self, XXPow_op: ops.GateOperation, others: Iterable[ops.GateOperation] - ) -> bool: - return any(self._check_if_XXPow_operation_interacts(XXPow_op, op) for op in others) - - def _check_if_XXPow_operation_interacts( - self, XXPow_op: ops.GateOperation, other_op: ops.GateOperation - ) -> bool: - if isinstance( - other_op.gate, - (ops.XPowGate, ops.YPowGate, ops.PhasedXPowGate, ops.MeasurementGate, ops.ZPowGate), - ): - return False - - return any(q == p for q in XXPow_op.qubits for p in other_op.qubits) - def validate_circuit(self, circuit: circuits.Circuit): super().validate_circuit(circuit) _verify_unique_measurement_keys(circuit.all_operations()) - def can_add_operation_into_moment(self, operation: ops.Operation, moment: ops.Moment) -> bool: - - if not super().can_add_operation_into_moment(operation, moment): - return False - if isinstance(operation.gate, ops.XXPowGate): - return not self._check_if_XXPow_operation_interacts_with_any( - cast(ops.GateOperation, operation), - cast(Iterable[ops.GateOperation], moment.operations), - ) - return True - def at(self, position: int) -> Optional[devices.LineQubit]: """Returns the qubit at the given position, if there is one, else None.""" q = devices.LineQubit(position) diff --git a/cirq-core/cirq/ion/ion_device_test.py b/cirq-core/cirq/ion/ion_device_test.py index 22e57a6fffc..94736d346f0 100644 --- a/cirq-core/cirq/ion/ion_device_test.py +++ b/cirq-core/cirq/ion/ion_device_test.py @@ -13,9 +13,9 @@ # limitations under the License. from datetime import timedelta -import pytest import numpy as np +import pytest import cirq import cirq.ion as ci @@ -164,7 +164,6 @@ def test_can_add_operation_into_moment(): assert d.can_add_operation_into_moment(cirq.XX(q1, q2), circuit[0]) - def test_ion_device_eq(): eq = cirq.testing.EqualsTester() eq.make_equality_group(lambda: ion_device(3))