Пример #1
0
    def convert_acquire(self, instruction):
        """Return converted `AcquireInstruction`.

        Args:
            instruction (PulseQobjInstruction): acquire qobj
        Returns:
            Schedule: Converted and scheduled Instruction
        """
        t0 = instruction.t0
        duration = instruction.duration
        qubits = instruction.qubits
        discriminators = (instruction.discriminators if hasattr(
            instruction, 'discriminators') else None)

        kernels = (instruction.kernels
                   if hasattr(instruction, 'kernels') else None)

        mem_slots = instruction.memory_slot
        reg_slots = (instruction.register_slot if hasattr(
            instruction, 'register_slot') else None)

        if not isinstance(discriminators, list):
            discriminators = [discriminators for _ in range(len(qubits))]

        if not isinstance(kernels, list):
            kernels = [kernels for _ in range(len(qubits))]

        schedule = Schedule()

        for i, qubit in enumerate(qubits):
            kernel = kernels[i]
            if kernel:
                kernel = commands.Kernel(name=kernel.name,
                                         params=kernel.params)

            discriminator = discriminators[i]
            if discriminator:
                discriminator = commands.Discriminator(
                    name=discriminator.name, params=discriminator.params)

            channel = channels.AcquireChannel(qubit, buffer=self.buffer)
            if reg_slots:
                register_slot = channels.RegisterSlot(reg_slots[i])
            else:
                register_slot = None
            memory_slot = channels.MemorySlot(mem_slots[i])

            cmd = commands.Acquire(duration,
                                   discriminator=discriminator,
                                   kernel=kernel)
            schedule |= commands.AcquireInstruction(cmd, channel, memory_slot,
                                                    register_slot) << t0

        return schedule
Пример #2
0
    def convert_acquire(self, instruction):
        """Return converted `AcquireInstruction`.

        Args:
            instruction (PulseQobjInstruction): acquire qobj
        Returns:
            Schedule: Converted and scheduled Instruction
        """
        t0 = instruction.t0
        duration = instruction.duration
        qubits = instruction.qubits
        qubit_channels = [channels.AcquireChannel(qubit) for qubit in qubits]

        mem_slots = [channels.MemorySlot(instruction.memory_slot[i]) for i in range(len(qubits))]

        if hasattr(instruction, 'register_slot'):
            register_slots = [channels.RegisterSlot(instruction.register_slot[i])
                              for i in range(len(qubits))]
        else:
            register_slots = None

        discriminators = (instruction.discriminators
                          if hasattr(instruction, 'discriminators') else None)
        if not isinstance(discriminators, list):
            discriminators = [discriminators]
        if any(discriminators[i] != discriminators[0] for i in range(len(discriminators))):
            warnings.warn("Can currently only support one discriminator per acquire. Defaulting "
                          "to first discriminator entry.")
        discriminator = discriminators[0]
        if discriminator:
            discriminator = commands.Discriminator(name=discriminators[0].name,
                                                   params=discriminators[0].params)

        kernels = (instruction.kernels
                   if hasattr(instruction, 'kernels') else None)
        if not isinstance(kernels, list):
            kernels = [kernels]
        if any(kernels[0] != kernels[i] for i in range(len(kernels))):
            warnings.warn("Can currently only support one kernel per acquire. Defaulting to first "
                          "kernel entry.")
        kernel = kernels[0]
        if kernel:
            kernel = commands.Kernel(name=kernels[0].name, params=kernels[0].params)

        cmd = commands.Acquire(duration, discriminator=discriminator, kernel=kernel)
        schedule = Schedule()
        schedule |= commands.AcquireInstruction(cmd, qubit_channels, mem_slots,
                                                register_slots) << t0

        return schedule