Пример #1
0
    def from_yaml(cls: Type[MultipathFading5GTDL], constructor: SafeConstructor, node: MappingNode) -> \
            MultipathFading5GTDL:
        """Recall a new `MultipathFading5GTDL` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `MultipathFading5GTDL` serialization.

        Returns:
            Channel:
                Newly created `MultipathFading5GTDL` instance.
                The internal references to modems will be `None` and need to be
                initialized by the `scenario` YAML constructor.
        """

        # Handle empty yaml nodes
        if isinstance(node, ScalarNode):
            raise RuntimeError(
                "5G TDL channel configurations require at least a model specification"
            )

        state = constructor.construct_mapping(node)

        model_type = state.pop('type', None)
        if model_type is None:
            raise RuntimeError(
                "5G TDL channel configurations require at least a model specification"
            )

        state['model_type'] = cls.TYPE[model_type]
        return cls(**state)
Пример #2
0
    def __construct_sequence(constructor: SafeConstructor,
                             node: SequenceNode) -> Sequence[Any]:
        """A custom sequence generator.

        Hacks ruamel to accept node names as tags.

        Args:
            constructor (SafeConstructor): Handle to the constructor.
            node (SequenceNode): A YAML sequence node.

        Returns:
            Sequence[Any]: A sequence of objects created from `node`.
        """

        sequence = []
        for node in node.value:

            if node.tag in constructor.yaml_constructors:
                sequence.append(constructor.yaml_constructors[node.tag](
                    constructor, node))

            else:
                sequence.append(
                    constructor.construct_non_recursive_object(node))

        return sequence
Пример #3
0
    def from_yaml(cls: Type[Modem], constructor: SafeConstructor, node: MappingNode) -> Modem:
        """Recall a new `Modem` class instance from YAML.

        Args:

            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (MappingNode):
                YAML node representing the `Modem` serialization.

        Returns:

            Modem:
                Newly created serializable instance.
        """

        state = constructor.construct_mapping(node, deep=True)

        encoding: List[Encoder] = state.pop('Encoding', [])
        precoding: List[SymbolPrecoder] = state.pop('Precoding', [])
        waveform: Optional[WaveformGenerator] = state.pop('Waveform', None)

        modem = cls.InitializationWrapper(state)

        for encoder in encoding:
            modem.encoder_manager.add_encoder(encoder)

        for precoder_idx, precoder in enumerate(precoding):
            modem.precoding[precoder_idx] = precoder

        if waveform is not None:
            modem.waveform_generator = waveform

        return modem
Пример #4
0
    def from_yaml(cls: Type[Simulation],
                  constructor: SafeConstructor,
                  node: MappingNode) -> Simulation:
        """Recall a new `Simulation` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `Simulation` serialization.

        Returns:
            Simulation:
                Newly created `Simulation` instance.
        """

        state = constructor.construct_mapping(node, deep=True)

        # Launch a global quadriga instance
        quadriga_interface: Optional[QuadrigaInterface] = state.pop(QuadrigaInterface.yaml_tag, None)
        if quadriga_interface is not None:
            QuadrigaInterface.SetGlobalInstance(quadriga_interface)

        # Pop configuration sections for "special" treatment
        devices: List[SimulatedDevice] = state.pop('Devices', [])
        channels: List[Tuple[Channel, int]] = state.pop('Channels', [])
        operators: List[Operator] = state.pop('Operators', [])
        evaluators: List[Evaluator] = state.pop('Evaluators', [])
        dimensions: Dict[str, Any] = state.pop('Dimensions', {})

        # Initialize simulation
        simulation = cls.InitializationWrapper(state)

        # Add devices to the simulation
        for device in devices:
            simulation.scenario.add_device(device)

        # Assign channel models
        for channel, channel_position in channels:

            output_device_idx = channel_position[0]
            input_device_idx = channel_position[1]

            simulation.scenario.set_channel(output_device_idx, input_device_idx, channel)

        # Register operators
        for operator in operators:
            simulation.__operators.append(operator)

        # Register evaluators
        for evaluator in evaluators:
            simulation.add_evaluator(evaluator)

        # Add simulation dimensions
        for dimension_key, dimension_values in dimensions.items():
            simulation.new_dimension(dimension_key, dimension_values)

        # Return simulation instance recovered from the serialization
        return simulation
    def from_yaml(cls: Type[SymbolPrecoding], constructor: SafeConstructor,
                  node: Node) -> SymbolPrecoding:
        """Recall a new `SymbolPrecoding` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `SymbolPrecoding` serialization.

        Returns:
            SymbolPrecoding:
                Newly created `SymbolPrecoding` instance.
        """

        state = constructor.construct_sequence(node, deep=True)
        symbol_precoding = cls()

        symbol_precoding.__symbol_precoders = state

        for precoder in symbol_precoding.__symbol_precoders:
            precoder.precoding = symbol_precoding

        return symbol_precoding
