Exemplo n.º 1
0
def init(calibration_path: str, mock: bool, mock_noise_std: Real,
         mock_gain: Real):
    """
    Initialize hxtorch connection and load calibration.

    Caveat: This also measures and sets the gain, therefore do this before
    initializing the model (as this influences layer initialization).

    :param calibration_path: Path of custom calibration
    :param mock: Whether to simulate the hardware
    :param mock_noise_std: Standard deviation of artificial noise in mock mode
    :param mock_gain: Multiplication gain used in mock mode
    """
    if mock:
        mock_parameter = hxtorch.MockParameter(noise_std=mock_noise_std,
                                               gain=mock_gain)
        log.info(f"Initialize mock mode with {mock_parameter}")
    else:
        log.info("Initialize with BrainScaleS-2 ASIC")
        if calibration_path:
            log.info(f"Apply calibration from: '{calibration_path}'")
            hxtorch.init_hardware(hxtorch.CalibrationPath(calibration_path))
        else:
            log.info("Apply latest nightly calibration")
            hxtorch.init_hardware()  # defaults to a nightly default calib
        mock_parameter = hxtorch.measure_mock_parameter()

    # set mock parameter used in mock mode and backward pass
    hxtorch.set_mock_parameter(mock_parameter)
Exemplo n.º 2
0
    def test_getter_setter(self):
        mock_parameter = hxtorch.MockParameter(gain=2000)
        with self.assertRaises(OverflowError):
            hxtorch.set_mock_parameter(mock_parameter)

        mock_parameter = hxtorch.MockParameter(gain=0.0043)
        hxtorch.set_mock_parameter(mock_parameter)
        self.assertEqual(hxtorch.get_mock_parameter(), mock_parameter)
Exemplo n.º 3
0
 def setUpClass(cls):
     hxtorch.set_mock_parameter(
         hxtorch.MockParameter(noise_std=cls.noise_std, gain=cls.gain))
Exemplo n.º 4
0
 def setUpClass(cls):
     hxtorch.init_hardware()
     mock_parameter = hxtorch.measure_mock_parameter()
     hxtorch.set_mock_parameter(mock_parameter)
     cls.noise_std = mock_parameter.noise_std
     cls.gain = mock_parameter.gain
Exemplo n.º 5
0
 def setUpClass(cls) -> None:
     hxtorch.set_mock_parameter(
         hxtorch.MockParameter(noise_std=0, gain=0.0018))
Exemplo n.º 6
0
 def setUpClass(cls):
     mock_parameter = hxtorch.MockParameter()
     hxtorch.set_mock_parameter(mock_parameter)
     cls.gain = mock_parameter.gain
Exemplo n.º 7
0
 def setUpClass(cls):
     mock_parameter = hxtorch.MockParameter(gain=0.0015, noise_std=0)
     hxtorch.set_mock_parameter(mock_parameter)
     cls.gain = mock_parameter.gain * 4