def get_bound_method(self, bound): """Get conversion method for bound object.""" try: return self._bound_instructions[bound] except KeyError as ex: raise QiskitError( f"Bound method for {bound} is not found.") from ex
def instruction_duration_validation(duration: int): """Validate instruction duration. Args: duration: Instruction duration value to validate. Raises: UnassignedDurationError: When duration is unassigned. QiskitError: When invalid duration is assigned. """ if isinstance(duration, ParameterExpression): raise UnassignedDurationError( 'Instruction duration {} is not assigned. ' 'Please bind all durations to an integer value before playing in the Schedule, ' 'or use ScheduleBlock to align instructions with unassigned duration.' ''.format(repr(duration))) if not isinstance(duration, (int, np.integer)) or duration < 0: raise QiskitError( 'Instruction duration must be a non-negative integer, ' 'got {} instead.'.format(duration))
def get_channel(self, channel: str) -> channels.PulseChannel: """Parse and retrieve channel from ch string. Args: channel: Channel to match Returns: Matched channel Raises: QiskitError: Is raised if valid channel is not matched """ match = self.chan_regex.match(channel) if match: prefix, index = match.group(1), int(match.group(2)) if prefix == channels.DriveChannel.prefix: return channels.DriveChannel(index) elif prefix == channels.MeasureChannel.prefix: return channels.MeasureChannel(index) elif prefix == channels.ControlChannel.prefix: return channels.ControlChannel(index) raise QiskitError("Channel %s is not valid" % channel)
def convert_bundled_acquires( self, shift, instructions_, ): """Bundle a list of acquires instructions at the same time into a single Qobj acquire instruction. Args: shift (int): Offset time. instructions_ (List[Acquire]): List of acquire instructions to bundle. Returns: dict: Dictionary of required parameters. Raises: QiskitError: If ``instructions`` is empty. """ if not instructions_: raise QiskitError('"instructions" may not be empty.') meas_level = self._run_config.get("meas_level", 2) t0 = instructions_[0].start_time duration = instructions_[0].duration memory_slots = [] register_slots = [] qubits = [] discriminators = [] kernels = [] for instruction in instructions_: qubits.append(instruction.channel.index) if instruction.start_time != t0: raise QiskitError( "The supplied acquire instructions have different starting times. " "Something has gone wrong calling this code. Please report this " "issue." ) if instruction.duration != duration: raise QiskitError( "Acquire instructions beginning at the same time must have same duration." ) if instruction.mem_slot: memory_slots.append(instruction.mem_slot.index) if meas_level == MeasLevel.CLASSIFIED: # setup discriminators if instruction.discriminator: discriminators.append( QobjMeasurementOption( name=instruction.discriminator.name, params=instruction.discriminator.params, ) ) # setup register_slots if instruction.reg_slot: register_slots.append(instruction.reg_slot.index) if meas_level in [MeasLevel.KERNELED, MeasLevel.CLASSIFIED]: # setup kernels if instruction.kernel: kernels.append( QobjMeasurementOption( name=instruction.kernel.name, params=instruction.kernel.params ) ) command_dict = { "name": "acquire", "t0": t0 + shift, "duration": duration, "qubits": qubits, } if memory_slots: command_dict["memory_slot"] = memory_slots if register_slots: command_dict["register_slot"] = register_slots if discriminators: num_discriminators = len(discriminators) if num_discriminators == len(qubits) or num_discriminators == 1: command_dict["discriminators"] = discriminators else: raise QiskitError( "A discriminator must be supplied for every acquisition or a single " "discriminator for all acquisitions." ) if kernels: num_kernels = len(kernels) if num_kernels == len(qubits) or num_kernels == 1: command_dict["kernels"] = kernels else: raise QiskitError( "A kernel must be supplied for every acquisition or a single " "kernel for all acquisitions." ) return self._qobj_model(**command_dict)
def get_bound_method(self, bound): """Get conversion method for bound object.""" try: return self._bound_instructions[bound] except KeyError: raise QiskitError('Bound method for %s is not found.' % bound)