Пример #6
0
    def from_yaml(
            cls: Type[AutomaticGainControl], constructor: SafeConstructor,
            node: Union[ScalarNode, MappingNode]) -> AutomaticGainControl:
        """Recall a new `AnalogDigitalConverter` instance from YAML.

        Args:
            constructor (RoundTripConstructor):
                A handle to the constructor extracting the YAML information.

            node (Union[ScalarNode, MappingNode]):
                YAML node representing the `AnalogDigitalConverter` serialization.

        Returns:
            AnalogDigitalConverter:
                Newly created `AnalogDigitalConverter` instance.
            """

        if isinstance(node, ScalarNode):
            return cls()

        state = SafeConstructor.construct_mapping(constructor,
                                                  node,
                                                  deep=False)

        return cls.InitializationWrapper(state)
Пример #7
0
 def from_yaml(cls, constructor, node):  # pylint:disable=unused-argument
     """
     A way to load the notetaker from a yaml object
     """
     new_obj = cls()
     new_obj.notes = dict()
     yield new_obj
     new_dict = SafeConstructor.construct_mapping(constructor,
                                                  node,
                                                  deep=True)
     new_obj.notes.update(new_dict)
     new_obj.current_id = max(new_dict.keys()) + 1
     for note_id, note in new_dict.items():
         for lab in note.labels:
             new_obj.label_id_map.setdefault(lab, []).append(note_id)
    def from_yaml(cls: Type[WaveformGenerator], constructor: SafeConstructor,
                  node: Node) -> WaveformGenerator:
        """Recall a new `WaveformGenerator` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `WaveformGenerator` serialization.

        Returns:
            WaveformGenerator:
                Newly created `WaveformGenerator` instance.
        """

        return cls.InitializationWrapper(constructor.construct_mapping(node))
    def from_yaml(cls: Type[WaveformGeneratorChirpFsk], constructor: SafeConstructor, node: Node)\
            -> WaveformGeneratorChirpFsk:
        """Recall a new `WaveformGeneratorChirpFsk` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `WaveformGeneratorChirpFsk` serialization.

        Returns:
            WaveformGenerator:
                Newly created `WaveformGeneratorChirpFsk` instance.
        """

        state = constructor.construct_mapping(node)
        return cls(**state)
Пример #10
0
    def from_yaml(cls: Type[ShapingFilter], constructor: SafeConstructor,
                  node: MappingNode) -> ShapingFilter:
        """Recall a new `ShapingFilter` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `ShapingFilter` serialization.

        Returns:
            ShapingFilter:
                Newly created `ShapingFilter` instance.
        """

        state = constructor.construct_mapping(node)
        return cls(**state)
Пример #11
0
    def from_yaml(cls: Type[QuadrigaInterface], constructor: SafeConstructor,
                  node: MappingNode) -> QuadrigaInterface:
        """Recall a new `QuadrigaInterface` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `QuadrigaInterface` serialization.

        Returns:
            QuadrigaInterface:
                Newly created `QuadrigaInterface` instance. The internal references to modems will be `None` and need to be
                initialized by the `scenario` YAML constructor.

        """

        state = constructor.construct_mapping(node)
        return cls(**state)
