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

BUG- Error when using the Taipy data generated from another __main__ #1174

Open
FlorianJacta opened this issue Apr 12, 2024 · 1 comment
Open
Labels
Core Related to Taipy Core 💥Malfunction Addresses an identified problem. 🟨 Priority: Medium Not blocking but should be addressed

Comments

@FlorianJacta
Copy link
Member

FlorianJacta commented Apr 12, 2024

Description
An error is created when I am trying to use Taipy SDM (Scenario and Data Management) from another script. The issue only arises when my tasks use functions inside my main.py (main).

How to reproduce
main.py

This is working fine:

from taipy import Config
import taipy as tp
import pandas as pd
import datetime as dt


data = pd.read_csv("https://raw.githubusercontent.com/Avaiga/taipy-getting-started-core/develop/src/daily-min-temperatures.csv")


# Normal function used by Taipy
def predict(historical_temperature: pd.DataFrame, date_to_forecast: dt.datetime) -> float:
    print(f"Running baseline...")
    historical_temperature['Date'] = pd.to_datetime(historical_temperature['Date'])
    historical_same_day = historical_temperature.loc[
        (historical_temperature['Date'].dt.day == date_to_forecast.day) &
        (historical_temperature['Date'].dt.month == date_to_forecast.month)
    ]
    return historical_same_day['Temp'].mean()

# Configuration of Data Nodes
historical_temperature_cfg = Config.configure_data_node("historical_temperature")
date_to_forecast_cfg = Config.configure_data_node("date_to_forecast")
predictions_cfg = Config.configure_data_node("predictions")

# Configuration of tasks
predictions_cfg = Config.configure_task("predict",
                                        predict,
                                        [historical_temperature_cfg, date_to_forecast_cfg],
                                        predictions_cfg)

# Configuration of scenario
scenario_cfg = Config.configure_scenario(id="my_scenario", task_configs=[predictions_cfg])

Config.export('config.toml')

if __name__ == '__main__':
    # Run of the Core
    tp.Core().run()

    # Creation of the scenario and execution
    scenario = tp.create_scenario(scenario_cfg)
    scenario.historical_temperature.write(data)
    scenario.date_to_forecast.write(dt.datetime.now())
    tp.submit(scenario)

test.py:

This throws an error.

import taipy as tp

if __name__ == '__main__':
    # Creation of the scenario and execution
    scenario = tp.get_scenarios()[0]
    print(scenario.date_to_forecast.read())

Error:
image (11)

Expected behavior
At a minimum, better logs should appear.

Runtime environment
Please specify relevant indications.

  • Taipy: 3.1.1
@FlorianJacta FlorianJacta added Core Related to Taipy Core 💥Malfunction Addresses an identified problem. 🟨 Priority: Medium Not blocking but should be addressed labels Apr 12, 2024
@jrobinAV
Copy link
Member

Indeed, the internal Taipy data (.taipy folder) is not designed to be shared across multiple applications (multiple main scripts).
The data stores some user code locations relative to the main script. Switching from one application to another is not guaranteed to work properly. This would depend on where the user code is located and how it is imported and declared to Taipy objects.

I keep the ticket open to investigate if we can do something to make it work in more cases or at least to document the use cases that don't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to Taipy Core 💥Malfunction Addresses an identified problem. 🟨 Priority: Medium Not blocking but should be addressed
Projects
None yet
Development

No branches or pull requests

2 participants