Skip to content

feat: KDL syntax improvements for clarity and consistency #176

@pesap

Description

@pesap

Problem Statement

The current Arco KDL syntax has terminology inconsistencies and ambiguities that confuse users:

  1. map keyword — reads as "mapping to a set" but actually renames a CSV column
  2. alias overloaded — used for both data column aliases and set shorthand
  3. control keyword — optimization users expect var or variable
  4. filter keywordwhere is more familiar (SQL, Python)
  5. Bound syntax — no clear pattern for indexed bounds (e.g., upper=capacity[g])

Solution

Rename keywords for clarity while maintaining backwards compatibility where feasible:

Before After Purpose
map X from="col" alias X column="col" Data column rename
set X alias=g set X as=g Set shorthand
control x lower=0 var x lower=0 Decision variable
filter { cond } where { cond } Set subsetting

Additional syntax clarifications:

  • Indexed bounds: upper { capacity[g] } / lower { expr } inside var block
  • Path resolution: relative to KDL file, overridable via --data-dir or ARCO_DATA_DIR

Implementation Decisions

Parser Changes

  • Add alias as new keyword; deprecate map (warn on use, still parse)
  • Add as= property on set; deprecate alias= property
  • Add var as new keyword; deprecate control (warn on use, still parse)
  • Add where as new keyword; deprecate filter
  • Parse lower { expr } / upper { expr } as child nodes in var blocks

Path Resolution

  • Resolve from="..." paths relative to the input KDL file location
  • --data-dir CLI flag overrides (highest priority)
  • ARCO_DATA_DIR env var as fallback
  • Document resolution order in help/docs

Backwards Compatibility

  • control, map, set alias=, filter continue to parse with deprecation warnings
  • Deprecation warnings include migration hint (e.g., "use var instead of control")

Testing Decisions

  • Unit tests: Parser accepts both old and new syntax; emits correct AST
  • Deprecation tests: Old keywords trigger warnings with correct messages
  • Path resolution tests: Verify relative, --data-dir, and ARCO_DATA_DIR precedence
  • Integration test: Update examples/nodal-allocation/input.kdl to new syntax; verify model runs

Out of Scope

  • Multi-objective optimization syntax
  • Model linking/composition semantics
  • Hierarchical optimization (see ADR-0001)

References

  • CONTEXT.md — domain language
  • docs/adr/0001-objective-composition-deferred.md — deferred decisions
  • examples/nodal-allocation/input.kdl — example to migrate

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions