def test_identity_result(self): self.assertIs(chain_transformations(), IdentityTransformation()) self.assertIs( chain_transformations(IdentityTransformation(), IdentityTransformation()), IdentityTransformation())
def test_internal_create_program(self): template = DummyPulseTemplate(duration='t1', defined_channels={'X', 'Y'}, parameter_names={'a', 'b'}, measurement_names={'M'}, waveform=DummyWaveform()) overwritten_channels = {'Y': 'c', 'Z': 'a'} parent_loop = object() measurement_mapping = object() channel_mapping = object() to_single_waveform = object() other_kwargs = dict(measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, to_single_waveform=to_single_waveform, parent_loop=parent_loop) pccpt = ParallelConstantChannelPulseTemplate(template, overwritten_channels) scope = DictScope.from_kwargs(c=1.2, a=3.4) kwargs = {**other_kwargs, 'scope': scope, 'global_transformation': None} expected_overwritten_channels = {'Y': 1.2, 'Z': 3.4} expected_transformation = ParallelConstantChannelTransformation(expected_overwritten_channels) expected_kwargs = {**kwargs, 'global_transformation': expected_transformation} with mock.patch.object(template, '_create_program', spec=template._create_program) as cp_mock: pccpt._internal_create_program(**kwargs) cp_mock.assert_called_once_with(**expected_kwargs) global_transformation = LinearTransformation(numpy.zeros((0, 0)), [], []) expected_transformation = chain_transformations(global_transformation, expected_transformation) kwargs = {**other_kwargs, 'scope': scope, 'global_transformation': global_transformation} expected_kwargs = {**kwargs, 'global_transformation': expected_transformation} with mock.patch.object(template, '_create_program', spec=template._create_program) as cp_mock: pccpt._internal_create_program(**kwargs) cp_mock.assert_called_once_with(**expected_kwargs)
def test_chaining(self): trafo = TransformationStub() expected = ChainedTransformation(trafo, trafo) result = chain_transformations(trafo, IdentityTransformation(), trafo) self.assertEqual(result, expected)
def test_denesting(self): trafo = TransformationStub() chained = ChainedTransformation(TransformationStub(), TransformationStub()) expected = ChainedTransformation(trafo, *chained.transformations, trafo) result = chain_transformations(trafo, chained, trafo) self.assertEqual(expected, result)
def test_internal_create_program(self): template = DummyPulseTemplate(duration='t1', defined_channels={'X', 'Y'}, parameter_names={'a', 'b'}, measurement_names={'M'}, waveform=DummyWaveform()) overwritten_channels = {'Y': 'c', 'Z': 'a'} parent_loop = object() measurement_mapping = object() channel_mapping = object() to_single_waveform = object() other_kwargs = dict(measurement_mapping=measurement_mapping, channel_mapping=channel_mapping, to_single_waveform=to_single_waveform, parent_loop=parent_loop) pccpt = ParallelConstantChannelPulseTemplate(template, overwritten_channels) parameters = {'c': ConstantParameter(1.2), 'a': ConstantParameter(3.4)} kwargs = { **other_kwargs, 'parameters': parameters.copy(), 'global_transformation': None } expected_overwritten_channels = {'Y': 1.2, 'Z': 3.4} expected_transformation = ParallelConstantChannelTransformation( expected_overwritten_channels) expected_kwargs = { **kwargs, 'global_transformation': expected_transformation } template._create_program = mock.Mock() pccpt._internal_create_program(**kwargs) template._create_program.assert_called_once_with(**expected_kwargs) global_transformation = LinearTransformation(numpy.zeros((0, 0)), [], []) expected_transformation = chain_transformations( global_transformation, expected_transformation) kwargs = { **other_kwargs, 'parameters': parameters.copy(), 'global_transformation': global_transformation } expected_kwargs = { **kwargs, 'global_transformation': expected_transformation } template._create_program = mock.Mock() pccpt._internal_create_program(**kwargs) template._create_program.assert_called_once_with(**expected_kwargs)
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)
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_single_transformation(self): trafo = TransformationStub() self.assertIs(chain_transformations(trafo), trafo) self.assertIs(chain_transformations(trafo, IdentityTransformation()), trafo)