spine-tools / SpineOpt.jl

A highly adaptable modelling framework for multi-energy systems
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
49 stars 12 forks source link

Bug with reduced stochastic structures. #554

Open Tasqu opened 1 year ago

Tasqu commented 1 year ago

Mostly a TODO for myself, but if anyone else wants to tackle this, be my guest.

There seems to be a bug if providing a model with input data defining a branching stochastic structure. E.g. defining

parent_stochastic_scenario__child_stochastic_scenario:
realization -> {optimistic, mean, pessimistic}

but limiting the branching on the stochastic_structure__stochastic_scenario stage seems to result in a couple of issues, e.g.

stochastic_structure__stochastic_scenario:
deterministic -> {realization, mean}

Essentially, the structure is intended to use only the mean scenario forecast and discard the optimistic and pessimistic. At the moment, this seems to result in the following issues:

  1. Error when processing the stochastic structure in stochastic_structure.jl:149-151 when child_relative_weight is not defined for non-existing scenarios.
  2. Even if this is fixed, seems like the model comes out as infeasible or unbounded for some currently unknown reason.

Current workaround is to disable the unused stochastic_scenarios with the is_active feature.

mihlema commented 1 year ago

We could e.g. check for scenarios not used in the stochastic structure and filter them out in preprocessing. Also, I think at the moment each stochastic structure needs to be connected to each stochastic scenario, which can be tedious. We could hence first filter out scenarios that don't appear in any structure, and then add "half-missing" scenarios. That latter part is somewhat more tricky I believe, but it felt a bit odd to having to create a "deterministic" structure that has all the child scenarios.

Tasqu commented 1 year ago

There is actually some filtering in the code it attempts to do, but it doesn't seem to do a sufficiently thorough job to avoid errors.

Also, I think at the moment each stochastic structure needs to be connected to each stochastic scenario, which can be tedious. We could hence first filter out scenarios that don't appear in any structure, and then add "half-missing" scenarios. That latter part is somewhat more tricky I believe, but it felt a bit odd to having to create a "deterministic" structure that has all the child scenarios.

@mihlema I don't think this is true? (At least I've gotten this to work without this?) All stochastic scenarios need to be mentioned in the parent_stochastic_scenario__child_stochastic_scenario relationship (if they are to be used anywhere), but stochastic_structure__stochastic_scenario only needs to account for the ones it actually includes. However, at the moment with this filtering being a little unreliable, I there are cases where one needs to filter out unused stochastic scenarios with the is_active flag from the database.

clizbe commented 7 months ago

@Tasqu What's the current status of this? Is it still relevant / is it necessary / is it nice to have?

Tasqu commented 7 months ago

@clizbe I honestly had forgotten all about this 😅 It's probably still relevant, as I imagine no-one has happened to fix this by accident. I don't imagine I'll have the time and/or a reason to fix this in the near-term, though.