Beispiel #1
0
    def user_register(self, reg: UserRegister, value: int = None) -> int:
        """Query user registers (1-16) and optionally set it.

        Args:
            reg: User register. If it is an int, a warning is raised and it is interpreted as a one based index
            value: Value to set

        Returns:
            User Register value after setting it
        """
        if isinstance(reg, int):
            warnings.warn(
                "User register is not a UserRegister instance. It is interpreted as one based index."
            )
            reg = UserRegister(one_based_value=reg)

        if reg.to_web_interface() not in range(1, 17):
            raise HDAWGValueError(
                '{reg:repr} not a valid (1-16) register.'.format(reg=reg))

        node_path = '/{}/awgs/{:d}/userregs/{:labone}'.format(
            self.device.serial, self.awg_group_index, reg)
        if value is not None:
            self.device.api_session.setInt(node_path, value)
            self.device.api_session.sync(
            )  # Global sync: Ensure settings have taken effect on the device.
        return self.device.api_session.getInt(node_path)
Beispiel #2
0
    def test_formatting(self):
        reg = UserRegister.from_seqc(3)

        with self.assertRaises(ValueError):
            '{}'.format(reg)

        self.assertEqual('3', '{:seqc}'.format(reg))
        self.assertEqual('4', '{:web}'.format(reg))
        self.assertEqual('UserRegister(zero_based_value=3)', repr(reg))
        self.assertEqual(repr(reg), '{:r}'.format(reg))
Beispiel #3
0
    def test_full_run(self):
        defined_channels = frozenset(['A', 'B', 'C'])

        unique_n = 1000
        unique_duration = 32

        unique_wfs = get_unique_wfs(n=unique_n,
                                    duration=unique_duration,
                                    defined_channels=defined_channels)
        same_wf = DummyWaveform(duration=48,
                                sample_output=np.ones(48),
                                defined_channels=defined_channels)

        channels = ('A', 'B')
        markers = ('C', None, 'A', None)
        amplitudes = (1., 1.)
        offsets = (0., 0.)
        volatage_transformations = (lambda x: x, lambda x: x)
        sample_rate = 1

        root = complex_program_as_loop(unique_wfs, wf_same=same_wf)
        seqc_nodes = complex_program_as_seqc(unique_wfs, wf_same=same_wf)

        manager = HDAWGProgramManager()

        manager.add_program('test', root, channels, markers, amplitudes,
                            offsets, volatage_transformations, sample_rate)

        self.assertEqual({UserRegister(zero_based_value=2): 7},
                         manager.get_register_values('test'))
        seqc_program = manager.to_seqc_program()
        expected_program = """const PROG_SEL_REGISTER = 0;
const TRIGGER_REGISTER = 1;
const TRIGGER_RESET_MASK = 0b1000000000000000;
const PROG_SEL_NONE = 0;
const NO_RESET_MASK = 0b1000000000000000;
const PROG_SEL_MASK = 0b111111111111111;
const IDLE_WAIT_CYCLES = 300;
wave test_concatenated_waveform = "3e0090e8ffd002d1134ce38827c6a35fede89cf23d126a44057ef43f466ae4cd";
wave test_shared_waveform_121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518 = "121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518";

//function used by manually triggered programs
void waitForSoftwareTrigger() {
  while (true) {
    var trigger_register = getUserReg(TRIGGER_REGISTER);
    if (trigger_register & TRIGGER_RESET_MASK) setUserReg(TRIGGER_REGISTER, 0);
    if (trigger_register) return;
  }
}


// program definitions
void test_function() {
  var pos = 0;
  var user_reg_2 = getUserReg(2);
  waitForSoftwareTrigger();
  var init_pos_1 = pos;
  repeat(12) {
    pos = init_pos_1;
    repeat(1000) { // stepping repeat
      repeat(10) {
        repeat(42) {
          playWaveIndexed(test_concatenated_waveform, pos, 32); // advance disabled do to parent repetition
        }
        repeat(98) {
          playWave(test_shared_waveform_121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518);
        }
      }
      pos = pos + 32;
    }
    repeat(21) {
      playWaveIndexed(test_concatenated_waveform, pos, 32); // advance disabled do to parent repetition
    }
    pos = pos + 32;
    repeat(23) {
      playWaveIndexed(test_concatenated_waveform, pos, 48); // advance disabled do to parent repetition
    }
    pos = pos + 48;
    var idx_2;
    for(idx_2 = 0; idx_2 < user_reg_2; idx_2 = idx_2 + 1) {
      playWaveIndexed(test_concatenated_waveform, pos, 48); // advance disabled do to parent repetition
    }
    pos = pos + 48;
  }
}

// INIT program switch.
var prog_sel = 0;

//runtime block
while (true) {
  // read program selection value
  prog_sel = getUserReg(PROG_SEL_REGISTER);
  if (!(prog_sel & NO_RESET_MASK))  setUserReg(PROG_SEL_REGISTER, 0);
  prog_sel = prog_sel & PROG_SEL_MASK;
  
  switch (prog_sel) {
    case 1:
      test_function();
      waitWave();
    default:
      wait(IDLE_WAIT_CYCLES);
  }
}"""
        self.assertEqual(expected_program, seqc_program)
