{
  "$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--mlos_core-optimizer-subschema.json",
  "title": "mlos_core Optimizer config subschema",
  "x-lintel": {
    "source": "https://raw.githubusercontent.com/microsoft/MLOS/main/mlos_bench/mlos_bench/config/schemas/optimizers/mlos_core-optimizer-subschema.json",
    "sourceSha256": "8517af3347567848bf5401b7e4856ed6892472ecd13c49d36eae6f30bdb4dd30"
  },
  "type": "object",
  "properties": {
    "optimizer_type": {
      "description": "The underlying optimizer type to use.",
      "$comment": "See Also: mlos_core/optimizers/__init__.py",
      "enum": [
        null,
        "FLAML",
        "RANDOM",
        "SMAC"
      ]
    },
    "space_adapter_type": {
      "description": "The type of space adapter to use.",
      "$comment": "See Also: mlos_core/spaces/__init__.py",
      "enum": [
        null,
        "IDENTITY",
        "LLAMATUNE"
      ]
    },
    "space_adapter_config": {
      "description": "The space adapter specific config.",
      "$comment": "stub for possible space adapter configs based on type (set using conditionals below)",
      "type": "object"
    }
  },
  "$comment": "Extensions to the allowed 'config' object properties when the optimizer is the mlos_core optimizer.",
  "allOf": [
    {
      "$comment": "add extra recognized params for SMAC optimizer type",
      "if": {
        "properties": {
          "optimizer_type": {
            "const": "SMAC"
          }
        },
        "required": [
          "optimizer_type"
        ],
        "type": "object"
      },
      "then": {
        "$comment": "Not all SMAC optimizer params are exposed here, since some are handled automatically by mlos_bench.",
        "properties": {
          "n_random_init": {
            "description": "Number of points evaluated at start to bootstrap the optimizer.",
            "type": "integer",
            "minimum": 1,
            "example": 10
          },
          "max_trials": {
            "description": "Influence the budget of max number of trials for SMAC. If omitted, will default to max_suggestions.",
            "type": "integer",
            "minimum": 10,
            "example": 100
          },
          "max_ratio": {
            "description": "Maximum ratio of max_trials to be random configurations to be evaluated at start to bootstrap the optimizer. Useful if you want to explicitly control the number of random configurations evaluated at start.",
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "example": 0.25
          },
          "use_default_config": {
            "description": "Whether to use the default config for the first trial.",
            "type": "boolean",
            "example": true
          },
          "n_random_probability": {
            "description": "Probability of choosing to evaluate a random configuration during optimization.",
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "example": 0.1
          },
          "output_directory": {
            "description": "Directory to store SMAC output files.",
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-zA-Z0-9_./\\:-]+$",
            "example": "smac_output"
          },
          "run_name": {
            "description": "Name to give for the smac output (e.g., $experimentId). If null is used, SMAC will calculate a hash based name.",
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-zA-Z0-9_.-]+$",
            "example": "$experimentId"
          }
        }
      }
    },
    {
      "$comment": "a set of rules for the space adapter schema extensions",
      "oneOf": [
        {
          "if": {
            "$comment": "disallow any extra space_adapter_configs for IDENTITY/null space_adapter_type",
            "anyOf": [
              {
                "properties": {
                  "space_adapter_type": {
                    "const": null
                  }
                },
                "required": [
                  "space_adapter_type"
                ],
                "type": "object"
              },
              {
                "properties": {
                  "space_adapter_type": {
                    "const": "IDENTITY"
                  }
                },
                "required": [
                  "space_adapter_type"
                ],
                "type": "object"
              },
              {
                "$comment": "Match when space_adapter_type is not present",
                "not": {
                  "required": [
                    "space_adapter_type"
                  ]
                }
              }
            ]
          },
          "then": {
            "not": {
              "$comment": "space_adapter_config should be omitted in this case",
              "required": [
                "space_adapter_config"
              ]
            }
          },
          "else": false
        },
        {
          "if": {
            "properties": {
              "space_adapter_type": {
                "const": "LLAMATUNE"
              }
            },
            "required": [
              "space_adapter_type"
            ],
            "type": "object"
          },
          "then": {
            "properties": {
              "space_adapter_config": {
                "$comment": "Properties specific to the llamatune space adapter config.",
                "type": "object",
                "properties": {
                  "num_low_dims": {
                    "description": "Number of dimensions used in the low-dimensional parameter search space.",
                    "type": "integer",
                    "minimum": 2
                  },
                  "special_param_values": {
                    "type": "object"
                  },
                  "max_unique_values_per_param": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "unevaluatedProperties": false
              }
            }
          },
          "else": false
        }
      ]
    }
  ]
}
