Skip to content

Fix mypy #47

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

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest

from andromede.model.parsing import parse_yaml_library
from andromede.model.resolve_library import resolve_library
from andromede.model.resolve_library import Library, resolve_library


@pytest.fixture(scope="session")
Expand All @@ -23,7 +23,7 @@ def libs_dir() -> Path:


@pytest.fixture(scope="session")
def lib(libs_dir: Path):
def lib(libs_dir: Path) -> Library:
lib_file = libs_dir / "lib.yml"

with lib_file.open() as f:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_andromede.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def generate_data(
for scenario in range(scenarios):
for absolute_timestep in range(horizon):
if absolute_timestep == 0:
data[TimeScenarioIndex(absolute_timestep, scenario)] = -18
data[TimeScenarioIndex(absolute_timestep, scenario)] = -18.0
else:
data[TimeScenarioIndex(absolute_timestep, scenario)] = 2 * efficiency

Expand Down
17 changes: 9 additions & 8 deletions tests/functional/test_andromede_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from andromede.expression import literal, param, var
from andromede.expression.indexing_structure import IndexingStructure
from andromede.model import Model, ModelPort, float_parameter, float_variable, model
from andromede.model.library import Library
from andromede.model.model import PortFieldDefinition, PortFieldId
from andromede.simulation import (
BlockBorderManagement,
Expand All @@ -23,7 +24,7 @@
)


def test_network(lib) -> None:
def test_network(lib: Library) -> None:
network = Network("test")
assert network.id == "test"
assert list(network.nodes) == []
Expand All @@ -47,7 +48,7 @@ def test_network(lib) -> None:
network.get_component("unknown")


def test_basic_balance(lib) -> None:
def test_basic_balance(lib: Library) -> None:
"""
Balance on one node with one fixed demand and one generation, on 1 timestep.
"""
Expand Down Expand Up @@ -88,7 +89,7 @@ def test_basic_balance(lib) -> None:
assert problem.solver.Objective().Value() == 3000


def test_link(lib) -> None:
def test_link(lib: Library) -> None:
"""
Balance on one node with one fixed demand and one generation, on 1 timestep.
"""
Expand Down Expand Up @@ -146,7 +147,7 @@ def test_link(lib) -> None:
assert variable.solution_value() == -100


def test_stacking_generation(lib) -> None:
def test_stacking_generation(lib: Library) -> None:
"""
Balance on one node with one fixed demand and 2 generations with different costs, on 1 timestep.
"""
Expand Down Expand Up @@ -198,7 +199,7 @@ def test_stacking_generation(lib) -> None:
assert problem.solver.Objective().Value() == 30 * 100 + 50 * 50


def test_spillage(lib) -> None:
def test_spillage(lib: Library) -> None:
"""
Balance on one node with one fixed demand and 1 generation higher than demand and 1 timestep .
"""
Expand Down Expand Up @@ -238,7 +239,7 @@ def test_spillage(lib) -> None:
assert problem.solver.Objective().Value() == 30 * 200 + 50 * 10


def test_min_up_down_times(lib) -> None:
def test_min_up_down_times(lib: Library) -> None:
"""
Model on 3 time steps with one thermal generation and one demand on a single node.
- Demand is the following time series : [500 MW, 0, 0]
Expand Down Expand Up @@ -332,7 +333,7 @@ def test_min_up_down_times(lib) -> None:
assert problem.solver.Objective().Value() == pytest.approx(72000, abs=0.01)


def test_changing_demand(lib) -> None:
def test_changing_demand(lib: Library) -> None:
"""
Model on 3 time steps simple production, demand
- P_max = 500 MW
Expand Down Expand Up @@ -388,7 +389,7 @@ def test_changing_demand(lib) -> None:
assert problem.solver.Objective().Value() == 40000


def test_min_up_down_times_2(lib) -> None:
def test_min_up_down_times_2(lib: Library) -> None:
"""
Model on 3 time steps with one thermal generation and one demand on a single node.
- Demand is the following time series : [500 MW, 0, 0]
Expand Down
10 changes: 8 additions & 2 deletions tests/functional/test_xpansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,14 @@ def test_generation_xpansion_two_time_steps_two_scenarios(

output = OutputValues(problem)
expected_output = OutputValues()
expected_output.component("G1").var("generation").value = [[0, 200], [0, 100]]
expected_output.component("CAND").var("generation").value = [[300, 300], [200, 300]]
expected_output.component("G1").var("generation").value = [
[0.0, 200.0],
[0.0, 100.0],
]
expected_output.component("CAND").var("generation").value = [
[300.0, 300.0],
[200.0, 300.0],
]
expected_output.component("CAND").var("p_max").value = 300.0

assert output == expected_output, f"Output differs from expected: {output}"
20 changes: 10 additions & 10 deletions tests/integration/test_benders_decomposed.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ def test_benders_decomposed_multi_time_block_single_scenario(
"""

data = {}
data[TimeIndex(0)] = 200
data[TimeIndex(1)] = 300
data[TimeIndex(0)] = 200.0
data[TimeIndex(1)] = 300.0

demand_data = TimeSeriesData(time_series=data)

Expand Down Expand Up @@ -327,15 +327,15 @@ def test_benders_decomposed_multi_time_block_single_scenario(
scenarios,
)

data = {
data_output = {
"solution": {
"overall_cost": 62_000,
"values": {
"CAND_p_max": 100,
},
}
}
solution = BendersSolution(data)
solution = BendersSolution(data_output)

assert xpansion.run()
decomposed_solution = xpansion.solution
Expand Down Expand Up @@ -374,8 +374,8 @@ def test_benders_decomposed_single_time_block_multi_scenario(
"""

data = {}
data[ScenarioIndex(0)] = 200
data[ScenarioIndex(1)] = 300
data[ScenarioIndex(0)] = 200.0
data[ScenarioIndex(1)] = 300.0

demand_data = ScenarioSeriesData(scenario_series=data)

Expand Down Expand Up @@ -415,15 +415,15 @@ def test_benders_decomposed_single_time_block_multi_scenario(
scenarios,
)

data = {
data_output = {
"solution": {
"overall_cost": 55_000,
"values": {
"CAND_p_max": 100,
},
}
}
solution = BendersSolution(data)
solution = BendersSolution(data_output)

assert xpansion.run()
decomposed_solution = xpansion.solution
Expand Down Expand Up @@ -510,15 +510,15 @@ def test_benders_decomposed_multi_time_block_multi_scenario(
scenarios,
)

data = {
data_output = {
"solution": {
"overall_cost": 58_000,
"values": {
"CAND_p_max": 100,
},
}
}
solution = BendersSolution(data)
solution = BendersSolution(data_output)

assert xpansion.run()
decomposed_solution = xpansion.solution
Expand Down
6 changes: 3 additions & 3 deletions tests/models/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest

from andromede.model.parsing import parse_yaml_library
from andromede.model.resolve_library import resolve_library
from andromede.model.resolve_library import Library, resolve_library


@pytest.fixture(scope="session")
Expand All @@ -28,7 +28,7 @@ def data_dir() -> Path:


@pytest.fixture(scope="session")
def lib(data_dir: Path):
def lib(data_dir: Path) -> Library:
lib_file = data_dir / "lib.yml"

with lib_file.open() as f:
Expand All @@ -39,7 +39,7 @@ def lib(data_dir: Path):


@pytest.fixture(scope="session")
def lib_sc():
def lib_sc() -> Library:
libs_path = Path(__file__).parents[2] / "src/andromede/libs/"
lib_sc_file = libs_path / "standard_sc.yml"

Expand Down
8 changes: 4 additions & 4 deletions tests/models/test_ac_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def ac_lib(libs_dir: Path, std_lib: Library) -> Library:
return resolve_library(input_lib, preloaded_libraries=[std_lib])


def test_ac_network_no_links(ac_lib: Library):
def test_ac_network_no_links(ac_lib: Library) -> None:
"""
The network only has one AC node where a generator and a demand are connected.

Expand Down Expand Up @@ -87,7 +87,7 @@ def test_ac_network_no_links(ac_lib: Library):
assert problem.solver.Objective().Value() == pytest.approx(3000, abs=0.01)


def test_ac_network(ac_lib: Library):
def test_ac_network(ac_lib: Library) -> None:
"""
The network only has 2 AC nodes connected by 1 AC link.

Expand Down Expand Up @@ -148,7 +148,7 @@ def test_ac_network(ac_lib: Library):
)


def test_parallel_ac_links(ac_lib: Library):
def test_parallel_ac_links(ac_lib: Library) -> None:
"""
The network has 2 AC nodes connected by 2 parallel links,
where reactance is 1 for line L1, and 2 for line L2.
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_parallel_ac_links(ac_lib: Library):
)


def test_parallel_ac_links_with_pst(ac_lib: Library):
def test_parallel_ac_links_with_pst(ac_lib: Library) -> None:
"""
Same case as in parallel_ac_links but:
- flow is restricted to 50 MW on line L1, so it cannot
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_electrolyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
)


def test_electrolyzer():
def test_electrolyzer() -> None:
elec_node = Node(model=ELECTRICAL_NODE_MODEL, id="1")
h2_node = Node(model=H2_NODE_MODEL, id="2")

Expand Down
32 changes: 16 additions & 16 deletions tests/models/test_electrolyzer_n_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"""


def test_electrolyzer_n_inputs_1():
def test_electrolyzer_n_inputs_1() -> None:
"""
Test with an electrolyzer for each input

Expand Down Expand Up @@ -133,15 +133,15 @@ def test_electrolyzer_n_inputs_1():
print(ep2_gen)
print(gp_gen)

assert math.isclose(ep1_gen, 70)
assert math.isclose(ep2_gen, 42)
assert math.isclose(gp_gen, 30)
assert math.isclose(ep1_gen, 70) # type:ignore
assert math.isclose(ep2_gen, 42) # type:ignore
assert math.isclose(gp_gen, 30) # type:ignore

assert status == problem.solver.OPTIMAL
assert math.isclose(problem.solver.Objective().Value(), 1990)


def test_electrolyzer_n_inputs_2():
def test_electrolyzer_n_inputs_2() -> None:
"""
Test with one electrolyzer that has two inputs

Expand Down Expand Up @@ -222,15 +222,15 @@ def test_electrolyzer_n_inputs_2():
print(ep2_gen)
print(gp_gen)

assert math.isclose(ep1_gen, 70)
assert math.isclose(ep2_gen, 42)
assert math.isclose(gp_gen, 30)
assert math.isclose(ep1_gen, 70) # type:ignore
assert math.isclose(ep2_gen, 42) # type:ignore
assert math.isclose(gp_gen, 30) # type:ignore

assert status == problem.solver.OPTIMAL
assert math.isclose(problem.solver.Objective().Value(), 1990)


def test_electrolyzer_n_inputs_3():
def test_electrolyzer_n_inputs_3() -> None:
"""
Test with a consumption_electrolyzer with two inputs

Expand Down Expand Up @@ -317,15 +317,15 @@ def test_electrolyzer_n_inputs_3():
ep2_gen = output.component("ep2").var("generation").value
gp_gen = output.component("gp").var("generation").value

assert math.isclose(ep1_gen, 70)
assert math.isclose(ep2_gen, 30)
assert math.isclose(gp_gen, 30)
assert math.isclose(ep1_gen, 70) # type:ignore
assert math.isclose(ep2_gen, 30) # type:ignore
assert math.isclose(gp_gen, 30) # type:ignore

assert status == problem.solver.OPTIMAL
assert math.isclose(problem.solver.Objective().Value(), 1750)


def test_electrolyzer_n_inputs_4():
def test_electrolyzer_n_inputs_4() -> None:
"""
Test with one electrolyzer with one input that takes every inputs

Expand Down Expand Up @@ -405,9 +405,9 @@ def test_electrolyzer_n_inputs_4():
ep2_gen = output.component("ep2").var("generation").value
gp_gen = output.component("gp").var("generation").value

assert math.isclose(ep1_gen, 70)
assert math.isclose(ep2_gen, 30)
assert math.isclose(gp_gen, 30)
assert math.isclose(ep1_gen, 70) # type:ignore
assert math.isclose(ep2_gen, 30) # type:ignore
assert math.isclose(gp_gen, 30) # type:ignore

assert status == problem.solver.OPTIMAL
assert math.isclose(problem.solver.Objective().Value(), 1750)
Loading
Loading