Skip to content

Conversation

@BelhsanHmida
Copy link
Contributor

@BelhsanHmida BelhsanHmida commented Nov 19, 2025

Description

This pr aims to complete the return values of the TrainPredictPipeline.compute()

  • Fixes the issue where TrainPredictPipeline.compute() always returned an empty list.
  • Implementing return values:
    • When as_job = False, the pipeline now returns the computed forecast results. in format:
   {
       "data": <BeliefsDataFrame of forecasts>,
       "sensor": <Sensor object the forecasts are stored on>
   }
  • When as_job = True, the pipeline returns a list of job IDs ["job-1": , "job-2": ].
[
    {"job-1": <job_id_1>},
    {"job-2": <job_id_2>},
    ...
]

CLI improvements:

  • The flexmeasures add forecasts command now reports detailed success messages.
  • When --as-job is set, it shows the number of forecast jobs created.
  • When forecasts are computed directly, it shows the number of forecast beliefs and unique belief times created.
  • If no forecasts or jobs are created, an error message is displayed instead of a generic success message.

How to test:

You can now run:
pytest flexmeasures/data/tests/test_train_predict_pipeline.py .

I added assertions to validate the return values of the pipelines, so the tests now cover both the as_job=False and as_job=True cases.

Related Items

closes #1811
...


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ensorAPI if model passed in as field in api call

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
… created

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…edictPipeline

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…Pipeline

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ictPipeline

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ictPipeline

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…eline

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…es in TrainPredictPipeline

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@read-the-docs-community
Copy link

read-the-docs-community bot commented Nov 19, 2025

Documentation build overview

📚 flexmeasures | 🛠️ Build #30593621 | 📁 Comparing d3638be against latest (235fe60)


🔍 Preview build

Show files changed (3 files in total): 📝 3 modified | ➕ 0 added | ➖ 0 deleted
File Status
changelog.html 📝 modified
_autosummary/flexmeasures.data.models.forecasting.pipelines.predict.html 📝 modified
api/v3_0.html 📝 modified

…is to fix error when running forecaster data generator it returns only job id's when ran as_job as forecasts haven't been generated yet.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ning as job

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida self-assigned this Nov 19, 2025
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
…tion. to do will be simplified

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #1811 by implementing meaningful return values for the TrainPredictPipeline.compute() method, which previously always returned an empty list. The changes introduce different return formats based on execution mode: forecast data with sensor information for synchronous execution (as_job=False), and job IDs for asynchronous execution (as_job=True).

Key changes:

  • Added return_values instance variable to collect and return results from pipeline execution
  • Modified run_cycle() to append forecast data and sensor information to return values
  • Updated run() method to return job IDs when executing asynchronously
  • Extended test assertions to validate the return value structure and content

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
flexmeasures/data/models/forecasting/pipelines/train_predict.py Implements return value collection and handling for both synchronous and asynchronous execution modes
flexmeasures/data/models/forecasting/pipelines/predict.py Returns the BeliefsDataFrame from the predict pipeline run
flexmeasures/data/models/forecasting/init.py Conditionally skips event resolution validation when running as job
flexmeasures/data/models/data_sources.py Conditionally skips sensor and source assignment when running as job
flexmeasures/data/tests/test_train_predict_pipeline.py Adds comprehensive assertions to validate return values for both execution modes
flexmeasures/api/v3_0/sensors.py Removes extra blank line (whitespace cleanup)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
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.

Very nice. I believe I only have rather small suggestions.

@Flix6x
Copy link
Contributor

Flix6x commented Dec 5, 2025

One more note: if the response message in the forecasting CLI command incorporates this new feature, then this PR by itself also becomes a user-facing feature. And it's useful to consider that when writing the changelog entry (i.e. from a user perspective, how does this PR help them).

@Flix6x Flix6x added this to the 0.31.0 milestone Dec 5, 2025
BelhsanHmida and others added 7 commits December 5, 2025 16:18
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…error

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…peline test

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
- Reports number of forecast jobs created when --as-job is used
- Reports number of forecast beliefs and unique belief times for direct computation
- Displays error message if no forecasts or jobs were create

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ature and cli response update

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida
Copy link
Contributor Author

One more note: if the response message in the forecasting CLI command incorporates this new feature, then this PR by itself also becomes a user-facing feature. And it's useful to consider that when writing the changelog entry (i.e. from a user perspective, how does this PR help them).

Thanks for the review, i applied the suggestions and added the changelog entry.

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.

Thanks. Just the main changelog entry still.

…alues feature and cli response update"

This reverts commit c29c870.
… for `flexmeasures add forecasts` CLI command

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
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.

Just one small formatting issue. Feel free to merge afterwards.

BelhsanHmida and others added 3 commits December 6, 2025 17:38
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@Flix6x Flix6x merged commit 1089414 into main Dec 6, 2025
7 of 8 checks passed
@Flix6x Flix6x deleted the feat/complete-forecasting-pipeline-return branch December 6, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete forecasting pipeline return

3 participants