示例#1
0
文件: ui_api.py 项目: jvitku/torchsim
    def cluster_observer(self, cluster_observer_data: ClusterObserverData,
                         properties: List[ObserverPropertiesItem], win: str):
        """
        Creates/updates Cluster Observer window.
        No specific `opts` are currently supported.
        """

        content = to_nested_dict(cluster_observer_data)
        content['properties'] = properties

        self._send_command_window(win, 'cluster_observer', content)
 def _call_ui(self, ui_helper: UIHelper, data: HierarchicalObservableData,
              properties: List[ObserverPropertiesItem]):
     ui_helper.ui_api.hierarchical_observer(
         data.groups_stacking,
         data.items_per_row,
         data.image_groups, [
             to_nested_dict(group_params)
             for group_params in data.params_groups
         ],
         UIHelper.convert_properties(properties),
         win=f'{self.name}')
示例#3
0
def test_namedtuple_to_dict_nested():
    nested = NestedParams(10, [1, 2, 3])
    params = Params('first', nested)

    result = to_nested_dict(params)
    assert {
        'name': 'first',
        'projection': {
            'width': 10,
            'items': [1, 2, 3]
        }
    } == result
示例#4
0
    def extract(
        self, parameters: List[Dict[str, Any]]
    ) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]:
        """Extracts the header and legend parameters.

        The header parameters are those that are the same in all individual runs.
        The legend parameters are those that are different for at least some of the runs.

        Returns:
            header parameters, legend parameters
        """

        default_parameters = to_nested_dict(self._default_parameters)

        # Create the legend - add default values where they are missing.
        legend = []
        for single_parameters in parameters:
            single_parameters = to_nested_dict(single_parameters)
            try:
                defaults = dict_with_defaults(single_parameters,
                                              default_parameters)
            except NestedDictException:
                defaults = {}

            legend.append(defaults)

        # Get the intersection of all the parameter dicts in the list.
        common_parameters = legend[0]
        for dict2 in legend[1:]:
            common_parameters = get_dict_intersection(common_parameters, dict2)

        header = common_parameters

        # Remove the common parameters from each legend item - they will be displayed in the header.
        legend = [
            remove_from_dict(single_params, common_parameters)
            for single_params in legend
        ]

        return header, legend
示例#5
0
def test_dataclasses_to_dict(test_item):
    assert test_item.expected == to_nested_dict(test_item.data)
示例#6
0
def test_namedtuple_to_dict_simple():
    nested = NestedParams(10, [1, 2, 3])
    result = to_nested_dict(nested)
    assert {'width': 10, 'items': [1, 2, 3]} == result