Skip to content

Commit

Permalink
WIP: align pulses instead of blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ristè committed Mar 26, 2018
1 parent a0b2956 commit 8db8fe1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion QGL/PulseSequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def TAPulse(label,
return Pulse(label, channel, params, amp, phase, frameChange, ignoredStrParams)



class CompositePulse(namedtuple("CompositePulse", ["label", "pulses"])):
'''
A sequential series of pulses that reside within one time bin of a pulse block
Expand Down Expand Up @@ -219,7 +220,7 @@ def __mul__(self, rhs):
else:
result.pulses[k] = v
result.length = max(self.length, rhs.length)
return result
return align('center', result)

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand Down Expand Up @@ -253,6 +254,32 @@ def align(pulseBlock, mode="center"):
pulseBlock.alignment = mode
return pulseBlock

def align_p(mode="center", *pulses): #move it to compiler?
# Align any number of Pulses
# TODO: First, make everything look like a sequence of pulses
def flatten_to_pulses(obj):
if isinstance(obj, Pulse):
yield obj
else:
for pulse in obj.pulses:
yield from flatten_to_pulses(pulse)

#if isinstance(pulses, PulseBlock):
#pulses = list(flatten_to_pulses(pulses))
pulse_lengths = np.array([pulse.length for pulse in pulses])
pad_lengths = max(pulse_lengths) - pulse_lengths
if max(pad_lengths) == 0:
# no padding element required
return pulses
elif mode == 'left':
return reduce(operator.mul,[p + TAPulse('Id', p.channel, round(max(pulse_lengths) - p.length,9),0) if p.length < max(pulse_lengths) else p for p in pulses])
elif mode == 'right':
return reduce(operator.mul,[TAPulse('Id', p.channel, round(max(pulse_lengths) - p.length,9),0) + p if p.length < max(pulse_lengths) else p for p in pulses])
elif mode == 'center':
return reduce(operator.mul,[TAPulse('Id', p.channel, round((max(pulse_lengths) - p.length)/2,9),0) + p + TAPulse('Id', p.channel, round((max(pulse_lengths) - p.length)/2,9),0) if p.length < max(pulse_lengths) else p for p in pulses])
else:
logger.error('Pulse alignment type must be one of left, right, or center.')

class CompoundGate(object):
'''
A wrapper around a python list to allow us to define '*' on lists.
Expand Down
2 changes: 1 addition & 1 deletion QGL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .ChannelLibraries import QubitFactory, MeasFactory, EdgeFactory, MarkerFactory, ChannelLibrary, channelLib
from .PulsePrimitives import *
from .Compiler import compile_to_hardware, set_log_level
from .PulseSequencer import align
from .PulseSequencer import align, align_p
from .ControlFlow import repeat, repeatall, qif, qwhile, qdowhile, qfunction, qwait, qsync, Barrier
from .BasicSequences import *
from .Plotting import output_file, output_notebook, show, build_waveforms, plot_waveforms
Expand Down

0 comments on commit 8db8fe1

Please sign in to comment.