def get_waveforms( self) -> Iterator[Tuple[int, PhaseFreqTuple, pulse.Instruction]]: """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() for frame_change in frame_changes: if isinstance(frame_change, pulse.instructions.SetFrequency): frequency = frame_change.frequency elif isinstance(frame_change, pulse.instructions.ShiftFrequency): frequency += frame_change.frequency elif isinstance(frame_change, pulse.instructions.SetPhase): phase = frame_change.phase elif isinstance(frame_change, pulse.instructions.ShiftPhase): phase += frame_change.phase frame = PhaseFreqTuple(phase, frequency) yield t0, frame, inst
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)
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)
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)
def get_frame_changes(self) -> Iterator[Tuple[int, PhaseFreqTuple, List[pulse.Instruction]]]: """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, insts in sorted_frame_changes: pre_phase = phase pre_frequency = frequency for inst in insts: if isinstance(inst, pulse.instructions.SetFrequency): frequency = inst.frequency elif isinstance(inst, pulse.instructions.ShiftFrequency): frequency += inst.frequency elif isinstance(inst, pulse.instructions.SetPhase): phase = inst.phase elif isinstance(inst, pulse.instructions.ShiftPhase): phase += inst.phase frame = PhaseFreqTuple(phase - pre_phase, frequency - pre_frequency) yield t0, frame, insts
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)