Beispiel #4
0
    def test_conversions(self):
        reg = UserRegister(zero_based_value=3)
        self.assertEqual(3, reg.to_seqc())
        self.assertEqual(3, reg.to_labone())
        self.assertEqual(4, reg.to_web_interface())

        reg = UserRegister(one_based_value=4)
        self.assertEqual(3, reg.to_seqc())
        self.assertEqual(3, reg.to_labone())
        self.assertEqual(4, reg.to_web_interface())

        self.assertEqual(reg, UserRegister.from_seqc(3))
        self.assertEqual(reg, UserRegister.from_labone(3))
        self.assertEqual(reg, UserRegister.from_web_interface(4))
Beispiel #5
0
    def test_full_run(self):
        defined_channels = frozenset(['A', 'B', 'C'])

        unique_n = 1000
        unique_duration = 32

        unique_wfs = get_unique_wfs(n=unique_n,
                                    duration=unique_duration,
                                    defined_channels=defined_channels)
        same_wf = DummyWaveform(duration=48,
                                sample_output=np.ones(48),
                                defined_channels=defined_channels)

        channels = ('A', 'B')
        markers = ('C', None, 'A', None)
        amplitudes = (1., 1.)
        offsets = (0., 0.)
        volatage_transformations = (lambda x: x, lambda x: x)
        sample_rate = 1

        root = complex_program_as_loop(unique_wfs, wf_same=same_wf)
        seqc_nodes = complex_program_as_seqc(unique_wfs, wf_same=same_wf)

        manager = HDAWGProgramManager()

        manager.add_program('test', root, channels, markers, amplitudes,
                            offsets, volatage_transformations, sample_rate)

        # 0: Program selection
        # 1: Trigger
        self.assertEqual({UserRegister(zero_based_value=2): 7},
                         manager.get_register_values('test'))
        seqc_program = manager.to_seqc_program()
        expected_program = """const PROG_SEL_REGISTER = 0;
const TRIGGER_REGISTER = 1;
const TRIGGER_RESET_MASK = 0b10000000000000000000000000000000;
const PROG_SEL_NONE = 0;
const NO_RESET_MASK = 0b10000000000000000000000000000000;
const PLAYBACK_FINISHED_MASK = 0b1000000000000000000000000000000;
const PROG_SEL_MASK = 0b111111111111111111111111111111;
const INVERTED_PROG_SEL_MASK = 0b11000000000000000000000000000000;
const IDLE_WAIT_CYCLES = 300;
wave test_concatenated_waveform_0 = "c45d955d9dc472d46bf74f7eb9ae2ed4d159adea7d6fe9ce3f48c95423535333";
wave test_shared_waveform_121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518 = "121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518";

// function used by manually triggered programs
void waitForSoftwareTrigger() {
  while (true) {
    var trigger_register = getUserReg(TRIGGER_REGISTER);
    if (trigger_register & TRIGGER_RESET_MASK) setUserReg(TRIGGER_REGISTER, 0);
    if (trigger_register) return;
  }
}


// program definitions
void test_function() {
  var pos = 0;
  var user_reg_2 = getUserReg(2);
  waitForSoftwareTrigger();
  var init_pos_1 = pos;
  repeat(12) {
    pos = init_pos_1;
    repeat(1000) { // stepping repeat
      repeat(10) {
        repeat(42) {
          playWaveIndexed(test_concatenated_waveform_0, pos, 32); // advance disabled do to parent repetition
        }
        repeat(98) {
          playWave(test_shared_waveform_121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518);
        }
      }
      pos = pos + 32;
    }
    repeat(21) {
      playWaveIndexed(test_concatenated_waveform_0, pos, 32); // advance disabled do to parent repetition
    }
    pos = pos + 32;
    repeat(23) {
      playWaveIndexed(test_concatenated_waveform_0, pos, 48); // advance disabled do to parent repetition
    }
    pos = pos + 48;
    var idx_2;
    for(idx_2 = 0; idx_2 < user_reg_2; idx_2 = idx_2 + 1) {
      playWaveIndexed(test_concatenated_waveform_0, pos, 48); // advance disabled do to parent repetition
    }
    pos = pos + 48;
  }
}

// Declare and initialize global variables
// Selected program index (0 -> None)
var prog_sel = 0;

// Value that gets written back to program selection register.
// Used to signal that at least one program was played completely.
var new_prog_sel = 0;

// Is OR'ed to new_prog_sel.
// Set to PLAYBACK_FINISHED_MASK if a program was played completely.
var playback_finished = 0;


// runtime block
while (true) {
  // read program selection value
  prog_sel = getUserReg(PROG_SEL_REGISTER);
  
  // calculate value to write back to PROG_SEL_REGISTER
  new_prog_sel = prog_sel | playback_finished;
  if (!(prog_sel & NO_RESET_MASK)) new_prog_sel &= INVERTED_PROG_SEL_MASK;
  setUserReg(PROG_SEL_REGISTER, new_prog_sel);
  
  // reset playback flag
  playback_finished = 0;
  
  // only use part of prog sel that does not mean other things to select the program.
  prog_sel &= PROG_SEL_MASK;
  
  switch (prog_sel) {
    case 1:
      test_function();
      waitWave();
      playback_finished = PLAYBACK_FINISHED_MASK;
    default:
      wait(IDLE_WAIT_CYCLES);
  }
}"""
        self.assertEqual(expected_program, seqc_program)