calliope-project / calliope

A multi-scale energy systems modelling framework
https://www.callio.pe
Apache License 2.0
277 stars 89 forks source link

Cannot use IDE schema validator with Calliope model YAML files #558

Open irm-codebase opened 5 months ago

irm-codebase commented 5 months ago

What happened?

The YAML schema is missing a couple of things that cause standard configurations to return linting errors. I am using the YAML support plugin for VSCode, but this should apply to any other schema-based linter.

I'll be adding the bugs to this list. Here are the ones I've found so far:

  1. import is not defined in the schema, causing it to return an error when using the command.

Which operating systems have you used?

Version

v0.7.0

Relevant log output

Errors returned:
1. `Property import is not allowed. yaml-schema: Model configuration schema`
brynpickering commented 5 months ago

The import key is removed from the dictionary after resolving its contents and before the model definition reaches the schema validator. This means that standard VSCode schema validator won't work well.

In fact, the way we allow a. relative file imports, b. applications of overrides, and c. loading tabular data, means that IDE schema validators are likely to complain frequently. For instance, the schema requires a technology to define a parent, but you could define the following two YAML files:

file1.yaml

  techs:
    tech1:
      parent: supply

file2.yaml

  techs:
    tech1:
      flow_cap_max: 10

And merge them together with import in model.yaml:

import:
  - file1.yaml
  - file2.yaml

Your IDE linter will complain that there is no parent defined in file2.yaml. However, this is perfectly valid for Calliope.

Similarly, the schema checks that cost_... parameters have defined costs as one of the dims. But you could define this in tech_groups and it would be valid for Calliope:

tech_groups:
  foo: 
    cost_flow_cap:
      data: null
      index: monetary
      dims: costs
techs:
  bar:
    inherit: foo
    cost_flow_cap.data: 1  # the IDE linter will complain.