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

fix: relax decimal resolution in constraint validation #731

Merged
merged 6 commits into from Jun 19, 2023

Conversation

victorgarcia98
Copy link
Contributor

This PR fixes the following bug fix request by @Flix6x:


I have the below bug fix request for 0.14.1. Would you have time to take it up?

File "/home/felix/PycharmProjects/flexmeasures/flexmeasures/data/models/planning/storage.py", line 191, in compute
    raise ValueError("The input data yields an infeasible problem.")

I'm also seeing this error in production. I'll probably reinstall fm==0.13.3 for now.

On inspection, line 191 has a comment preceding it with a todo. Let's first implement the todo. Secondly, upon printing the constraint_violations, I get (locally):

[{'dt': datetime.datetime(2023, 5, 1, 21, 45, tzinfo=<UTC>), 'condition': 'equals(t) <= max(t)', 'violation': 'equals(t) [1.6500000000000004]<=max(t) [1.65]'}]

This leads me to believe we should relax the constraint validation by some margin. Perhaps the default margin should correspond to the margin we use for rounding schedules:

See the Scheduler class In data/models/planning/init.py:

round_to_decimals: Optional[int] = 6,


The workaround is to split the LHS, RHS and inequality sign into different arguments arguments of the validate_constraint function. Then, use that to evaluate each expressions, rounding it.

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
… decimal resolution

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
@victorgarcia98 victorgarcia98 added bug Something isn't working Scheduling labels Jun 16, 2023
@victorgarcia98 victorgarcia98 self-assigned this Jun 16, 2023
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
@Flix6x Flix6x added this to the 0.14.1 milestone Jun 16, 2023
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Copy link
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@victorgarcia98 victorgarcia98 merged commit b4b3b1b into main Jun 19, 2023
6 of 7 checks passed
@victorgarcia98 victorgarcia98 deleted the bug/relax-constraint-validation branch June 19, 2023 08:08
Flix6x added a commit that referenced this pull request Jun 26, 2023
…ion (#731)

* fix: consider decimal precision when validating equality constraints

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* test: add test cases to check for the equality validation considering decimal resolution

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix: add self.round_to_decimals to create_constraint_violations_message

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix: fix and modernize type annotations

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix(docs): update docstring with split and new parameters

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Scheduling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants