def test_trafo(self):
        channels = {'X': 2, 'Y': 4.4}
        trafo = ParallelConstantChannelTransformation(channels)

        n_points = 17
        time = np.arange(17, dtype=float)

        expected_overwrites = {
            'X': np.full((n_points, ), 2.),
            'Y': np.full((n_points, ), 4.4)
        }

        empty_input_result = trafo(time, {})
        np.testing.assert_equal(empty_input_result, expected_overwrites)

        z_input_result = trafo(time, {'Z': np.sin(time)})
        np.testing.assert_equal(z_input_result, {
            'Z': np.sin(time),
            **expected_overwrites
        })

        x_input_result = trafo(time, {'X': np.cos(time)})
        np.testing.assert_equal(empty_input_result, expected_overwrites)

        x_z_input_result = trafo(time, {'X': np.cos(time), 'Z': np.sin(time)})
        np.testing.assert_equal(z_input_result, {
            'Z': np.sin(time),
            **expected_overwrites
        })
Example #2
0
    def build_waveform(self, parameters: Dict[str, numbers.Real],
                       channel_mapping: Dict[ChannelID, Optional[ChannelID]]) -> Optional[Waveform]:
        inner_waveform = self._template.build_waveform(parameters, channel_mapping)

        if inner_waveform:
            overwritten_channels = self._get_overwritten_channels_values(parameters=parameters,
                                                                         channel_mapping=channel_mapping)
            transformation = ParallelConstantChannelTransformation(overwritten_channels)
            return TransformingWaveform(inner_waveform, transformation)
Example #3
0
    def _internal_create_program(
            self, *, scope: Scope,
            global_transformation: Optional[Transformation], **kwargs):
        overwritten_channels = self._get_overwritten_channels_values(
            parameters=scope)
        transformation = ParallelConstantChannelTransformation(
            overwritten_channels)

        if global_transformation is not None:
            transformation = chain_transformations(global_transformation,
                                                   transformation)

        self._template._create_program(scope=scope,
                                       global_transformation=transformation,
                                       **kwargs)
Example #4
0
    def _internal_create_program(
            self, *, parameters: Dict[str, Parameter],
            global_transformation: Optional[Transformation], **kwargs):
        real_parameters = {
            name: parameters[name].get_value()
            for name in self.transformation_parameters
        }
        overwritten_channels = self._get_overwritten_channels_values(
            parameters=real_parameters)
        transformation = ParallelConstantChannelTransformation(
            overwritten_channels)

        if global_transformation is not None:
            transformation = chain_transformations(global_transformation,
                                                   transformation)

        self._template._create_program(parameters=parameters,
                                       global_transformation=transformation,
                                       **kwargs)
    def test_init(self):
        channels = {'X': 2, 'Y': 4.4}

        trafo = ParallelConstantChannelTransformation(channels)

        self.assertEqual(trafo._channels, channels)
        self.assertTrue(
            all(isinstance(v, float) for v in trafo._channels.values()))

        self.assertEqual(trafo.compare_key, (('X', 2.), ('Y', 4.4)))

        self.assertEqual(trafo.get_input_channels(set()), set())
        self.assertEqual(trafo.get_input_channels({'X'}), set())
        self.assertEqual(trafo.get_input_channels({'Z'}), {'Z'})
        self.assertEqual(trafo.get_input_channels({'X', 'Z'}), {'Z'})

        self.assertEqual(trafo.get_output_channels(set()), {'X', 'Y'})
        self.assertEqual(trafo.get_output_channels({'X'}), {'X', 'Y'})
        self.assertEqual(trafo.get_output_channels({'X', 'Z'}),
                         {'X', 'Y', 'Z'})
 def test_constant_propagation(self):
     channels = {'X': 2, 'Y': 4.4}
     trafo = ParallelConstantChannelTransformation(channels)
     self.assertTrue(trafo.is_constant_invariant())
    def test_scalar_trafo_works(self):
        channels = {'X': 2, 'Y': 4.4}
        trafo = ParallelConstantChannelTransformation(channels)

        assert_scalar_trafo_works(self, trafo, {'a': 0., 'b': 0.3, 'c': 0.6})
 def test_repr(self):
     channels = {'X': 2, 'Y': 4.4}
     trafo = ParallelConstantChannelTransformation(channels)
     self.assertEqual(trafo, eval(repr(trafo)))