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 6 commits into from Jun 19, 2023


Copy link

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/", 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/

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 <>
… decimal resolution

Signed-off-by: Victor Garcia Reolid <>
@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 <>
@Flix6x Flix6x added this to the 0.14.1 milestone Jun 16, 2023
Signed-off-by: F.N. Claessen <>
Signed-off-by: F.N. Claessen <>
Signed-off-by: F.N. Claessen <>
Copy link

@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.


@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 <>

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

Signed-off-by: Victor Garcia Reolid <>

* fix: add self.round_to_decimals to create_constraint_violations_message

Signed-off-by: Victor Garcia Reolid <>

* fix: fix and modernize type annotations

Signed-off-by: F.N. Claessen <>

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

Signed-off-by: F.N. Claessen <>

* docs: changelog entry

Signed-off-by: F.N. Claessen <>


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

Successfully merging this pull request may close these issues.

None yet

2 participants