def compile_sequence(seq, channels=None): ''' Takes a list of control flow and pulses, and returns aligned blocks separated into individual abstract channels (wires). ''' #Find the set of logical channels used here and initialize them if not channels: channels = find_unique_channels(seq) wires = {chan: [] for chan in channels} for block in normalize(flatten(seq), channels): # labels and control flow instructions broadcast to all channels if isinstance(block, (BlockLabel.BlockLabel, ControlFlow.ControlInstruction)): for chan in channels: wires[chan] += [copy(block)] continue # drop length 0 blocks but push frame change onto previous entry if block.length == 0: for chan in channels: if len(wires[chan]) > 0: wires[chan][-1] = copy(wires[chan][-1]) wires[chan][-1].frameChange += block.pulses[chan].frameChange else: warn("Dropping initial frame change") continue # schedule the block for chan in channels: # add aligned Pulses (if the block contains a composite pulse, may get back multiple pulses) wires[chan] += schedule(chan, block.pulses[chan], block.length, block.alignment) return wires
def collect_specializations(seqs): ''' Collects function definitions for all targets of Call instructions ''' targets = [x.target for x in flatten(seqs) if isinstance(x, ControlFlow.Call)] funcDefs = [] for target in targets: funcDefs += ControlFlow.qfunction_specialization(target) return funcDefs
def find_unique_channels(seq): channels = set([]) for step in flatten(seq): if not hasattr(step, 'channel'): continue if isinstance(step.channel, Channels.Channel): channels |= set([step.channel]) else: channels |= set(step.channel) return channels
def collect_specializations(seqs): ''' Collects function definitions for all targets of Call instructions ''' targets = [ x.target for x in flatten(seqs) if isinstance(x, ControlFlow.Call) ] funcDefs = [] for target in targets: funcDefs += ControlFlow.qfunction_specialization(target) return funcDefs
def generate_waveforms(physicalWires): wfs = {ch: {} for ch in physicalWires.keys()} for ch, wire in physicalWires.items(): for pulse in flatten(wire): if not isinstance(pulse, PulseSequencer.Pulse): continue if pulse.hashshape() not in wfs[ch]: if pulse.isTimeAmp: wfs[ch][pulse.hashshape()] = np.ones(1, dtype=np.complex) else: wfs[ch][pulse.hashshape()] = pulse.shape return wfs
def generate_waveforms(physicalWires): wfs = {ch : {} for ch in physicalWires.keys()} for ch, wire in physicalWires.items(): for pulse in flatten(wire): if not isinstance(pulse, PulseSequencer.Pulse): continue if pulse.hashshape() not in wfs[ch]: if pulse.isTimeAmp: wfs[ch][pulse.hashshape()] = np.ones(1, dtype=np.complex) else: wfs[ch][pulse.hashshape()] = pulse.shape return wfs
def compile_sequence(seq, channels=None): ''' Takes a list of control flow and pulses, and returns aligned blocks separated into individual abstract channels (wires). ''' #Find the set of logical channels used here and initialize them if not channels: channels = find_unique_channels(seq) wires = {chan: [] for chan in channels} for block in normalize(flatten(seq), channels): # labels and control flow instructions broadcast to all channels if isinstance(block, (BlockLabel.BlockLabel, ControlFlow.ControlInstruction)): for chan in channels: wires[chan] += [copy(block)] continue # drop length 0 blocks but push frame change onto previous entry if block.length == 0: for chan in channels: if len(wires[chan]) > 0: wires[chan][-1] = copy(wires[chan][-1]) wires[chan][-1].frameChange += block.pulses[ chan].frameChange else: warn("Dropping initial frame change") continue # schedule the block for chan in channels: # add aligned Pulses (if the block contains a composite pulse, may get back multiple pulses) wires[chan] += schedule(chan, block.pulses[chan], block.length, block.alignment) return wires