Skip to content

Commit

Permalink
Merge pull request #26 from tZ3ma/nox_poc
Browse files Browse the repository at this point in the history
Try Circumventing NOx
  • Loading branch information
mathias-ammon authored Feb 12, 2023
2 parents 9baa6ac + 70f4fbe commit e8299db
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 55 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tessif"
version = "0.0.22"
version = "0.0.23"
description = "Transforming Energy Supply System modell*I*ng Framework"
authors = ["Mathias Ammon <mathias.ammon@tuhh.de>"]
license = "MIT"
Expand Down Expand Up @@ -40,7 +40,7 @@ nox = "^2022.8.7"

[tool.poetry.group.oemof-0-4-4.dependencies]
oemof-solph = "0.4.4"
tessif-oemof-4-4 = ">=0.1.4"
tessif-oemof-4-4 = ">=0.1.5"
click = "^8.1.3"
strutils = "^0.1.0"

Expand Down
44 changes: 39 additions & 5 deletions src/tessif/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# src/tessif/cli.py
"""Module providing the Tessif Command Line Interface (CLI)."""
import importlib

import os
import venv
import subprocess
import click

PLUGIN = "tessif-oemof-4-4"

tessif_dir = os.path.join(os.path.expanduser("~"), ".tessif.d")
venv_dir = os.path.join(tessif_dir, "plugin-venvs", PLUGIN)
python_bin = os.path.join(venv_dir, "bin", "python")


@click.group()
def main_cli_entry():
Expand All @@ -17,14 +25,34 @@ def greet():
click.echo("Hello World!")


@main_cli_entry.command()
@click.argument("plugin")
def install_plugin(plugin):
venv.create(venv_dir, upgrade_deps=True, with_pip=True)
subprocess.run(
[
python_bin,
"-m",
"pip",
"install",
plugin,
]
)


@main_cli_entry.command()
@click.option(
"--system_model_location",
help="Tessif System-Model Location",
"--directory",
help="Directory the system_model.tsf and the results are/will be stored in",
)
@click.argument("plugin")
def tropp(system_model_location, plugin):
def tropp(directory, plugin):
"""TRansform Optimize and Post-Process."""

system_model_location = os.path.join(directory, "tessif_system_model.tsf")
all_resultier_location = os.path.join(directory, "all_resutlier.alr")
igr_resultier_location = os.path.join(directory, "igr_resultier.igr")

click.echo("TRansform Optimize and Post-Process!\n")

module_name = plugin.replace("-", "_")
Expand Down Expand Up @@ -65,7 +93,13 @@ def tropp(system_model_location, plugin):
post_process = importlib.import_module(f"{module_name}.post_process")
global_resultier = post_process.IntegratedGlobalResultier(
optimized_system_model)
click.echo(global_resultier.global_results)
global_resultier.pickle(igr_resultier_location)
click.echo(f"Stored global results to {igr_resultier_location}")

all_resultier = post_process.AllResultier(optimized_system_model)
all_resultier.pickle(all_resultier_location)
click.echo(f"Stored all other results to {all_resultier_location}")


# if __name__ == '__main__':
# main_cli_entry()
49 changes: 35 additions & 14 deletions src/tessif/model/energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def pickle(self, location):
Parameters
----------
location: str, default = None
String representing of a path the created system model is dumped
String representing of a path the created system model is pickled
to. Passed to: meth: `pickle.dump`.
"""
pickle.dump(self.__dict__, open(location, "wb"))
Expand Down Expand Up @@ -437,22 +437,43 @@ def tropp(self, what=None, py="3.8", tool=None, version=None):
tempdir, "tessif_system_model.tsf")
self.pickle(system_model_location)

# subprocess.run(
# [
# "nox",
# "-f",
# # try absolutifying once fully ported
# "/home/tze/Matze/Codes/tsf_release/test_nox.py",
# "-R",
# "-s",
# registered_plugin,
# "--python",
# "3.8",
# "--",
# tempdir,
# ]
# )

PLUGIN = "tessif-oemof-4-4"

tessif_dir = os.path.join(os.path.expanduser("~"), ".tessif.d")
venv_dir = os.path.join(tessif_dir, "plugin-venvs", PLUGIN)
activation_script = os.path.join(venv_dir, "bin", "activate")

activation_command = f". {activation_script}; "
tropp_command = f"tessif tropp --directory {tempdir} {PLUGIN}"
subprocess.run(
[
"nox",
"-f",
# try absolutifying once fully ported
"/home/tze/Matze/Codes/tsf_release/test_nox.py",
"-R",
"-s",
registered_plugin,
"--python",
"3.8",
"--",
system_model_location,
]
activation_command + tropp_command,
shell=True,
check=True,
)

all_resultier = pickle.load(open(os.path.join(
tempdir, "all_resutlier.alr"), "rb"))
igr = pickle.load(open(os.path.join(
tempdir, "igr_resultier.igr"), "rb"))

return igr, all_resultier

@classmethod
def from_components(cls, uid, components, timeframe,
global_constraints={'emissions': float('+inf')},
Expand Down
Loading

0 comments on commit e8299db

Please sign in to comment.