Example #1
0
 def decode_subgrid(
     subgrid: OptimizerService_pb2.GuestSubgrid
 ) -> SimpleHypergrid.JoinedSubgrid:
     assert isinstance(subgrid, OptimizerService_pb2.GuestSubgrid)
     return SimpleHypergrid.JoinedSubgrid(
         subgrid=OptimizerServiceDecoder.decode_hypergrid(subgrid.Subgrid),
         join_dimension=OptimizerServiceDecoder.decode_dimension(
             subgrid.ExternalPivotDimension))
Example #2
0
    def object_hook(self, obj):
        type_names_to_types = {
            "EmptyDimension": EmptyDimension,
            "CategoricalDimension": CategoricalDimension,
            "ContinuousDimension": ContinuousDimension,
            "DiscreteDimension": DiscreteDimension,
            "OrdinalDimension": OrdinalDimension,
            "CompositeDimension": CompositeDimension,
        }

        if 'ObjectType' not in obj:
            return obj

        object_type = obj['ObjectType']

        if object_type == 'EmptyDimension':
            return EmptyDimension(
                name=obj['Name'],
                type=type_names_to_types[obj['Type']]
            )
        if object_type == "CategoricalDimension":
            return CategoricalDimension(
                name=obj['Name'],
                values=obj['Values']
            )
        if object_type == "ContinuousDimension":
            return ContinuousDimension(
                name=obj['Name'],
                min=obj.get('Min', None),
                max=obj.get('Max', None),
                include_min=obj.get('IncludeMin', None),
                include_max=obj.get('IncludeMax', None)
            )
        if object_type == "DiscreteDimension":
            return DiscreteDimension(
                name=obj['Name'],
                min=obj['Min'],
                max=obj['Max']
            )
        if object_type == "OrdinalDimension":
            return OrdinalDimension(
                name=obj['Name'],
                ordered_values=obj.get('OrderedValues', None),
                ascending=obj.get('Ascending', True) # TODO - this looks risky
            )
        if object_type == "CompositeDimension":
            return CompositeDimension(
                name=obj['Name'],
                chunks_type=type_names_to_types[obj['ChunksType']],
                chunks=obj['Chunks']
            )
        if object_type == "SimpleHypergrid":
            simple_hypergrid = SimpleHypergrid(
                name=obj['Name'],
                dimensions=obj.get('Dimensions', [])
            )

            for _, subgrids_joined_on_dimension in obj.get('GuestSubgrids', dict()).items():
                for joined_subgrid in subgrids_joined_on_dimension:
                    simple_hypergrid.add_subgrid_on_external_dimension(
                        other_hypergrid=joined_subgrid.subgrid,
                        external_dimension=joined_subgrid.join_dimension
                    )
            return simple_hypergrid

        if object_type == "GuestSubgrid":
            return SimpleHypergrid.JoinedSubgrid(
                subgrid=obj['Subgrid'],
                join_dimension=obj['ExternalPivotDimension']
            )

        if object_type == "set":
            return set(obj['Values'])

        return obj