Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cirq.IonDevice.can_add_operation_into_moment #4271

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 1 addition & 28 deletions cirq-core/cirq/ion/ion_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion cirq-core/cirq/ion/ion_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -160,6 +160,8 @@ 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():
Expand Down