Skip to content

Commit

Permalink
add conditions to TDM; rename TdmLoadCmp instruction
Browse files Browse the repository at this point in the history
The "TdmLoadCmp" instruction is actually available to the AWG;
it really refers to the Vram.

There may still be instructions not handled correctly
by the TDM generator, but there are enough to show
the basic process
  • Loading branch information
Daniel Ellard committed Jan 30, 2018
1 parent 64d6857 commit f466945
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion QGL/Compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def compile_sequence(seq, channels=None):
if (isinstance(block, ControlFlow.ControlInstruction) or
isinstance(block, TdmInstructions.WriteAddrInstruction) or
isinstance(block, TdmInstructions.CustomInstruction) or
isinstance(block, TdmInstructions.LoadCmpTdmInstruction)):
isinstance(block, TdmInstructions.LoadCmpVramInstruction)):
# Need to deal with attaching measurements and edges to control
# instruction. Until we have a proper solution for that, we will
# always broadcast control instructions to all channels
Expand Down
2 changes: 1 addition & 1 deletion QGL/PatternUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def apply_gating_constraints(chan, linkList):
(ControlFlow.ControlInstruction, BlockLabel.BlockLabel,
TdmInstructions.CustomInstruction,
TdmInstructions.WriteAddrInstruction,
TdmInstructions.LoadCmpTdmInstruction)):
TdmInstructions.LoadCmpVramInstruction)):

if previousEntry:
gateSeq.append(previousEntry)
Expand Down
6 changes: 3 additions & 3 deletions QGL/TdmInstructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Invalidate(addr, mask, channel=None):
def StoreMeas(addr, value, channel=None):
return WriteAddrInstruction('STOREMEAS', channel, 5, addr, value)

class LoadCmpTdmInstruction(object):
class LoadCmpVramInstruction(object):

def __init__(self, name, use_vram, addr, mask):
# TODO: sanity checks on input values
Expand All @@ -98,8 +98,8 @@ def __ne__(self, other):
return not self == other


def LoadCmpTdm(addr, mask):
return LoadCmpTdmInstruction('LOADCMPTDM', 1, addr, mask)
def LoadCmpVram(addr, mask):
return LoadCmpVramInstruction('LOADCMPVRAM', 1, addr, mask)

# TODO: are there other variants of WriteAddr?

2 changes: 1 addition & 1 deletion QGL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from .Tomography import state_tomo, process_tomo
from .Scheduler import schedule

from .TdmInstructions import MajorityMask, MajorityVote, WriteAddr, Invalidate, LoadCmpTdm
from .TdmInstructions import MajorityMask, MajorityVote, WriteAddr, Invalidate, LoadCmpVram
21 changes: 13 additions & 8 deletions QGL/drivers/APS2TDMPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
GREATERTHAN = 0x2
LESSTHAN = 0x3

CMPTABLE = {'==': EQUAL, '!=': NOTEQUAL, '>': GREATERTHAN, '<': LESSTHAN}


# Whether we use PHASE_OFFSET modulation commands or bake it into waveform
# Default to false as we usually don't have many variants
USE_PHASE_OFFSET_INSTRUCTION = False
Expand Down Expand Up @@ -462,7 +465,7 @@ def MajorityVote(in_addr, out_addr, label=None):
def MajorityVoteMask(in_addr, out_addr, label=None):
return Custom(in_addr, out_addr, 1, label=label)

def LoadCmpTdm(addr, mask, label=None):
def LoadCmpVram(addr, mask, label=None):
header = LOADCMP << 4
payload = (1 << 48) | (mask << 16) | addr
return Instruction(header, payload, label=label)
Expand Down Expand Up @@ -721,8 +724,6 @@ def create_seq_instructions(seqs, offsets):
# keep track of where we are in each sequence
indexes = np.zeros(len(seqs), dtype=np.int64)

cmpTable = {'==': EQUAL, '!=': NOTEQUAL, '>': GREATERTHAN, '<': LESSTHAN}

# always start with SYNC (stealing label from beginning of sequence)
# unless it is a subroutine (using last entry as return as tell)
label = None
Expand Down Expand Up @@ -760,7 +761,7 @@ def create_seq_instructions(seqs, offsets):
isinstance(entry, BlockLabel.BlockLabel) or
isinstance(entry, TdmInstructions.CustomInstruction) or
isinstance(entry, TdmInstructions.WriteAddrInstruction) or
isinstance(entry, TdmInstructions.LoadCmpTdmInstruction)):
isinstance(entry, TdmInstructions.LoadCmpVramInstruction)):
if isinstance(entry, BlockLabel.BlockLabel):
# carry label forward to next entry
label = entry
Expand All @@ -786,7 +787,7 @@ def create_seq_instructions(seqs, offsets):
instructions.append(Load(entry.value - 1, label=label))
elif isinstance(entry, ControlFlow.ComparisonInstruction):
# TODO modify Cmp operator to load from specified address
instructions.append(Cmp(cmpTable[entry.operator],
instructions.append(Cmp(CMPTABLE[entry.operator],
entry.value,
label=label))

Expand Down Expand Up @@ -1318,10 +1319,10 @@ def tdm_instructions(seq):
elif isinstance(s, ControlFlow.LoadRepeat):
instructions.append(Load(s.value - 1, label=label))

elif isinstance(s, TdmInstructions.LoadCmpTdmInstruction):
if s.instruction == 'LOADCMPTDM':
elif isinstance(s, TdmInstructions.LoadCmpVramInstruction):
if s.instruction == 'LOADCMPVRAM':
instructions.append(
LoadCmpTdm(s.addr, s.mask, label=label))
LoadCmpVram(s.addr, s.mask, label=label))

elif isinstance(s, PulseSequencer.Pulse):
if s.label == 'MEAS' and s.maddr != (-1, 0):
Expand All @@ -1338,6 +1339,10 @@ def tdm_instructions(seq):
# If this happens, we are confused.
print('FIXME: TDM GOT LIST: %s' % str(s))

elif isinstance(s, ControlFlow.ComparisonInstruction):
instructions.append(
Cmp(CMPTABLE[s.operator], s.value, label=label))

else:
# This isn't necessarily an error, because the TDM ignores a
# lot of instructions, but until this is debugged it's handy
Expand Down
5 changes: 3 additions & 2 deletions QGL/n.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def setUp():
# MEASA(q1, maddr=(10, 2)),
MEASA(q2, maddr=(10, 2)),

LoadCmpTdm(10, 7),
LoadCmpVram(10, 7),

MajorityVote(10, 11),
qif(0, [X90(q1), Y(q1), X(q1)], [Y90(q2)]),
LoadCmpVram(11, 1),
qif(0, [MEASA(q1, maddr=(12, 0)), X(q1)], [Y90(q2)]),

]

Expand Down

0 comments on commit f466945

Please sign in to comment.