def target(self, qubits, channel): """Changes the target qubit of a 'Local' channel. Args: qubits (hashable, iterable): The new target for this channel. Must correspond to a qubit ID in device or an iterable of qubit IDs, when multi-qubit adressing is possible. channel (str): The channel's name provided when declared. Must be a channel with 'Local' addressing. """ if channel not in self._channels: raise ValueError("Use the name of a declared channel.") if isinstance(qubits, Iterable) and not isinstance(qubits, str): qs = set(qubits) else: qs = {qubits} if not qs.issubset(self._qids): raise ValueError("The given qubits have to belong to the device.") if self._channels[channel].addressing != 'Local': raise ValueError("Can only choose target of 'Local' channels.") elif len(qs) > self._channels[channel].max_targets: raise ValueError( "This channel can target at most " f"{self._channels[channel].max_targets} qubits at a time" ) basis = self._channels[channel].basis phase_refs = {self._phase_ref[basis][q].last_phase for q in qs} if len(phase_refs) != 1: raise ValueError("Cannot target multiple qubits with different " "phase references for the same basis.") try: last = self._last(channel) if last.targets == qs: warnings.warn("The provided qubits are already the target. " "Skipping this target instruction.") return ti = last.tf retarget = self._channels[channel].retarget_time elapsed = ti - self._last_target[channel] delta = np.clip(retarget - elapsed, 0, retarget) if delta != 0: with warnings.catch_warnings(): warnings.simplefilter("ignore") delta = validate_duration(np.clip(delta, 16, np.inf)) tf = ti + delta except ValueError: ti = -1 tf = 0 self._last_target[channel] = tf self._add_to_schedule(channel, _TimeSlot('target', ti, tf, qs))
def __init__(self, duration): """Initializes a waveform with a given duration. Args: duration (int): The waveforms duration (in multiples of 4 ns). """ self._duration = validate_duration(duration, min_duration=16, max_duration=4194304)
def _delay(self, duration, channel): self._validate_channel(channel) if self.is_parametrized(): return last = self._last(channel) ti = last.tf tf = ti + validate_duration(duration) self._add_to_schedule(channel, _TimeSlot('delay', ti, tf, last.targets))
def delay(self, duration, channel): """Idles a given channel for a specific duration. Args: duration (int): Time to delay (in multiples of 4 ns). channel (str): The channel's name provided when declared. """ last = self._last(channel) ti = last.tf tf = ti + validate_duration(duration) self._add_to_schedule(channel, _TimeSlot('delay', ti, tf, last.targets))
def _target(self, qubits, channel): self._validate_channel(channel) try: qs = set(qubits) if not isinstance(qubits, str) else {qubits} except TypeError: qs = {qubits} if self._channels[channel].addressing != 'Local': raise ValueError("Can only choose target of 'Local' channels.") elif len(qs) > self._channels[channel].max_targets: raise ValueError( "This channel can target at most " f"{self._channels[channel].max_targets} qubits at a time") if self.is_parametrized(): for q in qs: if q not in self._qids and not isinstance(q, Parametrized): raise ValueError("All non-variable qubits must belong to " "the register.") return elif not qs.issubset(self._qids): raise ValueError("All given qubits must belong to the register.") basis = self._channels[channel].basis phase_refs = {self._phase_ref[basis][q].last_phase for q in qs} if len(phase_refs) != 1: raise ValueError("Cannot target multiple qubits with different " "phase references for the same basis.") try: last = self._last(channel) if last.targets == qs: warnings.warn("The provided qubits are already the target. " "Skipping this target instruction.") return ti = last.tf retarget = self._channels[channel].retarget_time elapsed = ti - self._last_target[channel] delta = np.clip(retarget - elapsed, 0, retarget) if delta != 0: with warnings.catch_warnings(): warnings.simplefilter("ignore") delta = validate_duration(np.clip(delta, 16, np.inf)) tf = ti + delta except ValueError: ti = -1 tf = 0 self._last_target[channel] = tf self._add_to_schedule(channel, _TimeSlot('target', ti, tf, qs))