Skip to content

Removed config - added distinction for thermal/intermittent units#23

Open
AlessandroPampado99 wants to merge 4 commits intomainfrom
remove_config
Open

Removed config - added distinction for thermal/intermittent units#23
AlessandroPampado99 wants to merge 4 commits intomainfrom
remove_config

Conversation

@AlessandroPampado99
Copy link
Collaborator

@davide-f FYI. This PR is removing the use of the YAML config file passing parameters to pypsa2smspp directly. It distinguishes unit commitment cases directly, as well as distinction between capacity expansion with ucblock (base case) or investment

Comment on lines +83 to 176
Parameters
----------
unitblocks : dict
Dictionary that holds the parameters for each unit block, organized by network components.

IntermittentUnitBlock_parameters : dict
Parameters for an IntermittentUnitBlock, like solar and wind turbines.
The values set to a float number are absent in Pypsa, while lambda functions are used to get data from
Pypa DataFrames

ThermalUnitBlock_parameters : dict
Parameters for a ThermalUnitBlock
merge_links : bool | str | Sequence[str], default True
Controls whether store-related charge/discharge link pairs are merged into a single
"merged link" representation (useful to match PyPSA-Eur modelling conventions).

Supported values:
- False: disable merging entirely.
- True: enable merging for built-in safe presets (TES, battery, H2 reversed).
- str / list[str]: enable merging for a subset of presets and/or custom tags.
If custom tags are provided (i.e., values not in {"tes","battery","h2"}),
a `merge_selector` MUST be provided.

merge_selector : callable, optional
Optional power-user hook to authorize additional merges beyond the built-in presets.

Signature:
merge_selector(n, store_name, srow, charge_row, discharge_row) -> bool

Notes:
- If `merge_links` contains custom entries, this selector is required.
- Any exception raised inside the selector will cause the corresponding store
merge to be skipped.

capacity_expansion_ucblock : bool, default True
Selects the internal block structure / modelling mode:
- True -> build UCBlock-style representation.
- False -> build InvestmentBlock-style representation.

This flag is used to choose default SMS++ templates when `configfile="auto"`.

enable_thermal_units : bool, default False
Controls whether "thermal" generator units are allowed in the transformation.

Behaviour:
- False: all non-slack generators are treated as intermittent (i.e., no thermals).
- True : both intermittent and thermal generators are allowed.

When enabled, the intermittent/thermal split is determined by `intermittent_carriers`
(user override) or by the library default set (typically `renewable_carriers` from constants).

intermittent_carriers : str | Sequence[str], optional
Defines which generator carriers should be treated as intermittent when
`enable_thermal_units=True`.

Behaviour:
- None: use the library default intermittent set (typically `renewable_carriers`).
- str / list[str]: explicit override (case-insensitive).

Notes:
- This parameter is ignored when `enable_thermal_units=False` (since everything
is treated as intermittent anyway, except slack/load-shedding carriers).

workdir : str | Path, default "output"
Output directory for SMS++ artifacts. The directory is created if it does not exist.

name : str, default "test_case"
Case name used to render file templates (e.g., "temp_{name}.nc").

overwrite : bool, default True
If True, existing artifacts at the resolved paths are removed before optimization.

fp_temp : str | Path, default "temp_{name}.nc"
Temporary network file path template passed to `SMSNetwork.optimize(fp_temp=...)`.
If relative, it is interpreted relative to `workdir`.
Supports formatting with `{name}`.

fp_log : str | Path | None, default "log_{name}.txt"
Log file path template passed to `SMSNetwork.optimize(fp_log=...)`.
If None, logging to file is disabled. Supports `{name}`.

fp_solution : str | Path | None, default "solution_{name}.nc"
Solution file path template passed to `SMSNetwork.optimize(fp_solution=...)`.
If None, solution writing may be disabled depending on solver behaviour. Supports `{name}`.

configfile : str | Path | pysmspp.SMSConfig | None, default "auto"
SMS++ configuration input passed to `SMSNetwork.optimize(configfile=...)`.

Supported values:
- "auto" or None: use built-in default template based on `capacity_expansion_ucblock`.
- str/Path: interpreted as a template path used to build `pysmspp.SMSConfig(template=...)`.
- pysmspp.SMSConfig: used directly.

pysmspp_options : Mapping[str, Any], optional
Additional keyword arguments forwarded to `SMSNetwork.optimize(...)`.

Typical keys include (all optional; pySMSpp provides defaults):
- smspp_solver : str | SMSPPSolverTool
- inner_block_name : str
- logging : bool
- tracking_period : float

Any other keys are forwarded as solver-constructor kwargs (power-user usage).
"""
Copy link
Member

Choose a reason for hiding this comment

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

These entries shall be moved into the init they are the arguments of the init

Copy link
Member

Choose a reason for hiding this comment

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

The introduction of this class shall provide info on the class and how to use it.
It can be another PR

Comment on lines +192 to +197
fp_temp: Union[str, Path] = "temp_{name}.nc",
fp_log: Optional[Union[str, Path]] = "log_{name}.txt",
fp_solution: Optional[Union[str, Path]] = "solution_{name}.nc",

Methods:
----------
init : Start the workflow of the class

"""

# Class with conversion dicts for PyPSA-SMS++
config_conv = TransformationConfig()
# Work on a private copy so we can safely mutate dicts
self.config = deepcopy(config_conv)

# Config file
self.cfg = load_any_config(
config,
defaults=default_transformation_cfg(),
as_attrdict=True,
)
# --- SMS++ ---
configfile: Optional[Union[str, Path, "pysmspp.SMSConfig"]] = "auto",
Copy link
Member

Choose a reason for hiding this comment

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

these are pysmspp_options. Is there a reason to place them separately?

"Bus": "buses"
}

self.max_hours_stores = 1
Copy link
Member

Choose a reason for hiding this comment

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

? this should be documented. why 1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants