Skip to content
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: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda"
}
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The problem that **opti_market** solves is to optimize the charge and discharge
opti_market
├── base_configuration
│ ├── blue_print.yml
│ ├── double_market_min_charge.yml
│ ├── double_market_unconstrained.yml #
│ ├── double_market.yml
│ ├── single_market_a.yml
│ └── single_market_b.yml
Expand Down Expand Up @@ -193,7 +195,6 @@ simulation:
packaged_data:
output:
path_to_save:
basic_plot:
default_location:
clean_option:
```
Expand Down Expand Up @@ -243,7 +244,6 @@ One block per market (`market1`, `market2`, …; at most 6). The names are free;
| `default_location` | no | True | If True, the results are saved in `<repository>/results/<name>`. |
| `path_to_save` | no | null | Folder where the results are saved (`<path_to_save>/results/<name>`). Use it with `default_location: False`. |
| `clean_option` | no | True | If the output folder already exists, True deletes it and writes the new results; False stops the program. |
| `basic_plot` | no | False | Reserved for plotting. Not used in the current version. |

### Example

Expand Down Expand Up @@ -275,7 +275,6 @@ simulation:
packaged_data: True
output:
path_to_save: null
basic_plot: True
default_location: True
clean_option: True
```
1 change: 0 additions & 1 deletion base_configuration/blue_print.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ simulation:
packaged_data:
output:
path_to_save:
basic_plot:
default_location:
clean_option:
1 change: 0 additions & 1 deletion base_configuration/double_market.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ simulation:

output:
path_to_save: null
basic_plot: True
default_location: True
clean_option: True
1 change: 0 additions & 1 deletion base_configuration/double_market_min_charge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ simulation:

output:
path_to_save: null
basic_plot: True
default_location: True
clean_option: True
1 change: 0 additions & 1 deletion base_configuration/double_market_unconstrained.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ simulation:

output:
path_to_save: null
basic_plot: True
default_location: True
clean_option: True
1 change: 0 additions & 1 deletion base_configuration/single_market_a.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ simulation:

output:
path_to_save: null
basic_plot: True
default_location: True
clean_option: True
1 change: 0 additions & 1 deletion base_configuration/single_market_b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ simulation:

output:
path_to_save: null
basic_plot: True
default_location: True
clean_option: True
1 change: 1 addition & 0 deletions src/opti_market/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Battery dispatch optimisation across electricity markets."""
2 changes: 2 additions & 0 deletions src/opti_market/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Run the package with ``python -m opti_market``."""

from opti_market.opti_market import run_opti_market

run_opti_market()
2 changes: 2 additions & 0 deletions src/opti_market/config_module/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Configuration of the battery, markets, simulation options and output."""

from .configuration_read import read_configuration, read_configurations_files
from .configure_battery import BATTERY, BATTERY_SPEC
from .configure_market import Markets, read_market
Expand Down
99 changes: 65 additions & 34 deletions src/opti_market/config_module/configuration_read.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Definition of options for the input configuration file.

'man':'mandatory', => If it is not defined, the program is preventevely blocked
'opt': 'fully optional, if anything is defined, the default value are applied'
'man':'mandatory', => If it is not defined, the program is preventively blocked
'opt': 'fully optional, if nothing is defined, the default values are applied'
"""

from importlib.resources import files
Expand Down Expand Up @@ -58,7 +58,6 @@
}
_OUTPUT_INPUT_: dict[str, tuple[OptionKind, OptionValue]] = {
"path_to_save": ("opt", None),
"basic_plot": ("opt", False),
"default_location": ("opt", True),
"clean_option": ("opt", True),
}
Expand All @@ -67,6 +66,17 @@
# ---
# ---
def read_simulation_config(inp_dict: dict[str, Any]) -> dict[str, Any]:
"""Read the optimization section of the configuration file.

Check the input against _SIMULATION_INPUT_ and fill the missing
optional entries with their default values.

Args:
inp_dict (dict): optimization data field from the yml file.

Returns:
dict: complete set of simulation options, including defaults.
"""

sim_config = check_input(inp_dict=inp_dict, par=_SIMULATION_INPUT_)

Expand All @@ -75,6 +85,21 @@ def read_simulation_config(inp_dict: dict[str, Any]) -> dict[str, Any]:

# ---
def read_simulation_output(inp_dict: dict[str, Any]) -> dict[str, Any]:
"""Read the output section of the configuration file.

Check the input against _OUTPUT_INPUT_, fill the missing optional
entries with their default values and convert an empty path_to_save
into None.

Args:
inp_dict (dict): output data field from the yml file.

Raises:
ValueError: if path_to_save is specified and default_location is True.

Returns:
dict: complete set of output options, including defaults.
"""

output_configuration = check_input(inp_dict=inp_dict, par=_OUTPUT_INPUT_)
# Safe Guard.
Expand All @@ -94,13 +119,13 @@ def read_simulation_output(inp_dict: dict[str, Any]) -> dict[str, Any]:

