From 73ad49a35e97b85265e38979f8e65e41974332eb Mon Sep 17 00:00:00 2001 From: Juliette-Gerbaux Date: Wed, 11 Dec 2024 12:26:26 +0100 Subject: [PATCH] Run isort --- src/calculate_reward_and_bellman_values.py | 10 +++-- src/display.py | 5 ++- src/estimation.py | 6 ++- src/functions_iterative.py | 17 ++++---- src/hyperplane_decomposition.py | 1 + src/hyperplane_interpolation.py | 1 + src/launch_calculation.py | 6 +-- src/multi_stock_bellman_value_calculation.py | 39 +++++++++---------- src/optimization.py | 16 ++++---- src/read_antares_data.py | 5 ++- src/simple_bellman_value_calculation.py | 16 ++++---- src/type_definition.py | 5 ++- tests/test_basis.py | 17 ++++---- tests/test_bellman_value_exact.py | 14 +++---- tests/test_bellman_value_exact_two_stocks.py | 24 ++++++------ ...test_bellman_value_precalculated_reward.py | 9 +++-- ...n_value_precalculated_reward_two_stocks.py | 14 +++---- tests/test_fast_uv_two_stocks.py | 14 +++---- tests/test_iterative_two_stocks.py | 14 +++---- tests/test_itr_storage_values.py | 11 +++--- tests/test_optimization_problem_two_stock.py | 11 +++--- tests/test_overflow.py | 12 +++--- tests/test_read_optimization_problem.py | 11 +++--- tests/test_update_reward.py | 3 +- tests/test_upper_bound.py | 17 ++++---- 25 files changed, 149 insertions(+), 149 deletions(-) diff --git a/src/calculate_reward_and_bellman_values.py b/src/calculate_reward_and_bellman_values.py index 3b6b32f..f2a24c8 100644 --- a/src/calculate_reward_and_bellman_values.py +++ b/src/calculate_reward_and_bellman_values.py @@ -1,9 +1,11 @@ -from read_antares_data import TimeScenarioParameter, Reservoir, TimeScenarioIndex -from scipy.interpolate import interp1d -import numpy as np -from type_definition import Array1D, Array2D, Optional, Dict, Callable, List, Iterable from itertools import product +import numpy as np +from scipy.interpolate import interp1d + +from read_antares_data import Reservoir, TimeScenarioIndex, TimeScenarioParameter +from type_definition import Array1D, Array2D, Callable, Dict, Iterable, List, Optional + class ReservoirManagement: diff --git a/src/display.py b/src/display.py index d2a2a4f..4de5600 100644 --- a/src/display.py +++ b/src/display.py @@ -1,8 +1,9 @@ import numpy as np -from tqdm import tqdm import plotly.graph_objects as go -from read_antares_data import TimeScenarioParameter +from tqdm import tqdm + from multi_stock_bellman_value_calculation import MultiStockManagement +from read_antares_data import TimeScenarioParameter from type_definition import Array1D, Dict diff --git a/src/estimation.py b/src/estimation.py index f1eef49..90ff3fb 100644 --- a/src/estimation.py +++ b/src/estimation.py @@ -1,7 +1,9 @@ +from typing import Any, Dict, Optional, Union + import numpy as np -from typing import Dict, Union, Any, Optional -from read_antares_data import TimeScenarioParameter + from hyperplane_interpolation import get_interpolation +from read_antares_data import TimeScenarioParameter from type_definition import Array1D diff --git a/src/functions_iterative.py b/src/functions_iterative.py index 6f9aca2..d116377 100644 --- a/src/functions_iterative.py +++ b/src/functions_iterative.py @@ -1,18 +1,17 @@ +from time import time + import numpy as np from scipy.interpolate import interp1d -from time import time -from optimization import ( - AntaresProblem, - Basis, -) -from read_antares_data import TimeScenarioParameter, TimeScenarioIndex + from calculate_reward_and_bellman_values import ( - RewardApproximation, - ReservoirManagement, BellmanValueCalculation, - MultiStockManagement, MultiStockBellmanValueCalculation, + MultiStockManagement, + ReservoirManagement, + RewardApproximation, ) +from optimization import AntaresProblem, Basis +from read_antares_data import TimeScenarioIndex, TimeScenarioParameter from type_definition import Array1D, Array2D, Array3D, Array4D, Dict, List diff --git a/src/hyperplane_decomposition.py b/src/hyperplane_decomposition.py index 7e22702..0277445 100644 --- a/src/hyperplane_decomposition.py +++ b/src/hyperplane_decomposition.py @@ -1,5 +1,6 @@ import numpy as np from numpy.linalg import norm + from type_definition import Array1D diff --git a/src/hyperplane_interpolation.py b/src/hyperplane_interpolation.py index 21e3bfc..92db307 100644 --- a/src/hyperplane_interpolation.py +++ b/src/hyperplane_interpolation.py @@ -1,6 +1,7 @@ # Ceci est le ficiher des coupes gourmandes, l'utilité n'a malheuresement pas été prouvée et la méthode n'a pas été retenue import numpy as np from numpy.linalg import norm + from type_definition import Array1D diff --git a/src/launch_calculation.py b/src/launch_calculation.py index 60b0431..2a44193 100644 --- a/src/launch_calculation.py +++ b/src/launch_calculation.py @@ -1,10 +1,10 @@ +from calculate_reward_and_bellman_values import ReservoirManagement +from functions_iterative import itr_control +from read_antares_data import TimeScenarioParameter from simple_bellman_value_calculation import ( calculate_bellman_value_directly, calculate_bellman_value_with_precalculated_reward, ) -from functions_iterative import itr_control -from read_antares_data import TimeScenarioParameter -from calculate_reward_and_bellman_values import ReservoirManagement from type_definition import Array1D, Array2D diff --git a/src/multi_stock_bellman_value_calculation.py b/src/multi_stock_bellman_value_calculation.py index aa57ac0..e43c1e1 100644 --- a/src/multi_stock_bellman_value_calculation.py +++ b/src/multi_stock_bellman_value_calculation.py @@ -1,34 +1,33 @@ +import os as os +import pickle as pkl from itertools import product +from pathlib import Path +from typing import Annotated, Any, Dict, Literal, Optional + +import juliacall +import numpy as np +import numpy.typing as npt +import ortools.linear_solver.pywraplp as pywraplp +from ortools.linear_solver.python import model_builder +from scipy.stats import random_correlation +from tqdm import tqdm + from calculate_reward_and_bellman_values import ( - RewardApproximation, BellmanValueCalculation, - MultiStockManagement, MultiStockBellmanValueCalculation, + MultiStockManagement, + RewardApproximation, ) - -import ortools.linear_solver.pywraplp as pywraplp -from ortools.linear_solver.python import model_builder +from display import ConvergenceProgressBar, draw_usage_values, draw_uvs_sddp from estimation import Estimator, LinearCostEstimator, LinearInterpolator -from read_antares_data import TimeScenarioParameter, TimeScenarioIndex - from optimization import ( AntaresProblem, - WeeklyBellmanProblem, Basis, - solve_problem_with_multivariate_bellman_values, + WeeklyBellmanProblem, solve_for_optimal_trajectory, + solve_problem_with_multivariate_bellman_values, ) -from typing import Annotated, Literal, Dict, Optional, Any -import numpy.typing as npt -import numpy as np - -from display import ConvergenceProgressBar, draw_usage_values, draw_uvs_sddp -from scipy.stats import random_correlation -import pickle as pkl -from tqdm import tqdm -from pathlib import Path -import juliacall -import os as os +from read_antares_data import TimeScenarioIndex, TimeScenarioParameter jl = juliacall.Main diff --git a/src/optimization.py b/src/optimization.py index 6ab6376..e1782e9 100644 --- a/src/optimization.py +++ b/src/optimization.py @@ -1,5 +1,13 @@ +import pickle as pkl import re +from time import time from typing import Optional + +import numpy as np +import ortools.linear_solver.pywraplp as pywraplp +from ortools.linear_solver.python import model_builder +from scipy.interpolate import interp1d + from calculate_reward_and_bellman_values import ( BellmanValueCalculation, MultiStockBellmanValueCalculation, @@ -7,13 +15,7 @@ ) from estimation import Estimator, LinearInterpolator from read_antares_data import TimeScenarioParameter -import numpy as np -from time import time -from scipy.interpolate import interp1d -from ortools.linear_solver.python import model_builder -import ortools.linear_solver.pywraplp as pywraplp -from type_definition import Array2D, List, Dict, Array1D, npt -import pickle as pkl +from type_definition import Array1D, Array2D, Dict, List, npt class Basis: diff --git a/src/read_antares_data.py b/src/read_antares_data.py index b24d88c..920b889 100644 --- a/src/read_antares_data.py +++ b/src/read_antares_data.py @@ -1,7 +1,8 @@ -from dataclasses import dataclass, field -from typing import Optional import subprocess from configparser import ConfigParser +from dataclasses import dataclass, field +from typing import Optional + import numpy as np diff --git a/src/simple_bellman_value_calculation.py b/src/simple_bellman_value_calculation.py index 269887e..1da730c 100644 --- a/src/simple_bellman_value_calculation.py +++ b/src/simple_bellman_value_calculation.py @@ -1,16 +1,16 @@ +import numpy as np +from scipy.interpolate import interp1d + from calculate_reward_and_bellman_values import ( - RewardApproximation, - ReservoirManagement, BellmanValueCalculation, - MultiStockManagement, MultiStockBellmanValueCalculation, + MultiStockManagement, + ReservoirManagement, + RewardApproximation, ) -from read_antares_data import TimeScenarioParameter, TimeScenarioIndex -from optimization import AntaresProblem -from optimization import Basis -import numpy as np -from scipy.interpolate import interp1d from functions_iterative import compute_upper_bound +from optimization import AntaresProblem, Basis +from read_antares_data import TimeScenarioIndex, TimeScenarioParameter from type_definition import Array1D, Array2D, Dict diff --git a/src/type_definition.py b/src/type_definition.py index b056194..21fc1df 100644 --- a/src/type_definition.py +++ b/src/type_definition.py @@ -1,6 +1,7 @@ -import numpy.typing as npt +from typing import Annotated, Callable, Dict, Iterable, List, Literal, Optional + import numpy as np -from typing import Annotated, Literal, Dict, List, Optional, Callable, Iterable +import numpy.typing as npt Array1D = Annotated[npt.NDArray[np.float32], Literal["N"]] Array2D = Annotated[npt.NDArray[np.float32], Literal["N", "N"]] diff --git a/tests/test_basis.py b/tests/test_basis.py index 260ce11..ad97fd8 100644 --- a/tests/test_basis.py +++ b/tests/test_basis.py @@ -1,17 +1,18 @@ +import numpy as np +import ortools.linear_solver.pywraplp as pywraplp +import pytest + +from calculate_reward_and_bellman_values import MultiStockManagement from functions_iterative import ( - TimeScenarioParameter, + BellmanValueCalculation, ReservoirManagement, + RewardApproximation, TimeScenarioIndex, + TimeScenarioParameter, compute_upper_bound, - BellmanValueCalculation, - RewardApproximation, ) -from read_antares_data import Reservoir from optimization import AntaresProblem, Basis -from calculate_reward_and_bellman_values import MultiStockManagement -import pytest -import ortools.linear_solver.pywraplp as pywraplp -import numpy as np +from read_antares_data import Reservoir def test_basis_with_xpress() -> None: diff --git a/tests/test_bellman_value_exact.py b/tests/test_bellman_value_exact.py index 4106b45..ad7eb8e 100644 --- a/tests/test_bellman_value_exact.py +++ b/tests/test_bellman_value_exact.py @@ -1,13 +1,9 @@ -from functions_iterative import ( - TimeScenarioParameter, - ReservoirManagement, -) -from simple_bellman_value_calculation import ( - calculate_bellman_value_directly, -) -from read_antares_data import Reservoir -import pytest import numpy as np +import pytest + +from functions_iterative import ReservoirManagement, TimeScenarioParameter +from read_antares_data import Reservoir +from simple_bellman_value_calculation import calculate_bellman_value_directly def test_bellman_value_exact() -> None: diff --git a/tests/test_bellman_value_exact_two_stocks.py b/tests/test_bellman_value_exact_two_stocks.py index bb4e1a5..011ee00 100644 --- a/tests/test_bellman_value_exact_two_stocks.py +++ b/tests/test_bellman_value_exact_two_stocks.py @@ -1,24 +1,26 @@ +from itertools import product + +import numpy as np +import pytest + +from calculate_reward_and_bellman_values import ( + BellmanValueCalculation, + MultiStockBellmanValueCalculation, + MultiStockManagement, + RewardApproximation, +) from functions_iterative import ( - TimeScenarioParameter, ReservoirManagement, TimeScenarioIndex, + TimeScenarioParameter, ) from multi_stock_bellman_value_calculation import ( AntaresProblem, Dict, - solve_problem_with_multivariate_bellman_values, calculate_bellman_value_multi_stock, -) -from calculate_reward_and_bellman_values import ( - MultiStockManagement, - BellmanValueCalculation, - MultiStockBellmanValueCalculation, - RewardApproximation, + solve_problem_with_multivariate_bellman_values, ) from read_antares_data import Reservoir -import pytest -import numpy as np -from itertools import product def test_iterate_over_stock_discretization() -> None: diff --git a/tests/test_bellman_value_precalculated_reward.py b/tests/test_bellman_value_precalculated_reward.py index b627952..93deb13 100644 --- a/tests/test_bellman_value_precalculated_reward.py +++ b/tests/test_bellman_value_precalculated_reward.py @@ -1,14 +1,15 @@ +import numpy as np +import pytest + from functions_iterative import ( - TimeScenarioParameter, ReservoirManagement, TimeScenarioIndex, + TimeScenarioParameter, ) +from read_antares_data import Reservoir from simple_bellman_value_calculation import ( calculate_bellman_value_with_precalculated_reward, ) -from read_antares_data import Reservoir -import pytest -import numpy as np def test_bellman_value_precalculated_reward() -> None: diff --git a/tests/test_bellman_value_precalculated_reward_two_stocks.py b/tests/test_bellman_value_precalculated_reward_two_stocks.py index 4d9b9db..f3e4841 100644 --- a/tests/test_bellman_value_precalculated_reward_two_stocks.py +++ b/tests/test_bellman_value_precalculated_reward_two_stocks.py @@ -1,14 +1,10 @@ -from functions_iterative import ( - TimeScenarioParameter, - ReservoirManagement, -) +import numpy as np +import pytest + +from calculate_reward_and_bellman_values import MultiStockManagement +from functions_iterative import ReservoirManagement, TimeScenarioParameter from multi_stock_bellman_value_calculation import * -from calculate_reward_and_bellman_values import ( - MultiStockManagement, -) from read_antares_data import Reservoir -import pytest -import numpy as np def test_bellman_value_precalculated_multi_stock() -> None: diff --git a/tests/test_fast_uv_two_stocks.py b/tests/test_fast_uv_two_stocks.py index 5d94139..5ee3eb9 100644 --- a/tests/test_fast_uv_two_stocks.py +++ b/tests/test_fast_uv_two_stocks.py @@ -1,14 +1,10 @@ -from functions_iterative import ( - TimeScenarioParameter, - ReservoirManagement, -) +import numpy as np +import pytest + +from calculate_reward_and_bellman_values import MultiStockManagement +from functions_iterative import ReservoirManagement, TimeScenarioParameter from multi_stock_bellman_value_calculation import generate_fast_uvs_v2 -from calculate_reward_and_bellman_values import ( - MultiStockManagement, -) from read_antares_data import Reservoir -import pytest -import numpy as np def test_fast_usage_values_multi_stock() -> None: diff --git a/tests/test_iterative_two_stocks.py b/tests/test_iterative_two_stocks.py index bf7e5cd..ca27181 100644 --- a/tests/test_iterative_two_stocks.py +++ b/tests/test_iterative_two_stocks.py @@ -1,15 +1,11 @@ -from functions_iterative import ( - TimeScenarioParameter, - ReservoirManagement, -) -from multi_stock_bellman_value_calculation import * -from calculate_reward_and_bellman_values import ( - MultiStockManagement, -) -from read_antares_data import Reservoir import numpy as np import pytest +from calculate_reward_and_bellman_values import MultiStockManagement +from functions_iterative import ReservoirManagement, TimeScenarioParameter +from multi_stock_bellman_value_calculation import * +from read_antares_data import Reservoir + def test_bellman_value_iterative_method() -> None: diff --git a/tests/test_itr_storage_values.py b/tests/test_itr_storage_values.py index 698f91a..071f5b6 100644 --- a/tests/test_itr_storage_values.py +++ b/tests/test_itr_storage_values.py @@ -1,13 +1,14 @@ +import numpy as np +import ortools.linear_solver.pywraplp as pywraplp +import pytest + from functions_iterative import ( - TimeScenarioParameter, - itr_control, ReservoirManagement, TimeScenarioIndex, + TimeScenarioParameter, + itr_control, ) from read_antares_data import Reservoir -import pytest -import numpy as np -import ortools.linear_solver.pywraplp as pywraplp def test_itr_control() -> None: diff --git a/tests/test_optimization_problem_two_stock.py b/tests/test_optimization_problem_two_stock.py index c5c165e..cfa2060 100644 --- a/tests/test_optimization_problem_two_stock.py +++ b/tests/test_optimization_problem_two_stock.py @@ -1,9 +1,10 @@ -from functions_iterative import TimeScenarioParameter, ReservoirManagement -from read_antares_data import Reservoir -from optimization import AntaresProblem, Basis -from calculate_reward_and_bellman_values import MultiStockManagement -import pytest import ortools.linear_solver.pywraplp as pywraplp +import pytest + +from calculate_reward_and_bellman_values import MultiStockManagement +from functions_iterative import ReservoirManagement, TimeScenarioParameter +from optimization import AntaresProblem, Basis +from read_antares_data import Reservoir def test_create_weekly_problem_with_two_stocks() -> None: diff --git a/tests/test_overflow.py b/tests/test_overflow.py index 62820c6..76b092a 100644 --- a/tests/test_overflow.py +++ b/tests/test_overflow.py @@ -1,13 +1,11 @@ -from functions_iterative import ( - TimeScenarioParameter, - ReservoirManagement, -) +import numpy as np +from scipy.interpolate import interp1d + +from functions_iterative import ReservoirManagement, TimeScenarioParameter +from read_antares_data import Reservoir from simple_bellman_value_calculation import ( calculate_bellman_value_with_precalculated_reward, ) -from read_antares_data import Reservoir -import numpy as np -from scipy.interpolate import interp1d def test_bellman_value_precalculated_reward_overflow() -> None: diff --git a/tests/test_read_optimization_problem.py b/tests/test_read_optimization_problem.py index ace14f9..dd4080b 100644 --- a/tests/test_read_optimization_problem.py +++ b/tests/test_read_optimization_problem.py @@ -1,9 +1,10 @@ -from functions_iterative import TimeScenarioParameter, ReservoirManagement -from read_antares_data import Reservoir -from optimization import AntaresProblem, Basis -from calculate_reward_and_bellman_values import MultiStockManagement -import pytest import ortools.linear_solver.pywraplp as pywraplp +import pytest + +from calculate_reward_and_bellman_values import MultiStockManagement +from functions_iterative import ReservoirManagement, TimeScenarioParameter +from optimization import AntaresProblem, Basis +from read_antares_data import Reservoir def test_create_and_modify_weekly_problem() -> None: diff --git a/tests/test_update_reward.py b/tests/test_update_reward.py index e9769d3..baf02aa 100644 --- a/tests/test_update_reward.py +++ b/tests/test_update_reward.py @@ -1,6 +1,7 @@ -from calculate_reward_and_bellman_values import RewardApproximation from pytest import approx +from calculate_reward_and_bellman_values import RewardApproximation + def test_construct_initial_reward_approximation() -> None: initial_reward = RewardApproximation(lb_control=0, ub_control=10, ub_reward=10) diff --git a/tests/test_upper_bound.py b/tests/test_upper_bound.py index 00d2b87..17499ef 100644 --- a/tests/test_upper_bound.py +++ b/tests/test_upper_bound.py @@ -1,17 +1,18 @@ +import numpy as np +import ortools.linear_solver.pywraplp as pywraplp +import pytest + +from calculate_reward_and_bellman_values import MultiStockManagement from functions_iterative import ( - TimeScenarioParameter, - compute_upper_bound, + BellmanValueCalculation, + ReservoirManagement, RewardApproximation, TimeScenarioIndex, - ReservoirManagement, - BellmanValueCalculation, + TimeScenarioParameter, + compute_upper_bound, ) from optimization import AntaresProblem from read_antares_data import Reservoir -from calculate_reward_and_bellman_values import MultiStockManagement -import pytest -import numpy as np -import ortools.linear_solver.pywraplp as pywraplp def test_upper_bound() -> None: