def test_empty_dimension(self):
        empty_dimension = EmptyDimension(name="empty", type=ContinuousDimension)
        serialized = OptimizerMonitoringServiceEncoder.encode_empty_dimension(empty_dimension)
        deserialized_empty_dimension = OptimizerMonitoringServiceDecoder.decode_empty_dimension(serialized)

        assert isinstance(serialized, OptimizerMonitoringService_pb2.EmptyDimension)
        assert empty_dimension == deserialized_empty_dimension
Exemplo n.º 2
0
 def decode_empty_dimension(
         serialized: OptimizerService_pb2.EmptyDimension) -> EmptyDimension:
     assert isinstance(serialized, OptimizerService_pb2.EmptyDimension)
     return EmptyDimension(
         name=serialized.Name,
         type=OptimizerServiceDecoder.
         pb2_dimension_types_to_dimension_types[serialized.DimensionType])
    def test_empty_dimension(self):
        empty_dimension = EmptyDimension(name="empty",
                                         type=ContinuousDimension)
        serialized = json.dumps(empty_dimension, cls=HypergridJsonEncoder)
        deserialized_dict = json.loads(serialized)
        deserialized_empty_dimension = json.loads(serialized,
                                                  cls=HypergridJsonDecoder)

        self.assertTrue(deserialized_dict["ObjectType"] == "EmptyDimension")
        self.assertTrue(deserialized_dict["Type"] == "ContinuousDimension")
        self.assertTrue(deserialized_dict["Name"] == "empty")

        self.assertTrue(empty_dimension in deserialized_empty_dimension)
        self.assertTrue(deserialized_empty_dimension in empty_dimension)
Exemplo n.º 4
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