iesopt 2.2.1__tar.gz → 2.4.2__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.
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: iesopt
3
- Version: 2.2.1
3
+ Version: 2.4.2
4
4
  Summary: IESopt -- an Integrated Energy System Optimization framework.
5
- Home-page: https://github.com/ait-energy/iesopt
6
5
  License: MIT
7
6
  Keywords: integrated energy systems,optimization,energy model,modelling
8
7
  Author: Stefan Strömer
@@ -26,6 +25,7 @@ Requires-Dist: pydantic (>=2.7.4,<3.0.0)
26
25
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
27
26
  Project-URL: Changelog, https://github.com/ait-energy/iesopt/releases
28
27
  Project-URL: Documentation, https://ait-energy.github.io/iesopt
28
+ Project-URL: Homepage, https://github.com/ait-energy/iesopt
29
29
  Project-URL: Issues, https://github.com/ait-energy/iesopt/issues
30
30
  Project-URL: Repository, https://github.com/ait-energy/iesopt
31
31
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "iesopt"
7
- version = "2.2.1"
7
+ version = "2.4.2"
8
8
  description = "IESopt -- an Integrated Energy System Optimization framework."
9
9
  keywords = ["integrated energy systems", "optimization", "energy model", "modelling"]
10
10
  authors = [
@@ -13,9 +13,9 @@ def _strtobool(val: str):
13
13
  class Config:
14
14
  DEFAULTS = {
15
15
  "IESOPT_JULIA": "1.11.2",
16
- "IESOPT_CORE": "2.2.0",
17
- "IESOPT_JUMP": "1.23.5",
18
- "IESOPT_SOLVER_HIGHS": "1.12.2",
16
+ "IESOPT_CORE": "2.4.0",
17
+ "IESOPT_JUMP": "1.23.6",
18
+ "IESOPT_SOLVER_HIGHS": "1.13.0",
19
19
  "IESOPT_MULTITHREADED": "no", # yes, no
20
20
  "IESOPT_OPTIMIZATION": "latency", # rapid, latency, normal, performance
21
21
  }
@@ -27,7 +27,7 @@ class Config:
27
27
  return
28
28
 
29
29
  cls._config = {
30
- k[7:].lower(): v
30
+ (k[7:] if k.startswith("IESOPT_PKG_") else k[7:].lower()): v
31
31
  for (k, v) in {
32
32
  **cls.DEFAULTS,
33
33
  **dotenv_values(),
@@ -4,7 +4,7 @@ from pathlib import Path
4
4
  # import ssl
5
5
 
6
6
  from ..util import logger
7
- from .util import jl_import, jl_safe_seval
7
+ from .util import jl_import
8
8
  from ..config import Config
9
9
 
10
10
 
@@ -122,13 +122,21 @@ def setup_julia():
122
122
  logger.info(" Executable: %s" % juliapkg.executable())
123
123
  logger.info(" Project: %s" % juliapkg.project())
124
124
 
125
- custom_packages = list(Config.find("pkg_"))
125
+ custom_packages = list(Config.find("PKG_"))
126
126
  if len(custom_packages) > 0:
127
127
  logger.info("Installing custom Julia packages")
128
- jl_import("Pkg")
128
+
129
+ try:
130
+ juliacall.Main.seval("import Pkg")
131
+ except Exception as e:
132
+ logger.error(f"Failed to import Julia `Pkg`: {e}")
133
+
129
134
  for entry in custom_packages:
130
135
  name = entry[4:]
131
- jl_safe_seval(f"Pkg.add(Pkg.{name})")
136
+ try:
137
+ juliacall.Pkg.add(name=name, version=Config.get(entry))
138
+ except Exception as e:
139
+ logger.error(f"Failed to install custom package '{name}': {e}")
132
140
 
133
141
  # # Restoring potential SSL certificate.
134
142
  # if _ssl is not None:
@@ -7,6 +7,7 @@ def jl_safe_seval(code: str):
7
7
  return get_iesopt_module_attr("julia").seval(code)
8
8
  except Exception as e:
9
9
  logger.error("Exception while trying to execute Julia code: `%s`" % code)
10
+ logger.error("Exception: `%s`" % str(e))
10
11
  logger.error("Exception details: `%s`" % getattr(e, "exception", "missing"))
11
12
 
12
13
  return None
@@ -57,7 +58,10 @@ def jl_isa(obj, julia_type: str):
57
58
 
58
59
  def jl_docs(obj: str, module: str = "IESopt"):
59
60
  """Get the documentation string of a Julia object inside the IESopt module."""
60
- return "".join(el for el in jl_safe_seval(f"@doc {module}.{obj}").text)
61
+ julia_docstr = jl_safe_seval(f"@doc {module}.{obj}")
62
+ if julia_docstr is None:
63
+ return "Missing documentation string."
64
+ return "".join(el for el in julia_docstr.text)
61
65
 
62
66
 
63
67
  def recursive_convert_py2jl(item):
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
  from warnings import warn
4
4
 
5
5
  from .util import logger, get_iesopt_module_attr
6
- from .julia.util import jl_symbol, recursive_convert_py2jl
6
+ from .julia.util import jl_symbol, recursive_convert_py2jl, jl_safe_seval
7
7
  from .results import Results
8
8
 
9
9
 
@@ -111,6 +111,58 @@ class Model:
111
111
  except Exception as e:
112
112
  logger.error("Failed to extract debugging info")
113
113
 
114
+ def write_to_file(self, filename=None, *, format: str = "automatic") -> str:
115
+ """Write the model to a file.
116
+
117
+ Consult the Julia version of this function, [IESopt.write_to_file](https://ait-energy.github.io/iesopt/pages/manual/julia/index.html#write-to-file)
118
+ for more information. This will automatically invoke `generate` if the model has not been generated yet.
119
+
120
+ Arguments:
121
+ filename (Optional[str]): The filename to write to. If `None`, the path and name are automatically
122
+ determined by IESopt.
123
+
124
+ Keyword Arguments:
125
+ format (str): The format to write the file in. If `automatic`, the format is determined based on the
126
+ extension of the filename. Otherwise, it used as input to [`JuMP.write_to_file`](https://jump.dev/JuMP.jl/stable/api/JuMP/#write_to_file),
127
+ by converting to uppercase and prefixing it with `MOI.FileFormats.FORMAT_`. Writing to, e.g.,
128
+ an LP file can be done by setting `format="lp"` or `format="LP"`.
129
+
130
+ Returns:
131
+ str: The filename (including path) of the written file.
132
+
133
+ Examples:
134
+ .. code-block:: python
135
+ :caption: Writing a model to a problem file.
136
+
137
+ import iesopt
138
+
139
+ cfg = iesopt.make_example("01_basic_single_node", dst_dir="opt")
140
+
141
+ # Model will be automatically generated when calling `write_to_file`:
142
+ model = iesopt.Model(cfg)
143
+ model.write_to_file()
144
+
145
+ # It also works with already optimized models:
146
+ model = iesopt.run(cfg)
147
+ model.write_to_file("opt/out/my_problem.LP")
148
+
149
+ # And supports different formats:
150
+ target = model.write_to_file("opt/out/my_problem.foo", format="mof")
151
+ print(target)
152
+ """
153
+ if self._status == ModelStatus.EMPTY:
154
+ self.generate()
155
+
156
+ try:
157
+ if filename is None:
158
+ return self._IESopt.write_to_file(self.core)
159
+ else:
160
+ format = jl_safe_seval(f"JuMP.MOI.FileFormats.FORMAT_{format.upper()}")
161
+ return self._IESopt.write_to_file(self.core, str(filename), format=format)
162
+ except Exception as e:
163
+ logger.error(f"Error while writing model to file: {e}")
164
+ return ""
165
+
114
166
  def optimize(self) -> None:
115
167
  """Optimize the model."""
116
168
  try:
@@ -126,6 +178,9 @@ class Model:
126
178
  _term_status = self._JuMP.termination_status(self.core)
127
179
  if str(_term_status) == "INFEASIBLE":
128
180
  self._status = ModelStatus.INFEASIBLE
181
+ logger.error(
182
+ "The model seems to be infeasible; refer to `model.compute_iis()` and its documentation if you want to know more about the source of the infeasibility."
183
+ )
129
184
  elif str(_term_status) == "INFEASIBLE_OR_UNBOUNDED":
130
185
  self._status = ModelStatus.INFEASIBLE_OR_UNBOUNDED
131
186
  else:
@@ -139,6 +194,35 @@ class Model:
139
194
  except Exception as e:
140
195
  logger.error("Failed to extract debugging info")
141
196
 
197
+ def compute_iis(self, filename=None) -> None:
198
+ """Compute and print the Irreducible Infeasible Set (IIS) of the model, or optionally write it to a file.
199
+
200
+ Note that this requires a solver that supports IIS computation.
201
+
202
+ Arguments:
203
+ filename (Optional[str | Path]): The filename to write the IIS to. If `None`, the IIS is only printed to the
204
+ console.
205
+
206
+ Examples:
207
+ .. code-block:: python
208
+ :caption: Computing the IIS of a model.
209
+
210
+ import iesopt
211
+
212
+ model = iesopt.run("infeasible_model.iesopt.yaml")
213
+ model.compute_iis()
214
+
215
+ # or (arbitrary filename/extension):
216
+ model.compute_iis(filename="my_problem.txt")
217
+ """
218
+ try:
219
+ if filename is None:
220
+ self._IESopt.compute_IIS(self.core)
221
+ else:
222
+ self._IESopt.compute_IIS(self.core, filename=str(filename))
223
+ except Exception as e:
224
+ logger.error("Error while computing IIS: `%s`" % str(e.args[0]))
225
+
142
226
  @property
143
227
  def results(self) -> Results:
144
228
  """Get the results of the model."""
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes