diff --git a/src/iqm/cirq_iqm/devices/iqm_device.py b/src/iqm/cirq_iqm/devices/iqm_device.py index f3d75c26..88887ebd 100644 --- a/src/iqm/cirq_iqm/devices/iqm_device.py +++ b/src/iqm/cirq_iqm/devices/iqm_device.py @@ -99,7 +99,7 @@ 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() @@ -107,10 +107,12 @@ def has_valid_operation_targets(self, op: cirq.Operation) -> bool: ] 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 diff --git a/src/iqm/cirq_iqm/serialize.py b/src/iqm/cirq_iqm/serialize.py index 72b6c180..f380fbfe 100644 --- a/src/iqm/cirq_iqm/serialize.py +++ b/src/iqm/cirq_iqm/serialize.py @@ -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 diff --git a/tests/test_iqm_device.py b/tests/test_iqm_device.py index f1bf145d..c0bc1de1 100644 --- a/tests/test_iqm_device.py +++ b/tests/test_iqm_device.py @@ -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 ) @@ -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