iesopt 2.2.0__tar.gz → 2.3.0__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,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: iesopt
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: IESopt -- an Integrated Energy System Optimization framework.
5
5
  Home-page: https://github.com/ait-energy/iesopt
6
6
  License: MIT
@@ -10,7 +10,7 @@ Author-email: 8915976+sstroemer@users.noreply.github.com
10
10
  Maintainer: Stefan Strömer
11
11
  Maintainer-email: 8915976+sstroemer@users.noreply.github.com
12
12
  Requires-Python: >=3.11,<4.0
13
- Classifier: Development Status :: 4 - Beta
13
+ Classifier: Development Status :: 5 - Production/Stable
14
14
  Classifier: Intended Audience :: Science/Research
15
15
  Classifier: License :: OSI Approved :: MIT License
16
16
  Classifier: Programming Language :: Python :: 3
@@ -24,7 +24,7 @@ Requires-Dist: pandas (>=2.0.0,<3.0.0)
24
24
  Requires-Dist: pathlib (>=1.0.0,<2.0.0)
25
25
  Requires-Dist: pydantic (>=2.7.4,<3.0.0)
26
26
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
27
- Project-URL: Changelog, https://github.com/ait-energy/iesopt/blob/main/CHANGELOG.md
27
+ Project-URL: Changelog, https://github.com/ait-energy/iesopt/releases
28
28
  Project-URL: Documentation, https://ait-energy.github.io/iesopt
29
29
  Project-URL: Issues, https://github.com/ait-energy/iesopt/issues
30
30
  Project-URL: Repository, https://github.com/ait-energy/iesopt
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "iesopt"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "IESopt -- an Integrated Energy System Optimization framework."
9
9
  keywords = ["integrated energy systems", "optimization", "energy model", "modelling"]
10
10
  authors = [
@@ -16,7 +16,7 @@ maintainers = [
16
16
  readme = "README.md"
17
17
  license = "MIT"
18
18
  classifiers = [
19
- "Development Status :: 4 - Beta",
19
+ "Development Status :: 5 - Production/Stable",
20
20
  "Intended Audience :: Science/Research",
21
21
  "License :: OSI Approved :: MIT License",
22
22
  "Programming Language :: Python :: 3.10",
@@ -29,7 +29,7 @@ repository = "https://github.com/ait-energy/iesopt"
29
29
 
30
30
  [tool.poetry.urls]
31
31
  "Issues" = "https://github.com/ait-energy/iesopt/issues"
32
- "Changelog" = "https://github.com/ait-energy/iesopt/blob/main/CHANGELOG.md"
32
+ "Changelog" = "https://github.com/ait-energy/iesopt/releases"
33
33
 
34
34
  [tool.poetry.dependencies]
35
35
  python = "^3.11"
@@ -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.1.0",
17
- "IESOPT_JUMP": "1.23.5",
18
- "IESOPT_SOLVER_HIGHS": "1.12.1",
16
+ "IESOPT_CORE": "2.3.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
 
@@ -16,6 +16,7 @@ def lookup_package(name: str):
16
16
  "gurobi": ("Gurobi", "2e9cd046-0924-5485-92f1-d5272153d98b"),
17
17
  "cplex": ("CPLEX", "a076750e-1247-5638-91d2-ce28b192dca0"),
18
18
  "ipopt": ("Ipopt", "b6b21f68-93f8-5de0-b562-5493be1d77c9"),
19
+ "pythoncall": ("PythonCall", "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"),
19
20
  }
20
21
 
21
22
  if name in lookup:
@@ -49,8 +50,10 @@ def setup_julia():
49
50
  )
50
51
 
51
52
  if Path("juliapkg.json").exists():
52
- logger.warning("Found `juliapkg.json` file; removing it to prevent potential conflicts")
53
- Path("juliapkg.json").unlink()
53
+ raise Exception("Found `juliapkg.json` file; remove it to prevent potential conflicts")
54
+
55
+ if (Path(__file__).parent / ".." / "juliapkg.json").exists():
56
+ (Path(__file__).parent / ".." / "juliapkg.json").unlink()
54
57
 
55
58
  # # Check for local SSL certificate file, that can interfere with Julia setup.
56
59
  # _ssl = None
@@ -66,6 +69,7 @@ def setup_julia():
66
69
 
67
70
  # Set Julia version.
68
71
  juliapkg.require_julia(f"={Config.get('julia')}", target=target)
72
+ # add_package(juliapkg.add, "pythoncall", "0.9.23", target)
69
73
 
70
74
  # Set versions of "core" packages.
71
75
  add_package(juliapkg.add, "jump", Config.get("jump"), target)
@@ -118,13 +122,21 @@ def setup_julia():
118
122
  logger.info(" Executable: %s" % juliapkg.executable())
119
123
  logger.info(" Project: %s" % juliapkg.project())
120
124
 
121
- custom_packages = list(Config.find("pkg_"))
125
+ custom_packages = list(Config.find("PKG_"))
122
126
  if len(custom_packages) > 0:
123
127
  logger.info("Installing custom Julia packages")
124
- 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
+
125
134
  for entry in custom_packages:
126
135
  name = entry[4:]
127
- 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}")
128
140
 
129
141
  # # Restoring potential SSL certificate.
130
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 str(jl_safe_seval(f"@doc {module}.{obj}"))
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