@@ -987,11 +987,15 @@ def test_measurement_back_to_back_conversion(self):
987
987
class TestParameterConfigConverterToProto :
988
988
def test_discrete_config_to_proto (self ):
989
989
feasible_values = (- 1 , 3 , 2 )
990
+ child_parameter_config = pyvizier .ParameterConfig .factory (
991
+ "child" , bounds = (- 1.0 , 1.0 )
992
+ )
990
993
parameter_config = pyvizier .ParameterConfig .factory (
991
994
"name" ,
992
995
feasible_values = feasible_values ,
993
996
scale_type = pyvizier .ScaleType .LOG ,
994
997
default_value = 2 ,
998
+ children = [([- 1 ], child_parameter_config )],
995
999
)
996
1000
997
1001
proto = proto_converters .ParameterConfigConverter .to_proto (parameter_config )
@@ -1002,6 +1006,43 @@ def test_discrete_config_to_proto(self):
1002
1006
proto .scale_type
1003
1007
== study_pb2 .StudySpec .ParameterSpec .ScaleType .UNIT_LOG_SCALE
1004
1008
)
1009
+ assert len (proto .conditional_parameter_specs ) == 1
1010
+
1011
+ spec = proto .conditional_parameter_specs [0 ]
1012
+ assert spec .parameter_spec .parameter_id == "child"
1013
+ assert spec .parameter_spec .double_value_spec .min_value == - 1.0
1014
+ assert spec .parameter_spec .double_value_spec .max_value == 1.0
1015
+ assert len (spec .parent_discrete_values .values ) == 1
1016
+ assert spec .parent_discrete_values .values [0 ] == - 1
1017
+
1018
+ def test_categorical_config_to_proto_with_children (self ):
1019
+ feasible_values = ("option_a" , "option_b" )
1020
+ child_parameter_config = pyvizier .ParameterConfig .factory (
1021
+ "child" , bounds = (- 1.0 , 1.0 )
1022
+ )
1023
+ parameter_config = pyvizier .ParameterConfig .factory (
1024
+ "name" ,
1025
+ feasible_values = feasible_values ,
1026
+ children = [(["option_a" ], child_parameter_config )],
1027
+ )
1028
+ proto = proto_converters .ParameterConfigConverter .to_proto (parameter_config )
1029
+ assert len (proto .conditional_parameter_specs ) == 1
1030
+ spec = proto .conditional_parameter_specs [0 ]
1031
+ assert len (spec .parent_categorical_values .values ) == 1
1032
+ assert spec .parent_categorical_values .values [0 ] == "option_a"
1033
+
1034
+ def test_integer_config_to_proto_with_children (self ):
1035
+ child_parameter_config = pyvizier .ParameterConfig .factory (
1036
+ "child" , bounds = (- 1.0 , 1.0 )
1037
+ )
1038
+ parameter_config = pyvizier .ParameterConfig .factory (
1039
+ "name" , bounds = (1 , 10 ), children = [([6 ], child_parameter_config )]
1040
+ )
1041
+ proto = proto_converters .ParameterConfigConverter .to_proto (parameter_config )
1042
+ assert len (proto .conditional_parameter_specs ) == 1
1043
+ spec = proto .conditional_parameter_specs [0 ]
1044
+ assert len (spec .parent_int_values .values ) == 1
1045
+ assert spec .parent_int_values .values [0 ] == 6
1005
1046
1006
1047
1007
1048
class TestParameterConfigConverterFromProto :
0 commit comments