Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce consistency in objective dimensions #580

Closed
wants to merge 8 commits into from

Conversation

tsmbland
Copy link
Collaborator

@tsmbland tsmbland commented Nov 27, 2024

Description

See #581 for a description of the problem.

This PR enforces that all objectives must have an asset dimension. I've added these checks in the decorator, and modified the "comfort", "efficiency", "capital_costs" and "ALCOE" objectives accordingly, adding an asset dimension by broadcasting. The tests also needed updating.

Now, all objectives are consistent in the dimensions they return, apart from some of them which also return a timeslice dimension. However, this ends up being compressed by this line:

costs = timeslice_op(costs)

So now ultimately by the time the objectives reach the solver the dimensions are always the same: asset and replacement.

This seems to fix the problems described in the issue (see case study below), although I haven't really figured out why. I think it's to do with the scipy adapter (_unified_dataset and lp_constraint and lp_constraint_matrix functions), although the code is so unreadable it's hard to figure out what's going on. I'm not sure it matters though for now, as long as the issue is fixed.

To help enforce dimensions, I've created the check_dimensions helper function. This is checking both the inputs and outputs of the objectives. I think this is something that could be used in several other places throughout the code, but I'll look into this separately.

I've suppressed two tests that were failing. I haven't fully understood why these are failing, but they're both do do with noninvesting agents which will no longer calculate objectives in v1.3 (#554), so I'm not too fussed about it.

Case study

I've taken the default model and changed the objective to "capital_costs". I've also increased the capital costs of gasboiler 10x to 30, so the expected outcome is clear - it should invest in heatpumps in the residential sector

Scenario 1: original code, single objective (capital costs)

The solver fails to find a solution. This is strange as changing the objective is only supposed to change the costs vector, which shouldn't effect whether or not a solution is possible (this is all determined by the constraints)

Scenario 2: original code, adding a dummy second objective (LCOE, 0.01 weight)

Now the model runs to completion and the results are in line with expectations.

Capacity_Original_MultiObjective

I think this works because when the objectives are combined, the asset dimension from LCOE gets picked up in the overall combined objective.

Scenario 3: new code, single objective (capital costs)

Now we get the expected result, even without adding a dummy objective

Capacity_New_Capital

Fixes #581

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass: $ python -m pytest
  • The documentation builds and looks OK: $ python -m sphinx -b html docs docs/build

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@tsmbland tsmbland changed the title Enforce that all objectives have an asset dimension Enforce consistency in objective dimensions Nov 28, 2024
@tsmbland tsmbland marked this pull request as ready for review November 28, 2024 16:36
@tsmbland tsmbland marked this pull request as draft November 28, 2024 16:37
@tsmbland tsmbland marked this pull request as ready for review November 28, 2024 17:56
@tsmbland tsmbland requested a review from dalonsoa November 28, 2024 17:59
@tsmbland
Copy link
Collaborator Author

Actually don't review this, I've opened up #584 instead which is pretty much the same but based on the v1.3 branch which means the tests no longer fail

@tsmbland tsmbland closed this Nov 28, 2024
@tsmbland tsmbland deleted the objective_dimensions branch November 28, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUG] Odd results for objectives that don't return an asset dimension
1 participant