Пример #12
0
    def from_yaml(cls: Type[MatchedFilterJcas], constructor: SafeConstructor,
                  node: MappingNode) -> MatchedFilterJcas:
        """Recall a new `MatchedFilterJcas` class instance from YAML.

        Args:

            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (MappingNode):
                YAML node representing the `MatchedFilterJcas` serialization.

        Returns:

            MatchedFilterJcas:
                Newly created serializable instance.
        """

        state = constructor.construct_mapping(node)
        return cls.InitializationWrapper(state)
    def from_yaml(cls: Type[Synchronization], constructor: SafeConstructor,
                  node: Node) -> Synchronization:
        """Recall a new `Synchronization` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `Synchronization` serialization.

        Returns:
            Synchronization:
                Newly created `Synchronization` instance.
        """

        # For scalar nodes, initialize the synchronization routine with default parameters
        if isinstance(node, ScalarNode):
            return cls()

        return cls.InitializationWrapper(constructor.construct_mapping(node))
Пример #14
0
    def from_yaml(cls: Type[SimulatedDevice], constructor: SafeConstructor, node: MappingNode) -> SimulatedDevice:
        """Recall a new `SimulatedDevice` class instance from YAML.

        Args:

            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (MappingNode):
                YAML node representing the `SimulatedDevice` serialization.

        Returns:

            SimulatedDevice:
                Newly created serializable instance.
        """

        if isinstance(node, ScalarNode):
            return cls()

        state = constructor.construct_mapping(node)
        return cls.InitializationWrapper(state)
Пример #15
0
    def from_yaml(cls: Type[BlockInterleaver], constructor: SafeConstructor,
                  node: MappingNode) -> BlockInterleaver:
        """Recall a new `Interleaver` encoder from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `Interleaver` serialization.

        Returns:
            BlockInterleaver:
                Newly created `Interleaver` instance.

        Note that the created instance is floating by default.

        :meta private:
        """

        state = constructor.construct_mapping(node)
        return cls(**state)
Пример #16
0
    def __construct_map(constructor: SafeConstructor,
                        node: MappingNode) -> Mapping[MappingNode, Any]:
        """A custom map generator.

        Hacks ruamel to accept node names as tags.

        Args:
            constructor (SafeConstructor): Handle to the constructor.
            node (MappingNode): A YAML map node.

        Returns:
            Mapping[MappingNode, Any]: A sequence of objects created from `node`.
        """

        tag = node.value[0][0].value

        if tag in constructor.yaml_constructors:
            return constructor.yaml_constructors[tag](constructor,
                                                      node.value[0][1])

        else:
            return constructor.construct_mapping(node, deep=True)
Пример #17
0
    def from_yaml(cls: Type[CyclicRedundancyCheck],
                  constructor: SafeConstructor,
                  node: MappingNode) -> CyclicRedundancyCheck:
        """Recall a new `CyclicRedundancyCheck` from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `CyclicRedundancyCheck` serialization.

        Returns:
            CyclicRedundancyCheck:
                Newly created `CyclicRedundancyCheck` instance.

        Note that the created instance is floating by default.

        :meta private:
        """

        state = constructor.construct_mapping(node)
        return cls(**state)
Пример #18
0
    def from_yaml(cls: Type[RandomNode], constructor: SafeConstructor,
                  node: Union[ScalarNode, MappingNode]) -> RandomNode:
        """Recall a new `RandomNode` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `RandomNode` serialization.

        Returns:
            RandomNode:
                Newly created `RandomNode` instance.
        """

        if isinstance(node, ScalarNode):
            return cls()

        state = constructor.construct_mapping(node)

        # Just mask the seed state if provided
        state['random_generator'] = state.pop('seed', None)
Пример #19
0
    def from_yaml(cls: Type[Serializable], constructor: SafeConstructor,
                  node: Node) -> Serializable:
        """Recall a new serializable class instance from YAML.

        Args:

            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `Channel` serialization.

        Returns:

            Serializable:
                The de-serialized object.
        """

        # Handle empty yaml nodes
        if isinstance(node, ScalarNode):
            return cls()

        return cls.InitializationWrapper(constructor.construct_mapping(node))
