<commit_before><commit_msg>Add test for APS2 instruction merging.<commit_after>import h5py
import unittest
import numpy as np
from copy import copy

from QGL import *
from instruments.drivers import APS2Pattern

class APSPatternUtils(unittest.TestCase):
    def setUp(self):
        self.q1gate = Channels.LogicalMarkerChannel(label='q1-gate')
        self.q1 = Qubit(label='q1', gateChan=self.q1gate)
        self.q1 = Qubit(label='q1')
        self.q1.pulseParams['length'] = 30e-9

        Compiler.channelLib = {'q1': self.q1, 'q1-gate': self.q1gate}

    def test_synchronize_control_flow(self):
        q1 = self.q1

        pulse = Compiler.Waveform()
        pulse.length = 24
        pulse.key = 12345
        delay = Compiler.Waveform()
        delay.length = 100
        delay.isTimeAmp = True
        blank = Compiler.Waveform( BLANK(q1, pulse.length) )

        seq_1 = [qwait(), delay, copy(pulse), qwait(), copy(pulse)]
        seq_2 = [qwait(), copy(blank), qwait(), copy(blank)]
        offsets = { APS2Pattern.wf_sig(pulse) : 0 }
        
        instructions = APS2Pattern.create_seq_instructions([seq_1, seq_2, [], [], []], offsets)

        instr_types = [
            APS2Pattern.SYNC,
            APS2Pattern.WAIT,
            APS2Pattern.WFM,
            APS2Pattern.MARKER,
            APS2Pattern.WFM,
            APS2Pattern.WAIT,
            APS2Pattern.WFM,
            APS2Pattern.MARKER
        ]

        for actual, expected in zip(instructions, instr_types):
            instrOpCode = (actual.header >> 4) & 0xf
            assert(instrOpCode == expected)

if __name__ == "__main__":    
    unittest.main()
{'fraction_non_alphanumeric': 0.1145642900670323, 'fraction_numerical': 0.029250457038391225, 'mean_word_length': 2.357873210633947, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5493370', 'n_tokens_mistral': 564, 'n_tokens_neox': 523, 'n_words': 105}