zen-garden 2.8.3__tar.gz → 2.8.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {zen_garden-2.8.3 → zen_garden-2.8.5}/PKG-INFO +1 -1
  2. {zen_garden-2.8.3 → zen_garden-2.8.5}/pyproject.toml +1 -1
  3. zen_garden-2.8.5/zen_garden/postprocess/results/cache.py +52 -0
  4. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/results/results.py +2 -2
  5. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/results/solution_loader.py +7 -9
  6. {zen_garden-2.8.3 → zen_garden-2.8.5}/LICENSE.txt +0 -0
  7. {zen_garden-2.8.3 → zen_garden-2.8.5}/README.md +0 -0
  8. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/__init__.py +0 -0
  9. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/__main__.py +0 -0
  10. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/cli/__init__.py +0 -0
  11. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/cli/zen_example_cli.py +0 -0
  12. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/cli/zen_garden_cli.py +0 -0
  13. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/cli/zen_visualization_cli.py +0 -0
  14. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/default_config.py +0 -0
  15. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/__init__.py +0 -0
  16. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/carrier/__init__.py +0 -0
  17. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/carrier/carrier.py +0 -0
  18. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/component.py +0 -0
  19. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/element.py +0 -0
  20. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/energy_system.py +0 -0
  21. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/technology/__init__.py +0 -0
  22. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/technology/conversion_technology.py +0 -0
  23. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/technology/retrofitting_technology.py +0 -0
  24. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/technology/storage_technology.py +0 -0
  25. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/technology/technology.py +0 -0
  26. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/technology/transport_technology.py +0 -0
  27. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/model/time_steps.py +0 -0
  28. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/optimization_setup.py +0 -0
  29. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/.gitkeep +0 -0
  30. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/__init__.py +0 -0
  31. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/comparisons.py +0 -0
  32. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/postprocess.py +0 -0
  33. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/postprocess/results/__init__.py +0 -0
  34. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/preprocess/__init__.py +0 -0
  35. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/preprocess/extract_input_data.py +0 -0
  36. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/preprocess/parameter_change_log.py +0 -0
  37. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/preprocess/time_series_aggregation.py +0 -0
  38. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/preprocess/unit_handling.py +0 -0
  39. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/runner.py +0 -0
  40. {zen_garden-2.8.3 → zen_garden-2.8.5}/zen_garden/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zen_garden
3
- Version: 2.8.3
3
+ Version: 2.8.5
4
4
  Summary: ZEN-garden is an optimization model of energy systems and value chains.
5
5
  Author: Alissa Ganter, Johannes Burger, Francesco De Marco, Lukas Kunz, Lukas Schmidt-Engelbertz, Christoph Funke, Paolo Gabrielli, Giovanni Sansavini
6
6
  Author-email: Jacob Mannhardt <zen-garden@ethz.ch>
@@ -16,7 +16,7 @@ authors = [
16
16
  {name = "Giovanni Sansavini"},
17
17
  ]
18
18
  # do not change version manually! Done by bump2version
19
- version = "2.8.3"
19
+ version = "2.8.5"
20
20
  requires-python= ">=3.11,<3.14"
21
21
  description="ZEN-garden is an optimization model of energy systems and value chains."
22
22
  readme = "README.md"
@@ -0,0 +1,52 @@
1
+ import functools
2
+
3
+
4
+ class ConditionalCache:
5
+ """
6
+ Decorator to conditionally cache method results based on an instance flag.
7
+ If the flag is True, the method results are cached using functools.cache.
8
+ Otherwise, the method is called normally without caching.
9
+
10
+ ## Usage
11
+ ```
12
+ class MyClass:
13
+ def __init__(self, enable_cache: bool):
14
+ self.enable_cache = enable_cache
15
+
16
+ @ConditionalCache('enable_cache')
17
+ def my_method(self, ...):
18
+ # method implementation
19
+ pass
20
+ ```
21
+ """
22
+
23
+ def __init__(self, flag_name: str):
24
+ self.flag_name = flag_name
25
+
26
+ def __call__(self, func):
27
+ self.func = func
28
+ functools.update_wrapper(self, func)
29
+ return self
30
+
31
+ def __get__(self, instance, owner):
32
+ if instance is None:
33
+ return self
34
+
35
+ # Check if caching is enabled for this instance and get the bound method
36
+ enable_cache = getattr(instance, self.flag_name, False)
37
+ bound_func = self.func.__get__(instance, owner)
38
+
39
+ # If caching is disabled, return the original bound method
40
+ if not enable_cache:
41
+ return bound_func
42
+
43
+ # Check if the cached version already exists
44
+ cache_attr = f"__cached_{self.func.__name__}"
45
+ cached_func = getattr(instance, cache_attr, None)
46
+ if cached_func is not None:
47
+ return cached_func
48
+
49
+ # Create and store the cached version of the method
50
+ cached_func = functools.cache(bound_func)
51
+ setattr(instance, cache_attr, cached_func)
52
+ return cached_func
@@ -28,7 +28,7 @@ class Results:
28
28
  """
29
29
  The Results class is used to extract and process the results of a model run.
30
30
  """