Пример #20
0
    def from_yaml(cls: Type[MultipathFadingExponential], constructor: SafeConstructor, node: MappingNode) -> \
            MultipathFadingExponential:
        """Recall a new `MultipathFadingExponential` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `MultipathFadingExponential` serialization.

        Returns:
            Channel:
                Newly created `MultipathFadingExponential` instance.
                The internal references to modems will be `None` and need to be
                initialized by the `scenario` YAML constructor.
        """

        # Handle empty yaml nodes
        if isinstance(node, ScalarNode):
            return cls()

        state = constructor.construct_mapping(node)
        return cls(**state)
    def from_yaml(cls: Type[WaveformGeneratorPskQam],
                  constructor: SafeConstructor,
                  node: MappingNode) -> WaveformGeneratorPskQam:
        """Recall a new `WaveformGeneratorPskQam` instance from YAML.

        Args:
            constructor (SafeConstructor):
                A handle to the constructor extracting the YAML information.

            node (Node):
                YAML node representing the `WaveformGeneratorPskQam` serialization.

        Returns:
            WaveformGeneratorPskQam:
                Newly created `WaveformGeneratorPskQam` instance.
        """
        state = constructor.construct_mapping(node)
        shaping_filter = state.pop('filter', None)

        generator = cls.InitializationWrapper(state)

        if shaping_filter is not None:

            # TODO: Patch-through for sampling rate
            samples_per_symbol = generator.oversampling_factor  # int(1e3 / generator.symbol_rate)
            shaping_filter = ShapingFilter(
                **shaping_filter, samples_per_symbol=samples_per_symbol)

            if shaping_filter.filter_type == ShapingFilter.FilterType.FMCW:
                bandwidth_factor = generator.chirp_bandwidth / generator.symbol_rate
            else:
                bandwidth_factor = 1.

            tx_filter = ShapingFilter(
                shaping_filter.filter_type,
                samples_per_symbol,
                is_matched=False,
                length_in_symbols=shaping_filter.length_in_symbols,
                roll_off=shaping_filter.roll_off,
                bandwidth_factor=bandwidth_factor)
            # TODO: Check if chirp bandwidth is identical to full BW)

            if shaping_filter.filter_type == ShapingFilter.FilterType.RAISED_COSINE:
                # for raised cosine, receive filter is a low-pass filter with
                # bandwidth Rs(1+roll-off)/2
                rx_filter = ShapingFilter(
                    ShapingFilter.FilterType.RAISED_COSINE,
                    samples_per_symbol,
                    length_in_symbols=shaping_filter.length_in_symbols,
                    roll_off=0,
                    bandwidth_factor=1. + shaping_filter.roll_off)
            else:
                # for all other filter types, receive filter is a matched filter
                rx_filter = ShapingFilter(
                    shaping_filter.filter_type,
                    samples_per_symbol,
                    is_matched=True,
                    length_in_symbols=shaping_filter.length_in_symbols,
                    roll_off=shaping_filter.roll_off,
                    bandwidth_factor=bandwidth_factor)

            generator.tx_filter = tx_filter
            generator.rx_filter = rx_filter

        return generator
Пример #22
0
    # noinspection PyMissingOrEmptyDocstring,PyMissingTypeHints,PyUnusedLocal
    @yaml_object(yaml_parser)
    class UID(UnsignedCType):
        """
        This class represent an unsigned ID. Unsigned ID's are always unsigned integer constants.

        They are always of the machine's `unsigned` size.
        """
        yaml_tag = u'!u-id'

    # noinspection PyMissingOrEmptyDocstring,PyMissingTypeHints,PyUnusedLocal
    @yaml_object(yaml_parser)
    class Unsigned(UnsignedCType):
        """
        This class represent an unsigned value. Unsigned values are always unsigned integer constants.

        They are always of the machine's `unsigned` size.
        """
        yaml_tag = u'!unsigned'


# ===--------------------------------------------------------------------------------------------------------------=== #

SafeConstructor.add_constructor(u'tag:yaml.org,2002:seq',
                                CustomSafeConstructor.construct_yaml_seq)
SafeConstructor.add_constructor(u'tag:yaml.org,2002:str',
                                CustomSafeConstructor.construct_yaml_str)

# ===--------------------------------------------------------------------------------------------------------------=== #