From 33971e6e7d60bdf256a4ee70871e2ba19b3ed03e Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Thu, 17 Nov 2016 12:16:10 -0500 Subject: [PATCH] Write per-receiver measurement count info to meta file. --- QGL/Compiler.py | 28 ++++++++++++++++++++++++---- tests/test_Compiler.py | 8 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/QGL/Compiler.py b/QGL/Compiler.py index 63f3b543..13b0436d 100644 --- a/QGL/Compiler.py +++ b/QGL/Compiler.py @@ -381,6 +381,7 @@ def compile_to_hardware(seqs, # save number of measurements for meta info num_measurements = count_measurements(wireSeqs) + wire_measurements = count_measurements_per_wire(wireSeqs) # map logical to physical channels physWires = map_logical_to_physical(wireSeqs) @@ -434,11 +435,14 @@ def compile_to_hardware(seqs, 'points': list(range(1, 1 + num_measurements)), 'partition': 1 }] + receiver_measurements = {wire.receiverChan.label: n + for wire, n in wire_measurements.items()} meta = { 'instruments': files, 'num_sequences': len(seqs), 'num_measurements': num_measurements, 'axis_descriptor': axis_descriptor, + 'receivers': receiver_measurements } metafilepath = os.path.join(config.AWGDir, fileName + '-meta.json') with open(metafilepath, 'w') as FID: @@ -849,8 +853,24 @@ def count_measurements(wireSeqs): seq_len = len(wireSeqs[list(wireSeqs)[0]]) seq_measurements = [0 for _ in range(seq_len)] for ct in range(seq_len): - for wire, seqs in wireSeqs.items(): - seq_measurements[ct] = max( - seq_measurements[ct], - sum(PatternUtils.contains_measurement(e) for e in seqs[ct])) + seq_measurements[ct] = \ + reduce(max, count_measurements_per_wire_idx(wireSeqs, ct).values()) return sum(seq_measurements) + +def count_measurements_per_wire(wireSeqs): + # pick an arbitrary key to determine sequence length + seq_len = len(wireSeqs[list(wireSeqs)[0]]) + meas_wires = list(filter(lambda x: isinstance(x, Channels.Measurement), wireSeqs)) + measurements = {wire: 0 for wire in meas_wires} + for ct in range(seq_len): + seq_measurements = count_measurements_per_wire_idx(wireSeqs, ct) + for wire in meas_wires: + measurements[wire] += seq_measurements[wire] + return measurements + +def count_measurements_per_wire_idx(wireSeqs, idx): + measurements = { + wire: sum(PatternUtils.contains_measurement(e) for e in seqs[idx]) + for wire, seqs in wireSeqs.items() + } + return measurements diff --git a/tests/test_Compiler.py b/tests/test_Compiler.py index 44bdcd1c..fd5ce9d2 100644 --- a/tests/test_Compiler.py +++ b/tests/test_Compiler.py @@ -123,6 +123,8 @@ def test_merge_channels(self): def test_num_measurements(self): q1 = self.q1 q2 = self.q2 + mq1 = MEAS(q1).channel + mq2 = MEAS(q2).channel seqs = [[X(q1)*X(q2)]] wireSeqs = Compiler.compile_sequences(seqs) assert Compiler.count_measurements(wireSeqs) == 0 @@ -142,6 +144,9 @@ def test_num_measurements(self): seqs = [[MEAS(q1)*MEAS(q2), MEAS(q2)]] wireSeqs = Compiler.compile_sequences(seqs) assert Compiler.count_measurements(wireSeqs) == 2 + wire_meas = Compiler.count_measurements_per_wire(wireSeqs) + assert wire_meas[mq1] == 1 + assert wire_meas[mq2] == 2 seqs = [[MEAS(q1)*MEAS(q2), MEAS(q2)], [MEAS(q1)], @@ -150,6 +155,9 @@ def test_num_measurements(self): [X(q1)]] wireSeqs = Compiler.compile_sequences(seqs) assert Compiler.count_measurements(wireSeqs) == 5 + wire_meas = Compiler.count_measurements_per_wire(wireSeqs) + assert wire_meas[mq1] == 3 + assert wire_meas[mq2] == 4 if __name__ == "__main__": unittest.main()