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

Implement sclopf #710

Merged
merged 33 commits into from
Feb 28, 2024
Merged

Implement sclopf #710

merged 33 commits into from
Feb 28, 2024

Conversation

ClaraBuettner
Copy link
Contributor

Solves #381

I created a new feature branch and did not used the old one because it was very outdated and also included several features that were already in dev.

@ClaraBuettner
Copy link
Contributor Author

ClaraBuettner commented Jan 16, 2024

Current status:
The basic execution of the SCLOPF is working and is already included in etrago.optimize().
There are still some things to do:

Currently, the iterative sclopf always uses pyomo. It would be nice to allow using linopy, but that might not be part of this PR.

@ClaraBuettner ClaraBuettner marked this pull request as ready for review February 14, 2024 11:55
Copy link
Contributor

@CarlosEpia CarlosEpia left a comment

Choose a reason for hiding this comment

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

I installed eTraGo using this branch in a fresh virtual environment and when I try to run it (using eGon2035) I got this error message:

File ~/env/etrago_pr_710/lib/python3.10/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)

File ~/git/eTraGo/etrago/appl.py:770
etrago = run_etrago(args, json_path=None)

File ~/git/eTraGo/etrago/appl.py:678 in run_etrago
etrago.build_network_from_db()

File ~/git/eTraGo/etrago/tools/network.py:377 in build_network_from_db
self.scenario = NetworkScenario(

File ~/git/eTraGo/etrago/tools/io.py:129 in init
self.configure_timeindex()

File ~/git/eTraGo/etrago/tools/io.py:159 in configure_timeindex
tr = saio.as_pandas(

File ~/env/etrago_pr_710/lib/python3.10/site-packages/saio.py:181 in as_pandas
df = pd.read_sql_query(query.statement, query.session.bind,

File ~/env/etrago_pr_710/lib/python3.10/site-packages/pandas/io/sql.py:526 in read_sql_query
return pandas_sql.read_query(

File ~/env/etrago_pr_710/lib/python3.10/site-packages/pandas/io/sql.py:2739 in read_query
cursor = self.execute(sql, params)

File ~/env/etrago_pr_710/lib/python3.10/site-packages/pandas/io/sql.py:2671 in execute
raise TypeError("Query must be a string unless using sqlalchemy.")

TypeError: Query must be a string unless using sqlalchemy.

Do you have any idea why could it happen?

etrago/appl.py Outdated
@@ -51,7 +52,7 @@
"db": "egon-data", # database session
"gridversion": None, # None for model_draft or Version number
"method": { # Choose method and settings for optimization
"type": "market_grid", # type of optimization, 'lopf' or 'market_grid'
"type": "market_grid", # type of optimization, 'lopf', 'sclopf or 'market_grid'
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the description of the "type" parameter in the docstrings

@ClaraBuettner
Copy link
Contributor Author

I installed eTraGo using this branch in a fresh virtual environment and when I try to run it (using eGon2035) I got this error message:

File ~/env/etrago_pr_710/lib/python3.10/site-packages/spyder_kernels/py3compat.py:356 in compat_exec exec(code, globals, locals)

File ~/git/eTraGo/etrago/appl.py:770 etrago = run_etrago(args, json_path=None)

File ~/git/eTraGo/etrago/appl.py:678 in run_etrago etrago.build_network_from_db()

File ~/git/eTraGo/etrago/tools/network.py:377 in build_network_from_db self.scenario = NetworkScenario(

File ~/git/eTraGo/etrago/tools/io.py:129 in init self.configure_timeindex()

File ~/git/eTraGo/etrago/tools/io.py:159 in configure_timeindex tr = saio.as_pandas(

File ~/env/etrago_pr_710/lib/python3.10/site-packages/saio.py:181 in as_pandas df = pd.read_sql_query(query.statement, query.session.bind,

File ~/env/etrago_pr_710/lib/python3.10/site-packages/pandas/io/sql.py:526 in read_sql_query return pandas_sql.read_query(

File ~/env/etrago_pr_710/lib/python3.10/site-packages/pandas/io/sql.py:2739 in read_query cursor = self.execute(sql, params)

File ~/env/etrago_pr_710/lib/python3.10/site-packages/pandas/io/sql.py:2671 in execute raise TypeError("Query must be a string unless using sqlalchemy.")

TypeError: Query must be a string unless using sqlalchemy.

Do you have any idea why could it happen?

I have the same problem on dev when I create a new environment. So I guess this is not related to the changes on this branch. The reason might be a new package version or sth. like that.

etrago/appl.py Outdated
@@ -736,6 +737,9 @@ def run_etrago(args, json_path):
# skip snapshots
etrago.skip_snapshots()

# Temporary drop DLR as it is currently not working with sclopf
etrago.network.lines_t.s_max_pu = pd.DataFrame(index=etrago.network.snapshots, columns=etrago.network.lines.index, data=1.)
Copy link
Contributor

Choose a reason for hiding this comment

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

As it is implemented, we will be dropping DLR also for LOPF or market_grid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is also needed for market_grid as that method also used the sclopf. But I can adjust it for the lopf

formulation=args["model_formulation"],
pyomo=True,
)
path_name = "/sclopf_iteration_"
Copy link
Contributor

Choose a reason for hiding this comment

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

path_name is assigned but not used.

elif self.args["method"]["type"] == "sclopf":
self.sclopf(
post_lopf=False,
extra_functionality=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

The function iterate_sclopf() is failing due to an unexpected keyword. Error message:


  File ~/env/etrago_710_fail-fix/lib/python3.10/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File ~/git/eTraGo/etrago/appl.py:770
    etrago = run_etrago(args, json_path=None)

  File ~/git/eTraGo/etrago/appl.py:749 in run_etrago
    etrago.optimize()

  File ~/git/eTraGo/etrago/execute/__init__.py:422 in optimize
    self.sclopf(

TypeError: iterate_sclopf() got an unexpected keyword argument 'extra_functionality'

Copy link
Contributor

@CarlosEpia CarlosEpia left a comment

Choose a reason for hiding this comment

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

There are some changes that should be addressed before merging this branch.

Copy link
Contributor

@CarlosEpia CarlosEpia left a comment

Choose a reason for hiding this comment

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

This branch works using the default args. It can be merged to dev.

@ClaraBuettner ClaraBuettner merged commit 49eb0f0 into dev Feb 28, 2024
6 checks passed
@ClaraBuettner ClaraBuettner mentioned this pull request Aug 8, 2024
@ClaraBuettner ClaraBuettner deleted the features/implement-sclopf-pypsa0262 branch August 13, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants