def test_init_timedelta(): assert Duration.create(timedelta(microseconds=0)).total_picos() == 0 assert Duration.create( timedelta(microseconds=513)).total_picos() == 513 * 10**6 assert Duration.create( timedelta(microseconds=-5)).total_picos() == -5 * 10**6 assert Duration.create( timedelta(microseconds=211)).total_picos() == 211 * 10**6 assert Duration.create(timedelta(seconds=3)).total_picos() == 3 * 10**12 assert Duration.create(timedelta(seconds=-5)).total_picos() == -5 * 10**12 assert Duration.create(timedelta(seconds=3)).total_nanos() == 3 * 10**9 assert Duration.create(timedelta(seconds=-5)).total_nanos() == -5 * 10**9
def __init__(self, measurement_duration: Union[Duration, timedelta], gate_duration: Union[Duration, timedelta], control_radius: float, max_parallel_z: int, max_parallel_xy: int, max_parallel_c: int, qubits: Iterable[GridQubit]) -> None: """ Initializes the description of the AQuA device. Args: measurement_duration: the maximum duration of a measurement. gate_duration: the maximum duration of a gate control_radius: the maximum distance between qubits for a controlled gate. Distance is measured in units of the indices passed into the GridQubit constructor. max_parallel_z: The maximum number of qubits that can be acted on in parallel by a Z gate max_parallel_xy: The maximum number of qubits that can be acted on in parallel by a local XY gate max_parallel_c: the maximum number of qubits that can be acted on in parallel by a controlled gate. Must be less than or equal to the lesser of max_parallel_z and max_parallel_xy qubits: Qubits on the device, identified by their x, y location. Must be of type GridQubit Raises: ValueError: if the wrong qubit type is provided or if invalid parallel parameters are provided """ self._measurement_duration = Duration.create(measurement_duration) self._gate_duration = Duration.create(gate_duration) self._control_radius = control_radius self._max_parallel_z = max_parallel_z self._max_parallel_xy = max_parallel_xy if max_parallel_c > min(max_parallel_z, max_parallel_xy): raise ValueError("max_parallel_c must be less than or equal to the" "min of max_parallel_z and max_parallel_xy") self._max_parallel_c = max_parallel_c for q in qubits: if not isinstance(q, GridQubit): raise ValueError('Unsupported qubit type: {!r}'.format(q)) self.qubits = frozenset(qubits)
def __init__(self, time: Timestamp, duration: Union[Duration, timedelta], operation: ops.Operation) -> None: """Initializes the scheduled operation. Args: time: When the operation starts. duration: How long the operation lasts. operation: The operation. """ self.time = time self.duration = Duration.create(duration) self.operation = operation
def query( self, *, # Forces keyword args. time: Timestamp, duration: Union[Duration, timedelta] = Duration(), qubits: Iterable[Qid] = None, include_query_end_time=False, include_op_end_times=False) -> List[ScheduledOperation]: """Finds operations by time and qubit. Args: time: Operations must end after this time to be returned. duration: Operations must start by time+duration to be returned. qubits: If specified, only operations touching one of the included qubits will be returned. include_query_end_time: Determines if the query interval includes its end time. Defaults to no. include_op_end_times: Determines if the scheduled operation intervals include their end times or not. Defaults to no. Returns: A list of scheduled operations meeting the specified conditions. """ duration = Duration.create(duration) earliest_time = time - self._max_duration end_time = time + duration qubits = None if qubits is None else frozenset(qubits) def overlaps_interval(op): if not include_op_end_times and op.time + op.duration == time: return False if not include_query_end_time and op.time == end_time: return False return op.time + op.duration >= time and op.time <= end_time def overlaps_qubits(op): if qubits is None: return True return not qubits.isdisjoint(op.operation.qubits) potential_matches = self.scheduled_operations.irange_key( earliest_time, end_time) return [ op for op in potential_matches if overlaps_interval(op) and overlaps_qubits(op) ]