{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/mlos-config-mlos-jsonc-mlos-json5-mlos-json/_shared/latest--optimizer-schema.json",
  "title": "mlos_bench Optimizer config",
  "description": "config for the mlos_bench optimizer",
  "x-lintel": {
    "source": "https://raw.githubusercontent.com/microsoft/MLOS/main/mlos_bench/mlos_bench/config/schemas/optimizers/optimizer-schema.json",
    "sourceSha256": "1b5e279769631eb60b34877d876ca9e7cdc22d099bac934a8bf33b3a8ee9c9a5"
  },
  "type": "object",
  "properties": {
    "$schema": {
      "description": "The schema to use for validating the optimizer config (accepts both URLs and local paths).",
      "type": "string",
      "$comment": "This is optional, but if provided, should match the name of this file.",
      "pattern": "/schemas/optimizers/optimizer-schema.json$"
    },
    "description": {
      "description": "Optional description of the config.",
      "type": "string"
    },
    "class": {
      "description": "The name of the optimizer class to use.",
      "$comment": "required",
      "enum": [
        "mlos_bench.optimizers.ManualOptimizer",
        "mlos_bench.optimizers.manual_optimizer.ManualOptimizer",
        "mlos_bench.optimizers.MlosCoreOptimizer",
        "mlos_bench.optimizers.mlos_core_optimizer.MlosCoreOptimizer",
        "mlos_bench.optimizers.GridSearchOptimizer",
        "mlos_bench.optimizers.grid_search_optimizer.GridSearchOptimizer",
        "mlos_bench.optimizers.MockOptimizer",
        "mlos_bench.optimizers.mock_optimizer.MockOptimizer",
        "mlos_bench.optimizers.OneShotOptimizer",
        "mlos_bench.optimizers.one_shot_optimizer.OneShotOptimizer"
      ]
    },
    "include_tunables": {
      "description": "A list of file paths containing tunable parameters definitions to include in the optimization.",
      "type": "array",
      "items": {
        "type": "string",
        "$comment": "Paths are expected to be json.",
        "pattern": "[.]json[c]?$"
      },
      "uniqueItems": true,
      "minItems": 1
    },
    "config": {
      "description": "The optimizer specific config.",
      "$comment": "Stub for optimizer specific config appended with condition statements below",
      "type": "object",
      "minProperties": 1
    }
  },
  "$comment": "top level schema document rules",
  "unevaluatedProperties": false,
  "oneOf": [
    {
      "$comment": "Extensions to the allowed 'config' object properties when the optimizer is the mlos_core optimizer.",
      "if": {
        "properties": {
          "class": {
            "enum": [
              "mlos_bench.optimizers.MlosCoreOptimizer",
              "mlos_bench.optimizers.mlos_core_optimizer.MlosCoreOptimizer"
            ]
          }
        },
        "required": [
          "class"
        ],
        "type": "object"
      },
      "then": {
        "properties": {
          "config": {
            "type": "object",
            "allOf": [
              {
                "$comment": "Allow all base optimizer configs",
                "$ref": "#/$defs/config_base_optimizer"
              },
              {
                "$comment": "Extend with properties specific to the mlos_core optimizer type by referencing another subschema file.",
                "$ref": "https://catalog.lintel.tools/schemas/schemastore/mlos-config-mlos-jsonc-mlos-json5-mlos-json/_shared/latest--mlos_core-optimizer-subschema.json"
              }
            ],
            "$comment": "set unevaluatedProperties to false to prevent other properties from being allowed outside the combined set of valid documents $ref'ed above",
            "unevaluatedProperties": false
          }
        },
        "$comment": "Set 'else' to false to prevent it to defaulting to a valid document match."
      },
      "else": false
    },
    {
      "$comment": "extensions to the 'config' object properties when the mock optimizer is being used",
      "if": {
        "properties": {
          "class": {
            "enum": [
              "mlos_bench.optimizers.GridSearchOptimizer",
              "mlos_bench.optimizers.grid_search_optimizer.GridSearchOptimizer"
            ]
          }
        },
        "required": [
          "class"
        ],
        "type": "object"
      },
      "then": {
        "properties": {
          "config": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/$defs/config_base_optimizer"
              }
            ],
            "$comment": "disallow other properties",
            "unevaluatedProperties": false
          }
        }
      },
      "else": false
    },
    {
      "$comment": "extensions to the 'config' object properties when the mock optimizer is being used",
      "if": {
        "properties": {
          "class": {
            "enum": [
              "mlos_bench.optimizers.MockOptimizer",
              "mlos_bench.optimizers.mock_optimizer.MockOptimizer"
            ]
          }
        },
        "required": [
          "class"
        ],
        "type": "object"
      },
      "then": {
        "properties": {
          "config": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/$defs/config_base_optimizer"
              }
            ],
            "$comment": "disallow other properties",
            "unevaluatedProperties": false
          }
        }
      },
      "else": false
    },
    {
      "$comment": "extensions to the 'config' object properties when the one shot optimizer is being used",
      "if": {
        "properties": {
          "class": {
            "enum": [
              "mlos_bench.optimizers.OneShotOptimizer",
              "mlos_bench.optimizers.one_shot_optimizer.OneShotOptimizer"
            ]
          }
        },
        "required": [
          "class"
        ],
        "type": "object"
      },
      "then": {
        "properties": {
          "config": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/$defs/config_base_optimizer"
              }
            ],
            "unevaluatedProperties": false
          }
        }
      },
      "else": false
    },
    {
      "$comment": "extensions to the 'config' object properties when the manual optimizer is being used",
      "if": {
        "properties": {
          "class": {
            "enum": [
              "mlos_bench.optimizers.ManualOptimizer",
              "mlos_bench.optimizers.manual_optimizer.ManualOptimizer"
            ]
          }
        },
        "required": [
          "class"
        ],
        "type": "object"
      },
      "then": {
        "properties": {
          "config": {
            "type": "object",
            "allOf": [
              {
                "$ref": "#/$defs/config_base_optimizer"
              },
              {
                "type": "object",
                "properties": {
                  "max_cycles": {
                    "description": "The maximum number of cycles of tunable values to run the optimizer for.",
                    "type": "integer",
                    "minimum": 1
                  },
                  "tunable_values_cycle": {
                    "description": "The tunable values to cycle through.",
                    "type": "array",
                    "items": {
                      "$ref": "https://catalog.lintel.tools/schemas/schemastore/mlos-config-mlos-jsonc-mlos-json5-mlos-json/_shared/latest--tunable-values-schema.json#/$defs/tunable_values_set"
                    },
                    "minItems": 1
                  }
                }
              }
            ],
            "$comment": "disallow other properties",
            "unevaluatedProperties": false
          }
        }
      },
      "else": false
    }
  ],
  "$defs": {
    "comment": {
      "$comment": "This section contains reusable partial schema bits (or just split out for readability)"
    },
    "config_base_optimizer": {
      "$comment": "config properties common to all optimizer types.",
      "type": "object",
      "properties": {
        "optimization_targets": {
          "$ref": "https://catalog.lintel.tools/schemas/schemastore/mlos-config-mlos-jsonc-mlos-json5-mlos-json/_shared/latest--common-defs-subschemas.json#/$defs/optimization_targets"
        },
        "max_suggestions": {
          "description": "The maximum number of additional (in the case of merging experiment data or resuming experiments) config suggestions to run when we launch the app, or no limit if 0 is provided. Note: configs may be repeated in more than one trial.",
          "type": "integer",
          "minimum": 0,
          "example": 100
        },
        "seed": {
          "description": "The seed to use for the random number generator.",
          "type": "integer",
          "example": 42
        },
        "start_with_defaults": {
          "description": "If false, use the optimizer to suggest the initial configuration; if true (default), use the already assigned values for the first iteration.",
          "type": "boolean",
          "example": true
        }
      }
    }
  },
  "required": [
    "class"
  ]
}
