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

Refactor scheduler interface - API and inner logic #537

Merged
merged 44 commits into from
Dec 29, 2022

Conversation

nhoening
Copy link
Contributor

@nhoening nhoening commented Nov 23, 2022

  • Add flex_model & flex_context in API endpoint
  • refactor design for Scheduler implementations (moving some endpoint logic here, scheduler is responsible for deciding which flex_model is to be used / validated)

TODO:

  • Error handling of validation errors within endpoint (->422)
  • Docs pages which explain flex_model(s) and flex_context. Also link to there from endpoint docs and plugin developer docs
  • Has soc-sensor-id ever been used at all?
  • Adapt CLI data_addand tutorial to use make_schedule and create_scheduling_job in the new way.
  • Also add deprecation logic for flex_context params
  • Changelog entry
  • Try to not use underscore notation in API parameters, as "-" is more user-friendly to read.

…heduler implementations (moving some endpoint logic here);

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@coveralls
Copy link
Collaborator

coveralls commented Nov 23, 2022

Pull Request Test Coverage Report for Build 3799875511

  • 280 of 325 (86.15%) changed or added relevant lines in 13 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.5%) to 65.59%

Changes Missing Coverage Covered Lines Changed/Added Lines %
flexmeasures/data/services/scheduling.py 24 25 96.0%
flexmeasures/api/common/utils/deprecation_utils.py 19 22 86.36%
flexmeasures/api/v1_3/implementations.py 13 17 76.47%
flexmeasures/cli/utils.py 7 12 58.33%
flexmeasures/data/models/planning/init.py 44 49 89.8%
flexmeasures/api/v3_0/sensors.py 41 48 85.42%
flexmeasures/data/models/planning/storage.py 83 92 90.22%
flexmeasures/cli/data_add.py 7 18 38.89%
Files with Coverage Reduction New Missed Lines %
flexmeasures/data/models/planning/init.py 1 86.15%
flexmeasures/cli/data_add.py 2 32.26%
Totals Coverage Status
Change from base Build 3743385027: 0.5%
Covered Lines: 6841
Relevant Lines: 9802

💛 - Coveralls

@nhoening nhoening added this to the 0.12.0 milestone Nov 23, 2022
@nhoening nhoening added documentation Improvements or additions to documentation API Scheduling CLI labels Nov 23, 2022
@nhoening nhoening self-assigned this Nov 23, 2022
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…f params with underscore in docstring

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…e endpoint

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
… in dummy custom scheduler

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…es in v3.0 as well, using a way that lets all schedulers save (parts of) it if they want.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…re we apply the schema (which expects non-nan values here)

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…mall refactoring to save lines

Signed-off-by: Nicolas Höning <nicolas@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.

Impressive work so far. Here are some documentation suggestions already.

documentation/api/notation.rst Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
flexmeasures/data/models/planning/__init__.py Outdated Show resolved Hide resolved
flexmeasures/data/services/scheduling.py Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
documentation/api/notation.rst Outdated Show resolved Hide resolved
…e might choose that the CLI will be specific to our in-built flex models)

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
… to small fix in API endpoint and scheduling tests

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening
Copy link
Contributor Author

For me, only one item remains in this PR: I chose for underscores in the flex model and flex context parameter names to the API, but I now believe I could give users the "-" notation which we have used before as well.

…the API to use hyphens, which is conventionally preferred.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening requested a review from Flix6x December 25, 2022 23:25
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…s/flexmeasures into refactor-scheduler-interface
@Flix6x
Copy link
Contributor

Flix6x commented Dec 26, 2022

I noticed some unaddressed review comments, some of which may be worthwhile to discuss, like #537 (comment).

@nhoening
Copy link
Contributor Author

Oh yes, that one did escape, thanks for reminding.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
nhoening and others added 4 commits December 27, 2022 18:07
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…context (#564)

* Add deprecation and sunset response headers when deprecated fields are used

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

* Refactor: duplicate code becomes util function

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

* Correct deprecation and sunset links

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

* rename to represent plural-default of param, update link to 3.0.5 API changelog

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
… from soc targets

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening requested a review from Flix6x December 28, 2022 15:22
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.

Well done! I only added some comments for a potential function rename and opening up a new issue to advance our use of Marshmallow.

"soc_in_mwh", self.flex_model["soc_at_start"]
)

def inspect_flex_config(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just a note for later: we use a Marshmallow schema in this function, which by now does not only do validation, but also deserialization (which is what changes the flex config fields with dash notation to the flex config variables with underscore notation). This is already disclosed in the docstring, but I believe the function name could bring that to light better, because it's more than an inspection at this point. Maybe deserialize_flex_config. The function also fills in defaults (if needed), but this can be done in the schema, too, using load_default.

flexmeasures/data/models/planning/storage.py Outdated Show resolved Hide resolved
Ideas:
- Apply a schema to check validity (see in-built flex model schemas)
- Check for inconsistencies between settings (can also happen in Marshmallow)
- fill in missing values from the scheduler's knowledge (e.g. sensor attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: I found out how to access the sensor object (deserialized from location="path") in the schema used for deserializing fields from location="json" (using https://webargs.readthedocs.io/en/latest/advanced.html#meta-locations). Knowing this, filling in missing values can also happen using Marshmallow, e.g. using @validates(field_name) or @validates_schema. So all three of these ideas can happen in Marshmallow, which may be worth a note and/or a follow-up ticket.

Btw, I started using these meta-locations in #563, so I know how to make that work now.

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
… planning module without needing plugin developers to upgrade their code)

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
@Flix6x Flix6x merged commit 60e3ec3 into main Dec 29, 2022
@Flix6x Flix6x deleted the refactor-scheduler-interface branch December 29, 2022 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API CLI documentation Improvements or additions to documentation Scheduling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants