{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Experimenter Experiment",
  "description": "An Experiment: one model plus everything done to it. The only shape Experimenter opens or writes. A one-mode YAML file with a type: key is refused.",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "The Experiment's own name. Names its folder under Output/ and fills the sequence context column of the collated file (Output.csv by default). Absent means the document's own file name."
    },
    "output_saved_runs": {
      "type": "boolean",
      "description": "Which saved runs from the model's isdb are folded into the collated file. Absent (the GUI's 'All') folds every bound saved run; false ('None') folds none. A Table-name output scope folds unfiltered, because Experimenter does not read a Table's variable list back from the model. The named-list form is retired: a list value is refused, not silently accepted."
    },
    "model": {
      "type": "string",
      "description": "The model file (.stmx), relative to this document. Every Run executes on a throwaway copy."
    },
    "modules_dir": {
      "type": "string",
      "description": "Folder holding the model's .itmx modules, relative to this document. Every .itmx there is indexed; the model's own <module> references are ignored."
    },
    "engine": {
      "type": "string",
      "description": "architect (real Stella), professional or simulator (the other Stella editions), or experimenter (Euler/RK2/RK4 integration, Latin Hypercube/Multivariate/Grid for Sensitivity, Powell/Differential Evolution for Optimization, see Concepts, Engine, for its launch refusals). Falls back to the persisted Settings-window default, then to the first configured engine, when absent."
    },
    "outputs": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Display list. Does not scope a real run."
    },
    "retries": {
      "type": "integer",
      "description": "How many times a failed Run is retried. Default 2."
    },
    "timeout": {
      "type": [
        "number",
        "null"
      ],
      "description": "Seconds before a Run is killed and retried. Default 900."
    },
    "workers": {
      "type": "integer",
      "description": "How many Runs may run at the same time on an engine that allows it (The Experimenter engine). Absent means the Settings-window value, then one fewer than the number of physical CPU cores. A memory guard can lower the count when one Run would not fit 70% of physical memory that many times. An engine that does not allow it (Architect) runs one Run at a time, whatever this says."
    },
    "calibration_timeout": {
      "type": [
        "number",
        "null"
      ],
      "description": "Overrides timeout for optimize Runs specifically."
    },
    "datasets": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DatasetAxisEntry"
      },
      "description": "The dataset axis. Absent means the single implicit dataset (this document's own directory)."
    },
    "output_increment": {
      "type": "boolean",
      "description": "Default false."
    },
    "output_variables": {
      "type": "string",
      "description": "Scopes every section's collected output by default: a variable-list file or a model Table's export name."
    },
    "retention": {
      "type": "string",
      "enum": [
        "everything",
        "outputs_only",
        "outputs_and_final_models",
        "final_chained_group"
      ],
      "description": "What every launch keeps. Absent means the Settings default, everything."
    },
    "runs": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/RunEntry"
      },
      "description": "Runs and Groups, keyed by a stable id (the map key IS the id and the display name)."
    },
    "optimizations": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/OptimizationEntry"
      },
      "description": "Calibration scopes, keyed by a stable id."
    },
    "sensitivities": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/SensitivityEntry"
      },
      "description": "Sensitivity routines, keyed by name. A Run binds one through config.sensitivity."
    },
    "sequences": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/SequenceEntry"
      },
      "description": "Sequences, keyed by a stable id. A member's stage: names a sibling id in runs: or optimizations:, one flat namespace across both."
    }
  },
  "additionalProperties": false,
  "required": [
    "model"
  ],
  "$defs": {
    "Override": {
      "type": "object",
      "properties": {
        "row": {
          "type": [
            "string",
            "integer"
          ],
          "description": "Row selector: a name matched against column 0, or a 0-based index."
        },
        "col": {
          "type": [
            "string",
            "integer"
          ],
          "description": "Column selector: a header name, or a 0-based index."
        },
        "value": {
          "description": "The scalar written. Never an equation."
        }
      },
      "additionalProperties": false,
      "required": [
        "row",
        "col",
        "value"
      ],
      "description": "One cell edit of a data entry's own CSV (csv_cells.Override)."
    },
    "DataEntry": {
      "type": "object",
      "properties": {
        "file": {
          "type": "string",
          "description": "The CSV or .xlsx file. A path (with a separator) places an external file into the Run copy; a bare basename configures the model's own matching block."
        },
        "type": {
          "type": "string",
          "description": "import (default) or export.",
          "enum": [
            "import",
            "export"
          ]
        },
        "enabled": {
          "type": "boolean",
          "description": "Whether the model's import/export block fires. None leaves the model's own setting untouched."
        },
        "link": {
          "type": "string",
          "description": "dynamic or on_demand (Stella's own Link kinds); both load on every headless run.",
          "enum": [
            "dynamic",
            "on_demand"
          ]
        },
        "behavior": {
          "type": "string",
          "description": "Import kind: overwrite, control, dimensions, or timevarying.",
          "enum": [
            "overwrite",
            "control",
            "dimensions",
            "timevarying"
          ]
        },
        "interpolate": {
          "type": "string",
          "description": "Timevarying imports only: continuous, inside, extrapolated, discrete-backward, discrete-forward, or raw.",
          "enum": [
            "continuous",
            "inside",
            "extrapolated",
            "discrete-backward",
            "discrete-forward",
            "raw"
          ]
        },
        "orientation": {
          "type": "string",
          "description": "vertical or horizontal (a timevarying import's own CSV layout).",
          "enum": [
            "vertical",
            "horizontal"
          ]
        },
        "interval": {
          "type": "string",
          "description": "Exports only: one_value, DT, current_time, or use_settings (paired with scope: table).",
          "enum": [
            "one_value",
            "DT",
            "current_time",
            "use_settings"
          ]
        },
        "precomputed": {
          "type": "boolean",
          "description": "Exports only: Stella's own precomputed-values export setting."
        },
        "format": {
          "type": "string",
          "description": "Exports only: numbers or strings. Under strings, the exported numbers print the way the model's own Precision and Scale by settings (Model Settings) format them; Experimenter does not write those two attributes.",
          "enum": [
            "numbers",
            "strings"
          ]
        },
        "scope": {
          "description": "Exports only: all, parameter_values, table (paired with table:), a list of variable names, or a variable-list file reference (a .txt, resolved relative to this document).",
          "anyOf": [
            {
              "type": "string",
              "pattern": "^\\s*([Aa][Ll][Ll]|[Pp][Aa][Rr][Aa][Mm][Ee][Tt][Ee][Rr]_[Vv][Aa][Ll][Uu][Ee][Ss]|[Tt][Aa][Bb][Ll][Ee])\\s*$"
            },
            {
              "type": "string",
              "pattern": "\\.[^./\\\\]+\\s*$"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          ]
        },
        "table": {
          "type": "string",
          "description": "Exports only, required when scope: table, the model's own Report/Table view name (its isee:export_name)."
        },
        "tag": {
          "type": "string",
          "description": "Exports only: the Data Source Tag's name, written as <isee:tag> in place of <all/>. Exclusive with scope: an entry setting both refuses."
        },
        "worksheet": {
          "type": "string",
          "description": "Excel files only: the sheet an import reads or an export writes. Written as the block's worksheet attribute, with type Excel. A bare file name that matches several blocks on one workbook needs it to pick one."
        },
        "role": {
          "type": "string",
          "description": "comparison marks the calibration comparison dataset; it wires no import/export block.",
          "enum": [
            "comparison"
          ]
        },
        "overrides": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Override"
          },
          "description": "Byte-faithful cell edits into this entry's own CSV. Not valid on a workbook."
        }
      },
      "additionalProperties": false,
      "required": [
        "file"
      ],
      "description": "One data: entry, a Run's import/export configuration, keyed by file name (data_files.DataEntry)."
    },
    "RunByModule": {
      "description": "Stella's 'simulate by selected modules' switch (config_edits.RunByModule). A bare string, or a mapping when out_of_sector is non-default.",
      "oneOf": [
        {
          "type": "string",
          "description": "The bare-string form: the action alone ('remove'), or 'add' when out_of_sector is left at its default (true).",
          "enum": [
            "add",
            "remove"
          ]
        },
        {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "description": "add or remove the sim_specs run-by-module element.",
              "enum": [
                "add",
                "remove"
              ]
            },
            "out_of_sector": {
              "type": "boolean",
              "description": "Ignored on remove. Default true."
            }
          },
          "additionalProperties": false,
          "required": [
            "action"
          ]
        }
      ]
    },
    "ModuleEdit": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The module's name."
        },
        "run": {
          "type": "boolean",
          "description": "The module's run flag (config_edits.ModuleEdit), used with a modules: run-by-selection configuration."
        }
      },
      "additionalProperties": false,
      "required": [
        "name",
        "run"
      ],
      "description": "One entry of a config: modules: list."
    },
    "Config": {
      "type": "object",
      "properties": {
        "sim_specs": {
          "type": "object",
          "properties": {
            "method": {
              "type": "string",
              "description": "The integration method token.",
              "enum": [
                "Euler",
                "CYCLE_TIME",
                "RK2",
                "RK4"
              ]
            }
          },
          "description": "Model-level simulation settings: start/stop/dt and the method/restore_on_start/save_interval/analyze_mode set (and more), plus time_units, interaction_mode and a nested loop block (scores, exhaustive_allowed, pause_after_rates). Unknown keys are refused and each value is type-checked. interaction_mode: Normal is written as absence. Accepted keys: analyze_mode, disable_simulation_events, dt, dt_reciprocal, ignore_module_errors, instantaneous_flows, interaction_mode, loop, method, pause_interval, pause_interval_inf, play_start, restore_on_start, run_prefix, save_interval, sim_duration, simulation_delay, start, stop, strict_units, time_units."
        },
        "modules": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ModuleEdit"
          },
          "description": "Per-module run flags."
        },
        "optimizer": {
          "type": [
            "integer",
            "string"
          ],
          "description": "The optimizer this Run/step selects: an active_index or a spec name."
        },
        "sensitivity": {
          "type": "string",
          "description": "The named Sensitivity routine (sensitivities: key) this Run runs."
        },
        "comparison_run": {
          "type": "string",
          "description": "Global payoff comparison-run binding (a saved-run name)."
        },
        "payoff_comparison_runs": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "description": "Saved-run name for one named payoff."
          },
          "description": "Per-payoff comparison-run overrides: {payoff name -> saved-run name}."
        },
        "run_by_module": {
          "$ref": "#/$defs/RunByModule",
          "description": "Adds or removes the sim_specs run-by-module element."
        }
      },
      "additionalProperties": false,
      "description": "A Run's Configuration edits (config_edits.ConfigSpec). Every key is optional."
    },
    "Script": {
      "type": "object",
      "properties": {
        "script": {
          "type": "string",
          "description": "The command to run (bare '.py'/'.R' gets the inferred python3/Rscript; anything else runs verbatim)."
        },
        "name": {
          "type": "string",
          "description": "Label shown in the Monitor and EXPERIMENTER_POSITION."
        },
        "timeout": {
          "type": "number",
          "description": "Seconds before the script is killed. Default 300."
        },
        "continue_on_error": {
          "type": "boolean",
          "description": "Default false (halt-on-failure). true lets a later item run after this script fails."
        },
        "active": {
          "type": "boolean",
          "description": "Default true. false skips this script entirely (sequence-active-column)."
        },
        "level": {
          "type": "integer",
          "description": "Sequence outline depth. 0 starts from the Template. Ignored outside a sequences: entry."
        }
      },
      "additionalProperties": false,
      "required": [
        "script"
      ],
      "description": "An inline Script (spec.HookSpec): a sequences: stage, or a top-level datasets: entry's before:/after: bookend. A runs: entry, a group: member or an optimizations: runs: item that holds script: refuses the file."
    },
    "RunGroup": {
      "type": "object",
      "properties": {
        "group": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Sibling ids of this SAME runs: map, in the group's own order. A Script is never a member."
        },
        "retries": {
          "type": "integer",
          "description": "Overrides the file default for every Run in this group."
        },
        "timeout": {
          "type": "number",
          "description": "Seconds, per Run in this group."
        },
        "retention": {
          "type": "string",
          "enum": [
            "everything",
            "outputs_only",
            "outputs_and_final_models",
            "final_chained_group"
          ],
          "description": "What the Runs of this group keep. Absent inherits the file value."
        },
        "output_variables": {
          "type": "string",
          "description": "A variable-list file or Table name, group scope."
        },
        "sim_specs": {
          "type": "object",
          "description": "Group-level simulation window (start/stop), distinct from a Run's own config.sim_specs."
        },
        "engine": {
          "type": "string",
          "description": "The engine every Run in this group simulates on, overriding the file default. A Run below with its own engine: wins over this."
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Display list for every Run in this group. Does not scope a real run. Absent inherits the document value."
        },
        "calibration_timeout": {
          "type": "number",
          "description": "Seconds before an optimize Run is killed and retried, for every Run in this group. Overrides timeout for optimize Runs. Absent inherits the document value."
        },
        "datasets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DatasetAxisEntry"
          },
          "description": "The dataset axis for every Run in this group. Absent inherits the document's datasets: list."
        },
        "output_increment": {
          "type": "boolean",
          "description": "Output increment for every Run in this group. Absent inherits the document value."
        }
      },
      "additionalProperties": false,
      "required": [
        "group"
      ],
      "description": "A runs: entry naming an ordered set of sibling ids (spec.RunGroup), a self-contained runnable scope."
    },
    "Check": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The name of the check, unique in its Run. batch.json gives the result under this name."
        },
        "variable": {
          "type": "string",
          "description": "The model variable that the check reads from the output file of the Run."
        },
        "at": {
          "type": [
            "string",
            "number"
          ],
          "description": "The time points that the check reads: final or all, or one time value. The default is final. The test present takes no at."
        },
        "test": {
          "type": "string",
          "description": "How the observed value compares with value.",
          "enum": [
            "==",
            "!=",
            "<",
            "<=",
            ">",
            ">=",
            "between",
            "present"
          ]
        },
        "value": {
          "type": [
            "number",
            "array"
          ],
          "items": {
            "type": "number"
          },
          "description": "A number, or [low, high] for between. The test present takes no value."
        },
        "tolerance": {
          "type": "number",
          "minimum": 0,
          "description": "An absolute tolerance for == and !=. The default is 0."
        }
      },
      "additionalProperties": false,
      "required": [
        "id",
        "variable",
        "test"
      ],
      "description": "One acceptance check of a Run (spec.CheckSpec). A failed check does not change the job status."
    },
    "PlainRun": {
      "type": "object",
      "properties": {
        "data": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DataEntry"
          },
          "description": "This Run's import/export configuration."
        },
        "config": {
          "$ref": "#/$defs/Config",
          "description": "This Run's Configuration edits."
        },
        "depends_on": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Sibling ids (this same runs: map) that must finish first."
        },
        "mode": {
          "type": "string",
          "description": "simulate (default, -r) or optimize (-ro, a calibration step run standalone).",
          "enum": [
            "simulate",
            "optimize"
          ]
        },
        "retries": {
          "type": "integer",
          "description": "Overrides the file/group default for this Run."
        },
        "timeout": {
          "type": [
            "number",
            "null"
          ],
          "description": "Seconds before this Run is retried. null turns the watchdog off for this Run."
        },
        "retention": {
          "type": "string",
          "enum": [
            "everything",
            "outputs_only",
            "outputs_and_final_models",
            "final_chained_group"
          ],
          "description": "What this Run keeps. Absent inherits its group, then the file."
        },
        "output_variables": {
          "type": "string",
          "description": "A variable-list file (.txt/.csv) or a model Table's export name, scoping this Run's output."
        },
        "engine": {
          "type": "string",
          "description": "The engine this Run simulates on, overriding its group/file default. Stored even when it equals the resolved default: an explicit choice survives a later change to the default."
        },
        "checks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Check"
          },
          "description": "Acceptance checks on the output of this Run. The launch writes each result to batch.json beside the job status."
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Display list for this Run. Does not scope a real run. Absent inherits the document value."
        },
        "calibration_timeout": {
          "type": "number",
          "description": "Seconds before an optimize Run is killed and retried, for this Run. Overrides timeout for optimize Runs. Absent inherits the document value."
        },
        "datasets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DatasetAxisEntry"
          },
          "description": "The dataset axis for this Run. Absent inherits the document's datasets: list."
        },
        "output_increment": {
          "type": "boolean",
          "description": "Output increment for this Run. Absent inherits the document value."
        }
      },
      "additionalProperties": false,
      "description": "One Run (spec.RunSpec), a plain runs: entry with no script: or group: key. Every key is optional; {} is a valid native Run."
    },
    "RunEntry": {
      "description": "One runs: map value: a plain Run, or a Group (group: key). A Script is a sequences: stage only.",
      "oneOf": [
        {
          "$ref": "#/$defs/PlainRun"
        },
        {
          "$ref": "#/$defs/RunGroup"
        }
      ]
    },
    "ParameterOverride": {
      "type": "object",
      "properties": {
        "min": {
          "type": [
            "number",
            "string"
          ],
          "description": "Search lower bound override."
        },
        "max": {
          "type": [
            "number",
            "string"
          ],
          "description": "Search upper bound override."
        },
        "scaling": {
          "type": [
            "number",
            "string"
          ],
          "description": "Search-space scaling override."
        },
        "increment": {
          "type": [
            "number",
            "string"
          ],
          "description": "Grid/Discrete/Differential-Evolution step size override."
        }
      },
      "additionalProperties": false,
      "description": "Overrides for one optimizer parameter, keyed by variable name (config_edits.ParameterValueOverride)."
    },
    "OptimizerOverride": {
      "type": "object",
      "properties": {
        "tolerance": {
          "type": [
            "number",
            "string"
          ],
          "description": "Optimizer convergence tolerance override."
        },
        "init_step": {
          "type": [
            "number",
            "string"
          ],
          "description": "Initial Step override."
        },
        "max_sims": {
          "type": [
            "number",
            "string"
          ],
          "description": "Maximum simulations (XML maxiter) override."
        },
        "additional_starts": {
          "type": [
            "number",
            "string"
          ],
          "description": "Additional-starts count override."
        },
        "k": {
          "type": [
            "number",
            "string"
          ],
          "description": "Differential Evolution only."
        },
        "generations": {
          "type": [
            "number",
            "string"
          ],
          "description": "Differential Evolution only."
        },
        "pop_size": {
          "type": [
            "number",
            "string"
          ],
          "description": "Differential Evolution only."
        },
        "report_interval": {
          "type": [
            "number",
            "string"
          ],
          "description": "How often Stella reports optimizer progress; 0 means roughly 50 reports."
        },
        "confidence_range": {
          "type": [
            "number",
            "string"
          ],
          "description": "Compute Confidence Bounds (single-payoff only). The sign is the mode: 0 off, positive a payoff value change, negative a statistical percent."
        },
        "method": {
          "type": "string",
          "description": "The search algorithm.",
          "enum": [
            "Powell",
            "Grid",
            "Discrete",
            "Differential Evolution"
          ]
        },
        "recombine_type": {
          "type": "string",
          "description": "Differential Evolution's Mutation Type.",
          "enum": [
            "rand",
            "best",
            "target-to-rand",
            "target-to-best",
            "either-or"
          ]
        },
        "payoff_action": {
          "type": "string",
          "description": "max or min, on the optimizer's active payoff link.",
          "enum": [
            "max",
            "min"
          ]
        },
        "payoff_inactive": {
          "type": "boolean",
          "description": "Deactivates the optimizer's payoff link."
        },
        "payoff_name": {
          "type": "string",
          "description": "Moves the optimizer's active payoff link to a different payoff."
        },
        "payoff_links": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "action": {
                "type": "string",
                "description": "max, min, lte (Keep <= 0) or lt (Keep < 0). Leave it out for a Calibration payoff.",
                "enum": [
                  "max",
                  "min",
                  "lte",
                  "lt"
                ]
              },
              "inactive": {
                "type": "boolean",
                "description": "true unticks the payoff in the table; false removes the attribute."
              }
            },
            "additionalProperties": false
          },
          "description": "Differential Evolution's multi-criteria payoff table: {payoff name -> its link settings}. Each entry sets one payoff link and creates it when the optimizer has none. Do not combine it with payoff_action, payoff_inactive or payoff_name."
        },
        "additional_starts_path": {
          "type": "string",
          "description": "The additional-starts From File path, model-relative with Stella's own r.. prefix (e.g. r../Starts.csv). Written as typed."
        },
        "use_additional_starts_file": {
          "type": "boolean",
          "description": "The Additional Starts dialog's From-File/Randomized toggle. true removes the additional-starts count in the same edit, matching Stella's own save; false leaves the count to its own field."
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/ParameterOverride"
          },
          "description": "Per-parameter overrides, keyed by variable name."
        },
        "grid": {
          "$ref": "#/$defs/GridOverride",
          "description": "Grid method advanced fields. Meaningful only when method is Grid."
        },
        "discrete": {
          "$ref": "#/$defs/DiscreteOverride",
          "description": "Discrete method advanced fields. Meaningful only when method is Discrete."
        },
        "differential_evolution": {
          "$ref": "#/$defs/DifferentialEvolutionOverride",
          "description": "Differential Evolution advanced fields. Meaningful only when method is Differential Evolution."
        },
        "compare_against_sensitivity": {
          "type": "string",
          "description": "The sensitivity spec's name to compare this optimizer against (Optimize across all runs); absent means None."
        },
        "want_worst_case": {
          "type": "boolean",
          "description": "Maximize worst (lowest) payoff across the sensitivity runs, instead of the average. Accepted only while compare_against_sensitivity is set."
        }
      },
      "additionalProperties": false,
      "description": "Overrides for one named optimizer (config_edits.OptimizerValueOverride), keyed by optimizer name under optimizations: <entry>: optimizations:."
    },
    "GridParameterOverride": {
      "type": "object",
      "properties": {
        "tolerance": {
          "type": [
            "number",
            "string"
          ],
          "description": "Grid per-parameter Tolerance override. 0.01 (Stella's own default) is written as absence."
        },
        "steps": {
          "type": [
            "number",
            "string"
          ],
          "description": "Grid per-parameter Number of steps override. 11 (Stella's own default) is written as absence."
        }
      },
      "additionalProperties": false,
      "description": "Overrides for one Grid parameter's own advanced fields, keyed by variable name (config_edits.GridParameterOverride)."
    },
    "GridOverride": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "description": "Grid Search Type. Exhaustive (Stella's own default) is written as absence.",
          "enum": [
            "Exhaustive",
            "Bisecting",
            "Sequential",
            "Latin Hypercube"
          ]
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/GridParameterOverride"
          },
          "description": "Per-parameter Tolerance/Number of steps overrides, keyed by variable name."
        }
      },
      "additionalProperties": false,
      "description": "The Grid method's own advanced-field block (config_edits.GridOverride), under optimizations: <entry>: optimizations: <name>: grid:."
    },
    "DiscreteParameterOverride": {
      "type": "object",
      "properties": {
        "deadzone": {
          "type": "string",
          "description": "Discrete per-parameter exploration mode override. 'Check only a single increment' (Stella's own default) is written as absence.",
          "enum": [
            "Check only a single increment",
            "Explore upward to the max",
            "Explore downward to the min",
            "Explore both directions",
            "Exhaustive search on each pass"
          ]
        }
      },
      "additionalProperties": false,
      "description": "Overrides for one Discrete parameter's own advanced field, keyed by variable name (config_edits.DiscreteParameterOverride)."
    },
    "DiscreteOverride": {
      "type": "object",
      "properties": {
        "maxpass": {
          "type": [
            "number",
            "string"
          ],
          "description": "Discrete maximum passes override. 1000 (Stella's own default) is written as absence."
        },
        "refine": {
          "type": "boolean",
          "description": "Discrete Refine override. false (Stella's own default) is written as absence."
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/DiscreteParameterOverride"
          },
          "description": "Per-parameter Deadzone overrides, keyed by variable name."
        }
      },
      "additionalProperties": false,
      "description": "The Discrete method's own advanced-field block (config_edits.DiscreteOverride), under optimizations: <entry>: optimizations: <name>: discrete:."
    },
    "DifferentialEvolutionOverride": {
      "type": "object",
      "properties": {
        "seed": {
          "type": [
            "number",
            "string"
          ],
          "description": "Differential Evolution seed override. 0 (Stella's own default, random per run) is written as absence."
        },
        "cr": {
          "type": [
            "number",
            "string"
          ],
          "description": "Differential Evolution Crossover prob override, from 0 to 1. 0.2 (Stella's own default) is written as absence. The Experimenter engine refuses a value outside the range.",
          "minimum": 0,
          "maximum": 1
        },
        "f": {
          "type": [
            "number",
            "string"
          ],
          "description": "Differential Evolution Scaling factor override, at least 0 and below 2. 0.6 (Stella's own default) is written as absence. The Experimenter engine refuses a value outside the range.",
          "minimum": 0,
          "exclusiveMaximum": 2
        },
        "crossover_type": {
          "type": "string",
          "description": "Differential Evolution Crossover Type override. bin (Stella's own default) is written as absence.",
          "enum": [
            "bin",
            "exp"
          ]
        }
      },
      "additionalProperties": false,
      "description": "The Differential Evolution method's own advanced-field block (config_edits.DifferentialEvolutionOverride), under optimizations: <entry>: optimizations: <name>: differential_evolution:."
    },
    "ElementOverride": {
      "type": "object",
      "properties": {
        "weight": {
          "type": [
            "number",
            "string"
          ],
          "description": "A number, or a variable name for Stella's dynamic-weight form."
        },
        "tolerance": {
          "type": [
            "number",
            "string"
          ],
          "description": "Comparison tolerance override."
        },
        "time_range_type": {
          "type": "string",
          "description": "The payoff element's time horizon.",
          "enum": [
            "terminal_value",
            "full_span",
            "at_time",
            "subset"
          ]
        },
        "time_range_start": {
          "type": [
            "number",
            "string"
          ],
          "description": "Required for at_time and subset; refused otherwise."
        },
        "time_range_stop": {
          "type": [
            "number",
            "string"
          ],
          "description": "Required for subset; refused for at_time."
        },
        "compare_name": {
          "type": "string",
          "description": "The data-side variable this element is compared against (a selection, not a rename)."
        },
        "compare_type": {
          "type": "string",
          "description": "ls or mad, written on the element's own type attribute.",
          "enum": [
            "ls",
            "mad"
          ]
        }
      },
      "additionalProperties": false,
      "description": "Overrides for one payoff element, keyed by variable name (config_edits.ElementValueOverride)."
    },
    "PayoffOverride": {
      "type": "object",
      "properties": {
        "comparison": {
          "type": "string",
          "description": "Overrides this payoff's comparison CSV (relative to this document)."
        },
        "comparison_run": {
          "type": "string",
          "description": "Overrides this payoff's saved comparison-run name."
        },
        "compare_type": {
          "type": "string",
          "description": "Spec-level default: ls or mad.",
          "enum": [
            "ls",
            "mad"
          ]
        },
        "compare_tolerance": {
          "type": [
            "number",
            "string"
          ],
          "description": "Spec-level comparison tolerance default."
        },
        "recompute_weights": {
          "type": "boolean",
          "description": "Stella's 'Automatically compute weights' switch. Warns (never blocks) when combined with an authored element weight."
        },
        "calibration": {
          "type": "boolean",
          "description": "Payoff kind: true fits a comparison run (Calibration), false maximizes/minimizes a variable (Outcome)."
        },
        "compute_full_likelihood": {
          "type": "boolean",
          "description": "Stella's 'Compute full likelihood (optimize over weights)' switch, shown in place of recompute_weights only while at least one element's weight is a variable name. Refused unless a variable-name weight is in effect."
        },
        "simplified": {
          "type": "boolean",
          "description": "The Stella checkbox 'Use simplified payoff specification settings'. true: the payoff holds compare_type, compare_tolerance and compare_run. Every element gets them. false: the payoff holds none of them. Each element keeps its own. Absent: the model state. Calibration only."
        },
        "elements": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/ElementOverride"
          },
          "description": "Per-element overrides, keyed by variable name."
        }
      },
      "additionalProperties": false,
      "description": "A per-payoff comparison-run + numeric-element override (spec.PayoffOverride), keyed by payoff name under optimizations: <entry>: payoffs:."
    },
    "Step": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The step's label, selects the optimizer through config.optimizer."
        },
        "data": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DataEntry"
          },
          "description": "This step's own import/export overrides, merged over the scope's shared files: by resource identity."
        },
        "config": {
          "$ref": "#/$defs/Config",
          "description": "This Run's Configuration edits."
        },
        "output_variables": {
          "type": "string",
          "description": "Overrides the group/file output scope for this step."
        },
        "retries": {
          "type": "integer",
          "description": "Overrides the group/file retry budget for this step."
        },
        "timeout": {
          "type": "number",
          "description": "Seconds before this step is retried."
        },
        "retention": {
          "type": "string",
          "enum": [
            "everything",
            "outputs_only",
            "outputs_and_final_models",
            "final_chained_group"
          ],
          "description": "What this step keeps. Absent inherits its scope, then the file."
        },
        "chain": {
          "type": "boolean",
          "description": "false (default) runs this step in its own folder from a fresh Template copy; true continues in the folder of the step above it. Not valid on the first step of a scope."
        }
      },
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "description": "One optimize step (spec.CalibrationStep) inside an optimizations: <entry>: runs: list."
    },
    "OptimizationStepEntry": {
      "description": "One optimizations: <entry>: runs: list item: an optimize step. A Script is a sequences: stage only.",
      "oneOf": [
        {
          "$ref": "#/$defs/Step"
        }
      ]
    },
    "OptimizationEntry": {
      "type": "object",
      "properties": {
        "comparison": {
          "type": "string",
          "description": "Default comparison CSV for every payoff in this scope, relative to this document."
        },
        "comparison_run": {
          "type": "string",
          "description": "Default saved comparison-run name, bound and written to the copy's isdb once at scope start."
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DataEntry"
          },
          "description": "The shared import/export configuration every step in this scope uses (the fit-carrier declaration lives here)."
        },
        "payoffs": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/PayoffOverride"
          },
          "description": "Per-payoff overrides, keyed by payoff name."
        },
        "optimizations": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/OptimizerOverride"
          },
          "description": "Per-optimizer value overrides, keyed by optimizer name."
        },
        "retries": {
          "type": "integer",
          "description": "Overrides the file default for every step in this scope."
        },
        "timeout": {
          "type": "number",
          "description": "Seconds, per step in this scope."
        },
        "retention": {
          "type": "string",
          "enum": [
            "everything",
            "outputs_only",
            "outputs_and_final_models",
            "final_chained_group"
          ],
          "description": "What the steps of this scope keep. Absent inherits the file value."
        },
        "output_variables": {
          "type": "string",
          "description": "A variable-list file or Table name, scope level."
        },
        "window": {
          "type": "object",
          "description": "Scope-level payoff time window (start/stop/dt), the group window of the legacy shape. Not a simulation window: sim_specs is not valid on an optimization scope."
        },
        "engine": {
          "type": "string",
          "description": "The engine every step in this scope runs on, overriding the file default. One section runs on one engine."
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Display list for every step in this scope. Does not scope a real run. Absent inherits the document value."
        },
        "calibration_timeout": {
          "type": "number",
          "description": "Seconds before an optimize Run is killed and retried, for every step in this scope. Overrides timeout for optimize Runs. Absent inherits the document value."
        },
        "datasets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DatasetAxisEntry"
          },
          "description": "The dataset axis for every step in this scope. Absent inherits the document's datasets: list."
        },
        "output_increment": {
          "type": "boolean",
          "description": "Output increment for every step in this scope. Absent inherits the document value."
        },
        "runs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/OptimizationStepEntry"
          },
          "description": "The ordered optimize steps of this scope."
        }
      },
      "additionalProperties": false,
      "description": "One optimizations: map value, a calibration scope (spec.CalibrationSequence)."
    },
    "SensiParameter": {
      "type": "object",
      "properties": {
        "distribution": {
          "type": "string",
          "description": "The sampling distribution.",
          "enum": [
            "normal",
            "uniform",
            "incremental",
            "log_normal",
            "adhoc",
            "beta",
            "exponential",
            "gamma",
            "logistic",
            "pareto",
            "triangular",
            "weibull"
          ]
        },
        "mean": {
          "type": "number",
          "description": "normal / log_normal / logistic only."
        },
        "std_dev": {
          "type": "number",
          "description": "normal / log_normal only."
        },
        "min": {
          "type": "number",
          "description": "Every distribution but adhoc. Required for log_normal."
        },
        "max": {
          "type": "number",
          "description": "Every distribution but adhoc. Required for log_normal."
        },
        "seed": {
          "type": "integer",
          "description": "A fixed random seed, when the distribution samples."
        },
        "num_samples": {
          "type": "integer",
          "description": "How many samples this parameter contributes."
        },
        "starting_value": {
          "type": "number",
          "description": "incremental only."
        },
        "ending_value": {
          "type": "number",
          "description": "incremental only."
        },
        "values": {
          "type": "string",
          "description": "adhoc only: a comma-separated literal value list, carried verbatim."
        },
        "alpha": {
          "type": "number",
          "description": "beta only."
        },
        "beta": {
          "type": "number",
          "description": "beta only."
        },
        "lambda": {
          "type": "number",
          "description": "exponential only."
        },
        "shape": {
          "type": "number",
          "description": "gamma / pareto / weibull only."
        },
        "scale": {
          "type": "number",
          "description": "gamma / logistic / pareto / weibull only."
        },
        "lower": {
          "type": "number",
          "description": "triangular only."
        },
        "mode": {
          "type": "number",
          "description": "triangular only."
        },
        "upper": {
          "type": "number",
          "description": "triangular only."
        }
      },
      "additionalProperties": false,
      "required": [
        "distribution"
      ],
      "description": "One row of a sensitivities: <entry>: parameters: table, keyed by variable name (spec.SensiParameter, wraps model_index.SensiVariable)."
    },
    "SensitivityEntry": {
      "type": "object",
      "properties": {
        "method": {
          "type": "string",
          "description": "The sampling method. external is legal only beside path.",
          "enum": [
            "multivariate",
            "sobol_sequence",
            "latin_hypercube",
            "grid",
            "sequential",
            "external"
          ]
        },
        "runs": {
          "type": [
            "number",
            "string"
          ],
          "description": "Sample count. Omitted for grid and sequential, which take no run count."
        },
        "seed": {
          "type": [
            "number",
            "string"
          ],
          "description": "A fixed random seed for the whole routine."
        },
        "clear_database": {
          "type": "boolean",
          "description": "Marks this routine's run copy for a fresh .isdb before the run."
        },
        "parameters": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/SensiParameter"
          },
          "description": "The Sensitivity Parameters table, keyed by variable name."
        },
        "threshold": {
          "$ref": "#/$defs/Threshold",
          "description": "Setup Criteria's Grounded Sensitivity Criteria for one payoff."
        },
        "using_optimization": {
          "type": "string",
          "description": "Run this optimization spec on every sensitivity draw (Setup Criteria's \"Optimization to run\"). Written before method on Stella's own save."
        },
        "path": {
          "type": "string",
          "description": "From External Parameter File: a model-relative, r-prefixed path (for example r../ExtParams.csv). Sets the routine's effective method to external and drops its own parameters on write."
        },
        "saltelli": {
          "$ref": "#/$defs/Saltelli",
          "description": "A Saltelli design for Sobol indices. The routine then runs base_samples times (parameters + 2) simulations. Experimenter engine only."
        }
      },
      "additionalProperties": false,
      "description": "One sensitivities: map value, a named routine's settings (spec.SensitivitySpec)."
    },
    "Threshold": {
      "type": "object",
      "properties": {
        "payoff": {
          "type": "string",
          "description": "The payoff spec this Grounded Sensitivity Criteria threshold applies to."
        },
        "value": {
          "type": [
            "number",
            "string"
          ],
          "description": "The Threshold field of Setup Criteria (isee:threshold val). A number, or a numeric string like multiplier."
        },
        "recompute": {
          "type": "boolean",
          "description": "Relative to base (isee:threshold recompute). Written as the literal true or false."
        },
        "multiplier": {
          "type": [
            "number",
            "string"
          ],
          "description": "Adjust factor (isee:threshold sensi_parm_mult). Present only while Adjust sensi parameters is checked. The empty string clears an existing sensi_parm_mult, which unchecks Adjust sensi parameters. Omitting the key leaves the attribute in the model as it is."
        },
        "remove": {
          "type": "boolean",
          "description": "Deletes the whole isee:threshold element of this payoff and ignores every other field on this block. It is the file form of unchecking the box of this payoff in the Setup Criteria dialog of Stella."
        }
      },
      "additionalProperties": false,
      "required": [
        "payoff"
      ],
      "description": "sensitivities.<name>.threshold's own block (spec.ThresholdSpec)."
    },
    "Saltelli": {
      "type": "object",
      "properties": {
        "base_samples": {
          "type": "integer",
          "description": "The base sample count: a power of 2 from 2 to 1048576. With k parameters the routine runs base_samples x (k+2) simulations. The design is a Sobol sequence, so it takes no seed."
        }
      },
      "additionalProperties": false,
      "required": [
        "base_samples"
      ],
      "description": "sensitivities.<name>.saltelli's own block (spec.SaltelliSpec)."
    },
    "Stage": {
      "type": "object",
      "properties": {
        "stage": {
          "type": "string",
          "description": "A sibling id in this document's runs: or optimizations: section (one flat namespace across both)."
        },
        "level": {
          "type": "integer",
          "description": "Sequence outline depth. 0, or an absent key, starts from the Template."
        },
        "active": {
          "type": "boolean",
          "description": "Default true. false skips this member entirely."
        },
        "export": {
          "type": "boolean",
          "description": "Default true. false still runs this member; only collation is skipped."
        },
        "retention": {
          "type": "string",
          "enum": [
            "everything",
            "outputs_only",
            "outputs_and_final_models",
            "final_chained_group"
          ],
          "description": "What this stage keeps when the Sequence ends. Absent inherits its Run or group, then the Sequence."
        }
      },
      "additionalProperties": false,
      "required": [
        "stage"
      ],
      "description": "One sequences: <entry> list item that references a sibling (spec.StageRef, Experiment form)."
    },
    "SequenceMember": {
      "description": "One sequences: <entry> list item: a stage reference, or an inline Script.",
      "oneOf": [
        {
          "$ref": "#/$defs/Stage"
        },
        {
          "$ref": "#/$defs/Script"
        }
      ]
    },
    "LaneDataItem": {
      "type": "object",
      "properties": {
        "file": {
          "type": "string",
          "description": "A bare file name, with no path separator. It names an import of the model or of a stage."
        },
        "overrides": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Override"
          },
          "description": "Cell edits for this file, layered over the entries of each stage. The lane wins a cell the stage also sets, and a workbook takes none."
        }
      },
      "additionalProperties": false,
      "required": [
        "file",
        "overrides"
      ],
      "description": "One cell-override item of a Sequence lane's data: list (spec mb2-0034)."
    },
    "DatasetAxisEntry": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The dataset's label, names the Run-folder subtree it writes into."
        },
        "base": {
          "type": "string",
          "description": "The directory (relative to this document) this dataset's data: files resolve from. A Sequence lane that sets data: needs none."
        },
        "active": {
          "type": "boolean",
          "description": "Default true. false deactivates this dataset (no Run, no output folder)."
        },
        "data": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LaneDataItem"
          },
          "description": "Cell overrides this lane layers over every stage. Valid only on a Sequence lane (a groups: entry or a sequences: <entry> datasets: entry). A lane with no base then reads the files of the base group."
        },
        "before": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Script"
          },
          "description": "Runs once before this dataset's lane starts. A top-level datasets: entry only. On a Sequence groups: entry it is an error."
        },
        "after": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Script"
          },
          "description": "Runs once after this dataset's lane finishes. A top-level datasets: entry only. On a Sequence groups: entry it is an error."
        }
      },
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "description": "One dataset of a dataset axis (spec.DatasetAxisEntry), a top-level datasets: entry, or a sequences: <entry>: groups: entry. before/after validate structurally here though a groups: entry rejects them."
    },
    "DatasetListEntry": {
      "type": "object",
      "properties": {
        "list": {
          "type": "string",
          "description": "A plain-text file, relative to this document: one dataset path per line, blank and '#'-prefixed lines skipped. Each remaining line resolves relative to the list file's own folder (not this document's) when not already absolute, and expands to one dataset group per line. Each load reads the file fresh, so a wrapping script's regenerated list is picked up on the next open or run. A listed path need not exist yet at load time; it is checked like any other group's base once the sequence is validated."
        },
        "active": {
          "type": "boolean",
          "description": "Default true. false deactivates every group this list expands to, in one step."
        }
      },
      "additionalProperties": false,
      "description": "A sequences: <entry>: groups: entry sourced from a text file of paths, instead of a single hand-written {name, base}."
    },
    "SequenceEntry": {
      "description": "One sequences: map value: a bare stage list, or a mapping with {stages, include_base, enabled, groups, output_folder, output_name, engine, retries, timeout, retention, output_variables, outputs, calibration_timeout, datasets, output_increment} when a dataset axis, an output override or a section setting is present. Only stages is required.",
      "oneOf": [
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/SequenceMember"
          },
          "description": "The common shape: an ordered stage/Script list."
        },
        {
          "type": "object",
          "properties": {
            "stages": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SequenceMember"
              }
            },
            "include_base": {
              "type": "boolean",
              "description": "Whether the base dataset group runs. Default true. false runs only the added groups."
            },
            "enabled": {
              "type": "boolean",
              "description": "Whether Run Enabled Sequences runs this Sequence. Default true. Written only when false."
            },
            "groups": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "$ref": "#/$defs/DatasetAxisEntry"
                  },
                  {
                    "$ref": "#/$defs/DatasetListEntry"
                  }
                ]
              },
              "description": "Added dataset groups: a hand-written {name, base} folder, or a {list: <path>} text-file reference that expands to one group per usable line. The base group (this document's own configured inputs) is always present and implicit, never listed here."
            },
            "output_folder": {
              "type": "string",
              "description": "This Sequence's own output root, overriding the Output File Location preference for this Sequence only. Absolute wins outright; a relative name resolves under the model folder. Absent inherits the preference."
            },
            "output_name": {
              "type": "string",
              "description": "This Sequence's own collated CSV name, overriding the Output File Name preference for this Sequence only. Absent inherits the preference, default 'Output.csv'."
            },
            "engine": {
              "type": "string",
              "description": "The engine every stage of this Sequence runs on. Inside this Sequence only, it overrides the engine of the Run, Group or Optimization entry that each stage names, and writes nothing to them. Absent, each stage runs on the engine of its own section, then on the document engine. A stage carries no engine: key."
            },
            "retries": {
              "type": "integer",
              "description": "How many times a failed Run is retried, for every stage of this Sequence whose own section sets none."
            },
            "timeout": {
              "type": "number",
              "description": "Seconds before a Run is killed and retried, for every stage of this Sequence whose own section sets none."
            },
            "retention": {
              "type": "string",
              "enum": [
                "everything",
                "outputs_only",
                "outputs_and_final_models",
                "final_chained_group"
              ],
              "description": "What the stages of this Sequence keep. Absent inherits the file value."
            },
            "output_variables": {
              "type": "string",
              "description": "A variable-list file or Table name scoping collected output, for every stage of this Sequence whose own section sets none."
            },
            "outputs": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "description": "Display list for every stage of this Sequence whose own section sets none. Does not scope a real run. Absent inherits the document value."
            },
            "calibration_timeout": {
              "type": "number",
              "description": "Seconds before an optimize Run is killed and retried, for every stage of this Sequence whose own section sets none. Overrides timeout for optimize Runs. Absent inherits the document value."
            },
            "datasets": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/DatasetAxisEntry"
              },
              "description": "The dataset axis for every stage of this Sequence whose own section sets none. Absent inherits the document's datasets: list."
            },
            "output_increment": {
              "type": "boolean",
              "description": "Output increment for every stage of this Sequence whose own section sets none. Absent inherits the document value."
            }
          },
          "additionalProperties": false,
          "required": [
            "stages"
          ]
        }
      ]
    }
  }
}
