Skip to content

Commit

Permalink
chore: tweak json-schema tooling, schemas, and test cases (#1957)
Browse files Browse the repository at this point in the history
This is in preparation for the actual ExperimentConfig objects.
  • Loading branch information
rb-determined-ai authored Feb 12, 2021
1 parent b2d15aa commit 5c7e279
Show file tree
Hide file tree
Showing 46 changed files with 1,426 additions and 624 deletions.
1 change: 1 addition & 0 deletions master/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ clean: ungen
.PHONY: ungen
ungen:
rm -f $(GENERATED)
git checkout -- $(GENERATED_COMMITTED)

.PHONY: gen
gen: $(GENERATED)
Expand Down
13 changes: 9 additions & 4 deletions master/pkg/schemas/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func fillDefaults(obj reflect.Value, defaultBytes []byte, name string) reflect.V

case reflect.Struct:
defaultSource := getDefaultSource(obj)
// Create a clean copy of the object which is settable. This is necessary because if you
// have a required struct (i.e. it appears as a struct rather than a struct pointer on its
// parent object), then obj.Field(i) will not be settable.
newObj := reflect.New(obj.Type()).Elem()
// Iterate through all the fields of the struct once, applying defaults.
for i := 0; i < obj.NumField(); i++ {
var fieldDefaultBytes []byte
Expand All @@ -107,8 +111,10 @@ func fillDefaults(obj reflect.Value, defaultBytes []byte, name string) reflect.V
}
fieldName := fmt.Sprintf("%v.%v", name, obj.Type().Field(i).Name)
// Recurse into the field.
obj.Field(i).Set(fillDefaults(obj.Field(i), fieldDefaultBytes, fieldName))
newObj.Field(i).Set(fillDefaults(obj.Field(i), fieldDefaultBytes, fieldName))
}
// Use the new copy instead of the old one.
obj = newObj

case reflect.Slice:
for i := 0; i < obj.Len(); i++ {
Expand Down Expand Up @@ -148,11 +154,10 @@ func fillDefaults(obj reflect.Value, defaultBytes []byte, name string) reflect.V

// getDefaultSource gets a source of defaults from a Defaultable or Schema interface.
func getDefaultSource(v reflect.Value) interface{} {
// Use Addr so that if the DefaultSource is defined on a struct pointer, it still works.
if defaultable, ok := v.Addr().Interface().(Defaultable); ok {
if defaultable, ok := v.Interface().(Defaultable); ok {
return defaultable.DefaultSource()
}
if schema, ok := v.Addr().Interface().(Schema); ok {
if schema, ok := v.Interface().(Schema); ok {
return schema.ParsedSchema()
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions master/pkg/schemas/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ type BindMountV0 struct {
Propagation *string `json:"propagation"`
}

func (b *BindMountV0) ParsedSchema() interface{} {
func (b BindMountV0) ParsedSchema() interface{} {
return ParsedBindMountV0()
}

func (b *BindMountV0) SanityValidator() *jsonschema.Schema {
func (b BindMountV0) SanityValidator() *jsonschema.Schema {
return GetSanityValidator(
"http://determined.ai/schemas/expconf/v0/bind-mount.json",
)
}

func (b *BindMountV0) CompletenessValidator() *jsonschema.Schema {
func (b BindMountV0) CompletenessValidator() *jsonschema.Schema {
return GetCompletenessValidator(
"http://determined.ai/schemas/expconf/v0/bind-mount.json",
)
Expand Down
75 changes: 41 additions & 34 deletions master/pkg/schemas/expconf/dummies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,45 @@ package expconf

// These dummy types let us compile the generated code without the real struct definitions present.
type (
BindMountV0 struct{}
CheckpointStorageConfigV0 struct{}
DataLayerGCSConfigV0 struct{}
DataLayerS3ConfigV0 struct{}
DataLayerSharedFSConfigV0 struct{}
DataLayerConfigV0 struct{}
EnvironmentImageV0 struct{}
EnvironmentVariablesV0 struct{}
EnvironmentConfigV0 struct{}
ExperimentConfigV0 struct{}
GCSConfigV0 struct{}
HDFSConfigV0 struct{}
CategoricalHyperparameterV0 struct{}
ConstHyperparameterV0 struct{}
DoubleHyperparameterV0 struct{}
IntHyperparameterV0 struct{}
LogHyperparameterV0 struct{}
HyperparameterV0 struct{}
InternalConfigV0 struct{}
LengthV0 struct{}
OptimizationsConfigV0 struct{}
ResourcesConfigV0 struct{}
S3ConfigV0 struct{}
AdaptiveASHASearcherConfigV0 struct{}
AdaptiveSimpleSearcherConfigV0 struct{}
AdaptiveSearcherConfigV0 struct{}
AsyncHalvingSearcherConfigV0 struct{}
GridSearcherConfigV0 struct{}
PBTSearcherConfigV0 struct{}
RandomSearcherConfigV0 struct{}
SingleSearcherConfigV0 struct{}
SyncHalvingSearcherConfigV0 struct{}
SearcherConfigV0 struct{}
SharedFSConfigV0 struct{}
AdaptiveASHAConfigV0 struct{}
AdaptiveConfigV0 struct{}
AdaptiveSimpleConfigV0 struct{}
AsyncHalvingConfigV0 struct{}
BindMountV0 struct{}
CategoricalHyperparameterV0 struct{}
CheckpointStorageConfigV0 struct{}
ConstHyperparameterV0 struct{}
DataLayerConfigV0 struct{}
DoubleHyperparameterV0 struct{}
EnvironmentConfigV0 struct{}
EnvironmentImageMapV0 struct{}
EnvironmentImageV0 struct{}
EnvironmentVariablesMapV0 struct{}
EnvironmentVariablesV0 struct{}
ExperimentConfigV0 struct{}
GCSConfigV0 struct{}
GCSDataLayerConfigV0 struct{}
GridConfigV0 struct{}
HDFSConfigV0 struct{}
HyperparametersV0 struct{}
HyperparameterV0 struct{}
InternalConfigV0 struct{}
IntHyperparameterV0 struct{}
KerberosConfigV0 struct{}
LengthV0 struct{}
LogHyperparameterV0 struct{}
OptimizationsConfigV0 struct{}
PBTConfigV0 struct{}
RandomConfigV0 struct{}
ReproducibilityConfigV0 struct{}
ResourcesConfigV0 struct{}
S3ConfigV0 struct{}
S3DataLayerConfigV0 struct{}
SearcherConfigV0 struct{}
SecurityConfigV0 struct{}
SharedFSConfigV0 struct{}
SharedFSDataLayerConfigV0 struct{}
SingleConfigV0 struct{}
SyncHalvingConfigV0 struct{}
TensorboardStorageConfigV0 struct{}
)
Loading

0 comments on commit 5c7e279

Please sign in to comment.