Skip to content

Commit

Permalink
Added reviewer feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Arianne Meijer committed Aug 28, 2024
1 parent b8ab02a commit 6cd4b7f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/iqm/cirq_iqm/devices/iqm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,20 @@ def is_native_operation(self, op: cirq.Operation) -> bool:
return check

def has_valid_operation_targets(self, op: cirq.Operation) -> bool:
"""Predicate, True iff the given operation is native and it=s targets are valid."""
"""Predicate, True iff the given operation is native and its targets are valid."""
matched_support = [
(g, qbs)
for g, qbs in self.supported_operations.items()
if op.gate is not None and op.gate in cirq.GateFamily(g)
]
if len(matched_support) > 0:
gf, valid_targets = matched_support[0]
valid_qubits = set(q for qb in valid_targets for q in qb)
if gf == cirq.MeasurementGate: # Measurements can be done on any available qubits
return all(q in [q for qb in valid_targets for q in qb] for q in op.qubits)
return all(q in valid_qubits for q in op.qubits)
if issubclass(gf, cirq.InterchangeableQubitsGate):
return any(len(t) == len(op.qubits) and all(q1 in t for q1 in op.qubits) for t in valid_targets)
target_qubits = set(op.qubits)
return any(set(t) == target_qubits for t in valid_targets)
return any(all(q1 == q2 for q1, q2 in zip_longest(op.qubits, t)) for t in valid_targets)
return False

Expand Down
2 changes: 1 addition & 1 deletion src/iqm/cirq_iqm/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

"""
Circuit sampler that executes quantum circuits on an IQM quantum computer.
Helper functions for serializing and deserializing quantum circuits between Cirq and IQM Circuit formats.
"""
from cirq import Circuit

Expand Down
9 changes: 9 additions & 0 deletions tests/test_iqm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_device_with_resonator(device_with_resonator):
assert_qubit_indexing(
device_with_resonator, set(zip(range(1, len(device_with_resonator.qubits) + 1), device_with_resonator.qubits))
)
assert len(device_with_resonator.resonators) == 1
assert device_with_resonator.resonators[0] == NamedQid(
"COMP_R", device_with_resonator._metadata.RESONATOR_DIMENSION
)
Expand Down Expand Up @@ -152,6 +153,14 @@ def test_validate_moves(device_with_resonator):
with pytest.raises(ValueError):
device_with_resonator.validate_moves(circuit)

# Test odd valid MOVEs (incomplete sandwich)
circuit = Circuit(
IQMMoveGate()(device_with_resonator.qubits[0], device_with_resonator.resonators[0]),
IQMMoveGate()(device_with_resonator.qubits[0], device_with_resonator.resonators[0]),
IQMMoveGate()(device_with_resonator.qubits[0], device_with_resonator.resonators[0]),
)
with pytest.raises(ValueError):
device_with_resonator.validate_moves(circuit)
# Test no moves
circuit = Circuit()
assert device_with_resonator.validate_moves(circuit) is None
Expand Down

0 comments on commit 6cd4b7f

Please sign in to comment.