Example #1
0
    def get_frame_changes(self) -> Iterator[PulseInstruction]:
        """Return frame change type instructions with total frame change amount."""
        # TODO parse parametrised FCs correctly

        sorted_frame_changes = sorted(self._frames.items(), key=lambda x: x[0])

        phase = self._init_phase
        frequency = self._init_frequency
        for t0, frame_changes in sorted_frame_changes:
            is_opaque = False

            pre_phase = phase
            pre_frequency = frequency
            phase, frequency = ChannelEvents._calculate_current_frame(
                frame_changes=frame_changes, phase=phase, frequency=frequency)

            # keep parameter expression to check either phase or frequency is parametrized
            frame = PhaseFreqTuple(phase - pre_phase,
                                   frequency - pre_frequency)

            # remove parameter expressions to find if next frame is parametrized
            if isinstance(phase, circuit.ParameterExpression):
                phase = float(
                    phase.bind({param: 0
                                for param in phase.parameters}))
                is_opaque = True
            if isinstance(frequency, circuit.ParameterExpression):
                frequency = float(
                    frequency.bind(
                        {param: 0
                         for param in frequency.parameters}))
                is_opaque = True

            yield PulseInstruction(t0, self._dt, frame, frame_changes,
                                   is_opaque)
Example #2
0
    def get_waveforms(self) -> Iterator[PulseInstruction]:
        """Return waveform type instructions with frame."""
        sorted_frame_changes = sorted(self._frames.items(), key=lambda x: x[0], reverse=True)
        sorted_waveforms = sorted(self._waveforms.items(), key=lambda x: x[0])

        # bind phase and frequency with instruction
        phase = self._init_phase
        frequency = self._init_frequency
        for t0, inst in sorted_waveforms:
            is_opaque = False

            while len(sorted_frame_changes) > 0 and sorted_frame_changes[-1][0] <= t0:
                _, frame_changes = sorted_frame_changes.pop()
                phase, frequency = ChannelEvents._calculate_current_frame(
                    frame_changes=frame_changes,
                    phase=phase,
                    frequency=frequency)

            # Convert parameter expression into float
            if isinstance(phase, circuit.ParameterExpression):
                phase = float(phase.bind({param: 0 for param in phase.parameters}))
            if isinstance(frequency, circuit.ParameterExpression):
                frequency = float(frequency.bind({param: 0 for param in frequency.parameters}))

            frame = PhaseFreqTuple(phase, frequency)

            # Check if pulse has unbound parameters
            if isinstance(inst, pulse.Play) and isinstance(inst.pulse, pulse.ParametricPulse):
                params = inst.pulse.parameters
                if any(isinstance(pval, circuit.Parameter) for pval in params.values()):
                    is_opaque = True

            yield PulseInstruction(t0, self._dt, frame, inst, is_opaque)
Example #3
0
    def get_frame_changes(self) -> Iterator[PulseInstruction]:
        """Return frame change type instructions with total frame change amount."""
        sorted_frame_changes = sorted(self._frames.items(), key=lambda x: x[0])

        phase = self._init_phase
        frequency = self._init_frequency
        for t0, frame_changes in sorted_frame_changes:
            pre_phase = phase
            pre_frequency = frequency
            phase, frequency = ChannelEvents._calculate_current_frame(
                frame_changes=frame_changes, phase=phase, frequency=frequency)
            frame = PhaseFreqTuple(phase - pre_phase,
                                   frequency - pre_frequency)

            yield PulseInstruction(t0, self._dt, frame, frame_changes)
Example #4
0
    def get_waveforms(self) -> Iterator[PulseInstruction]:
        """Return waveform type instructions with frame."""
        sorted_frame_changes = sorted(self._frames.items(),
                                      key=lambda x: x[0],
                                      reverse=True)
        sorted_waveforms = sorted(self._waveforms.items(), key=lambda x: x[0])

        # bind phase and frequency with instruction
        phase = self._init_phase
        frequency = self._init_frequency
        for t0, inst in sorted_waveforms:
            while len(sorted_frame_changes
                      ) > 0 and sorted_frame_changes[-1][0] <= t0:
                _, frame_changes = sorted_frame_changes.pop()
                phase, frequency = ChannelEvents._calculate_current_frame(
                    frame_changes=frame_changes,
                    phase=phase,
                    frequency=frequency)
            frame = PhaseFreqTuple(phase, frequency)

            yield PulseInstruction(t0, self._dt, frame, inst)