# ---
def read_battery(inp_dict: dict[str, Any]) -> dict[str, Any]:
"""Read the battery input data
Check the input, fill up the data with the default options
"""Read the battery input data.
Check the input and fill in the data with the default options.
Args:
inp_dict (dict): input battery data field from yml file
inp_dict (dict): input battery data field from the yml file.

Returns:
dict: complete data set for battery with default.
dict: complete data set for the battery, with defaults.
"""
battery = check_input(inp_dict=inp_dict, par=_BATTERY_INPUT_)

Expand All @@ -109,20 +134,20 @@ def read_battery(inp_dict: dict[str, Any]) -> dict[str, Any]:

# ---
def check_input(inp_dict: dict[str, Any], par: dict[str, Any]) -> dict[str, Any]:
"""Check the input, and fill a new small dictionary
of input.
The function checks the data
"""Check the input and fill a new small dictionary
of inputs.
The function checks the data.

Args:
inp_dict (dict): the data read from the configuration files
par (dict): the global parameter dictionary on top of this file
par (dict): the global parameter dictionary at the top of this file

Raises:
ValueError: if the parameters is not defined (i.e., it is not specified),
ValueError: if the parameter is not defined (i.e., it is not specified)
but it is mandatory, throw an error and highlight at least the name of the field

Returns:
dict: completed dictionary with all the information for filling up the
dict: completed dictionary with all the information for filling in the
real input configuration.
"""
new_dict = dict.fromkeys(par, None)
Expand All @@ -145,7 +170,7 @@ def check_input(inp_dict: dict[str, Any], par: dict[str, Any]) -> dict[str, Any]

# ---
def read_markets(markt: dict[str, Any]) -> dict[str, Any]:
"""Reads the market and convert path in case of flags.
"""Read the market and convert the path in case of flags.

Args:
markets (dict): check the input data of the market and release
Expand Down Expand Up @@ -203,16 +228,16 @@ def post_process_config_file(
pre_config: dict[str, Any], config_fin: dict[str, Any]
) -> None:
"""Use the original configuration file and construct the
effective configuration of the simulation
effective configuration of the simulation.

Reason: Since the take-home assignment has two market, I wanted
Reason: Since the take-home assignment has two markets, I wanted
to flag the presence of these markets within the package, such
that the behaviour is deterministic for the example, and also
to inform directly the unit/integration/regression test.
to directly inform the unit/integration/regression tests.

Args:
pre_config (dict): data read from the configuration file
config_fin (dict): final data for configure, battery and market classes
config_fin (dict): final data to configure the battery and market classes
"""

config_fin["markets"] = read_markets(pre_config["simulation"]["markets"])
Expand Down Expand Up @@ -251,37 +276,43 @@ def read_configuration(config_file: str) -> dict[str, dict[str, Any]]:
)

return configurations_sim


# ---
def check_consistency(markt:Markets,opti_opt:Opti_Market_Options)->None:
def check_consistency(markt: Markets, opti_opt: Opti_Market_Options) -> None:
"""Check if the starting date of the simulation is consistent with the
common start/end of the markets
common start/end of the markets.

Args:
markt (Markets): Markets class
opti_opt (Opti_Market_Options): optimization option
markt (Markets): Markets class
opti_opt (Opti_Market_Options): optimization options

Raises:
ValueError: The starting date of the simulation predates the markets timeseries.
ValueError: The ending date of the simulation is after the final date of the markets timeseries.
ValueError: The starting date of the simulation predates the market timeseries.
ValueError: The ending date of the simulation is after the final date of the market timeseries.
"""

if opti_opt.start_date < markt.common_start:
raise ValueError(' The simulation starts before the initial common time frame of the markets')
elif opti_opt.end_date > markt.common_end:
raise ValueError(' The simulation ends after the final common time frame of the markets')


if opti_opt.start_date < markt.common_start:
raise ValueError(
" The simulation starts before the initial common time frame of the markets"
)
elif opti_opt.end_date > markt.common_end:
raise ValueError(
" The simulation ends after the final common time frame of the markets"
)


# ---
def read_configurations_files(
config_file: str,
) -> tuple[BATTERY, Markets, Opti_Market_Options, Output]:
"""Configure the simulation using the configuration file
"""Configure the simulation using the configuration file.

Args:
config_file (str): path to the configuration file

Returns:
tuple[BATTERY, Markets, Opti_Market_Options, Output]: classes that handles the simulation behaviour
tuple[BATTERY, Markets, Opti_Market_Options, Output]: classes that handle the simulation behaviour
"""

configuration_sim = read_configuration(config_file=config_file)
Expand All @@ -297,8 +328,8 @@ def read_configurations_files(
dict_config=configuration_sim["output"],
name_simulation=str(configuration_sim["name"]),
)
check_consistency(markt=markt,opti_opt=opti_opt)

check_consistency(markt=markt, opti_opt=opti_opt)

return bat, markt, opti_opt, output

Expand Down
Loading