flexmeasures icon indicating copy to clipboard operation
flexmeasures copied to clipboard

Scheduler computes per-commodity costs but never exports them (job meta only gets flat commitment_costs)

Open Flix6x opened this issue 3 months ago • 1 comments

What happens

Both scheduler backends compute a per-commodity cost breakdown at the end of solving:

  • flexmeasures/data/models/planning/linear_optimization.py:815 — model.commodity_costs = aggregate_commodity_costs(...)
  • flexmeasures/data/models/planning/highspy_optimization.py:748 — same

But nothing downstream ever reads it:

  • StorageScheduler only reports the flat per-commitment breakdown (report_commitment_costs_by_name, flexmeasures/data/models/planning/storage.py around line 3506, under the result name "commitment_costs").
  • The job handler only persists that one key into job meta: flexmeasures/data/services/scheduling.py:846 → rq_job.meta["scheduler_info"]["commitment_costs"].

grep -rn commodity_costs flexmeasures/ --include=*.py shows no consumer outside the planning modules.

Why it matters

With multi-commodity flex-contexts now first-class (commodity contexts, balance groups, coupled converter devices), "what did the heat side cost vs the electricity side" is a natural question for anything consuming scheduling results (API clients, plugins, UI). The scheduler already answers it — the answer is just dropped on the floor. Anyone wanting a per-commodity view today has to re-derive it by parsing commitment names.

Suggested fix

Have StorageScheduler emit a second result entry (e.g. name "commodity_costs", same shape as the commitment costs entry) and persist it next to commitment_costs in scheduler_info, guarded so single-commodity schedules don't gain noise (skip when there is only the default commodity). Small, backwards-compatible change; happy to PR it.

Flix6x avatar Aug 08 '26 04:08 Flix6x

Working on this: emitting commodity_costs in StorageScheduler outputs and persisting it in job.meta["scheduler_info"]["commodity_costs"] for multi-commodity schedules with unit test coverage.

taran-dev4u avatar Aug 31 '26 05:08 taran-dev4u