31
- def __init__(self, path: str):
31
+ def __init__(self, path: str, enable_cache: bool = True):
32
32
  """
33
33
  Initializes the Results class.
34
34
 
@@ -36,7 +36,7 @@ class Results:
36
36
  """
37
37
  assert os.path.exists(path), f"The output folder {Path(path).absolute()} does not exist."
38
38
  assert len(os.listdir(path)) > 0, f"The output folder {Path(path).absolute()} is empty."
39
- self.solution_loader = SolutionLoader(path)
39
+ self.solution_loader = SolutionLoader(path, enable_cache=enable_cache)
40
40
  self.has_scenarios = len(self.solution_loader.scenarios) > 1
41
41
  first_scenario = next(iter(self.solution_loader.scenarios.values()))
42
42
  self.name = Path(first_scenario.analysis.dataset).name
@@ -14,9 +14,9 @@ import logging
14
14
 
15
15
  from typing import Optional, Any,Literal
16
16
  from enum import Enum
17
- from functools import cache
18
17
  from zen_garden.default_config import Analysis, System, Solver
19
18
  from zen_garden.utils import slice_df_by_index
19
+ from .cache import ConditionalCache
20
20
 
21
21
  class ComponentType(Enum):
22
22
  parameter: str = "parameter"
@@ -304,11 +304,12 @@ class SolutionLoader():
304
304
  Implementation of a SolutionLoader.
305
305
  """
306
306
 
307
- def __init__(self, path: str) -> None:
307
+ def __init__(self, path: str, enable_cache: bool = True) -> None:
308
308
  self.path = path
309
309
  assert len(os.listdir(path)) > 0, f"Path {path} is empty."
310
310
  self._scenarios: dict[str, Scenario] = self._read_scenarios()
311
311
  self._series_cache: dict[str, "pd.Series[Any]"] = {}
312
+ self.enable_cache = enable_cache
312
313
 
313
314
  @property
314
315
  def scenarios(self) -> dict[str, Scenario]:
@@ -395,7 +396,7 @@ class SolutionLoader():
395
396
  series.index.names = new_index_names
396
397
  return series
397
398
 
398
- @cache
399
+ @ConditionalCache("enable_cache")
399
400
  def get_component_data(
400
401
  self,
401
402
  scenario: Scenario,
@@ -492,7 +493,7 @@ class SolutionLoader():
492
493
 
493
494
  return ans
494
495
 
495
- @cache
496
+ @ConditionalCache("enable_cache")
496
497
  def get_timestep_duration(
497
498
  self, scenario: Scenario, component: Component
498
499
  ) -> "pd.Series[Any]":
@@ -523,9 +524,7 @@ class SolutionLoader():
523
524
 
524
525
  return time_step_duration
525
526
 
526
-
527
-
528
- @cache
527
+ @ConditionalCache("enable_cache")
529
528
  def get_timesteps(
530
529
  self, scenario: Scenario, component: Component, year: int
531
530
  ) -> "pd.Series[Any]":
@@ -556,7 +555,7 @@ class SolutionLoader():
556
555
 
557
556
  return ans
558
557
 
559
- @cache
558
+ @ConditionalCache("enable_cache")
560
559
  def get_timesteps_of_years(
561
560
  self, scenario: Scenario, ts_type: TimestepType, years: tuple
562
561
  ) -> "pd.DataFrame | pd.Series[Any]":
@@ -785,7 +784,6 @@ def get_has_units(h5_file: h5py.File,component_name: str,version: str) -> bool:
785
784
  raise ValueError(f"Value {has_units} for has_units not supported.")
786
785
  return has_units
787
786
 
788
- @cache
789
787
  def get_df_from_path(path: str, component_name: str, version: str, data_type: Literal["dataframe","units"] = "dataframe",index: Optional[tuple[str]] = None) -> "pd.Series[Any]":
790
788
  """
791
789
  Helper-function that returns a Pandas series given the path of a file and the
File without changes
File without changes