pyoframe 0.0.4__tar.gz → 0.0.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 (32) hide show
  1. {pyoframe-0.0.4/src/pyoframe.egg-info → pyoframe-0.0.5}/PKG-INFO +9 -2
  2. {pyoframe-0.0.4 → pyoframe-0.0.5}/README.md +6 -0
  3. {pyoframe-0.0.4 → pyoframe-0.0.5}/pyproject.toml +8 -2
  4. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/__init__.py +12 -3
  5. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/_arithmetic.py +2 -5
  6. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/constants.py +15 -12
  7. pyoframe-0.0.4/src/pyoframe/constraints.py → pyoframe-0.0.5/src/pyoframe/core.py +490 -74
  8. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/io.py +51 -25
  9. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/io_mappers.py +49 -18
  10. pyoframe-0.0.5/src/pyoframe/model.py +115 -0
  11. pyoframe-0.0.5/src/pyoframe/model_element.py +222 -0
  12. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/monkey_patch.py +2 -2
  13. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/objective.py +16 -13
  14. pyoframe-0.0.5/src/pyoframe/solvers.py +353 -0
  15. pyoframe-0.0.5/src/pyoframe/user_defined.py +60 -0
  16. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe/util.py +56 -55
  17. {pyoframe-0.0.4 → pyoframe-0.0.5/src/pyoframe.egg-info}/PKG-INFO +9 -2
  18. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe.egg-info/SOURCES.txt +4 -3
  19. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe.egg-info/requires.txt +2 -1
  20. {pyoframe-0.0.4 → pyoframe-0.0.5}/tests/test_arithmetic.py +29 -9
  21. {pyoframe-0.0.4 → pyoframe-0.0.5}/tests/test_examples.py +17 -8
  22. {pyoframe-0.0.4 → pyoframe-0.0.5}/tests/test_io.py +1 -3
  23. pyoframe-0.0.5/tests/test_solver.py +162 -0
  24. pyoframe-0.0.4/src/pyoframe/model.py +0 -92
  25. pyoframe-0.0.4/src/pyoframe/model_element.py +0 -116
  26. pyoframe-0.0.4/src/pyoframe/solvers.py +0 -186
  27. pyoframe-0.0.4/src/pyoframe/variables.py +0 -193
  28. {pyoframe-0.0.4 → pyoframe-0.0.5}/LICENSE +0 -0
  29. {pyoframe-0.0.4 → pyoframe-0.0.5}/setup.cfg +0 -0
  30. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe.egg-info/dependency_links.txt +0 -0
  31. {pyoframe-0.0.4 → pyoframe-0.0.5}/src/pyoframe.egg-info/top_level.txt +0 -0
  32. {pyoframe-0.0.4 → pyoframe-0.0.5}/tests/test_operations.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyoframe
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: Blazing fast linear program interface
5
5
  Author-email: Bravos Power <dev@bravospower.com>
6
6
  Project-URL: Homepage, https://bravos-power.github.io/pyoframe/
@@ -15,10 +15,11 @@ Classifier: Natural Language :: English
15
15
  Requires-Python: >=3.8
16
16
  Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
- Requires-Dist: polars==0.20.13
18
+ Requires-Dist: polars
19
19
  Requires-Dist: numpy
20
20
  Requires-Dist: pyarrow
21
21
  Requires-Dist: pandas
22
+ Requires-Dist: tqdm
22
23
  Provides-Extra: dev
23
24
  Requires-Dist: black; extra == "dev"
24
25
  Requires-Dist: bumpver; extra == "dev"
@@ -56,3 +57,9 @@ Contributions are welcome! See [`CONTRIBUTE.md`](./CONTRIBUTE.md).
56
57
  ## Acknowledgments
57
58
 
58
59
  Martin Staadecker first created this library while working for [Bravos Power](https://www.bravospower.com/) The library takes inspiration from Linopy and Pyomo, two prior libraries for optimization for which we are thankful.
60
+
61
+ ## Troubleshooting Common Errors
62
+
63
+ ### `datatypes of join keys don't match`
64
+
65
+ Often, this error indicates that two dataframes in your inputs representing the same dimension have different datatypes (e.g. 16bit integer and 64bit integer). This is not allowed and you should ensure for the same dimensions, datatypes are identical.
@@ -17,3 +17,9 @@ Contributions are welcome! See [`CONTRIBUTE.md`](./CONTRIBUTE.md).
17
17
  ## Acknowledgments
18
18
 
19
19
  Martin Staadecker first created this library while working for [Bravos Power](https://www.bravospower.com/) The library takes inspiration from Linopy and Pyomo, two prior libraries for optimization for which we are thankful.
20
+
21
+ ## Troubleshooting Common Errors
22
+
23
+ ### `datatypes of join keys don't match`
24
+
25
+ Often, this error indicates that two dataframes in your inputs representing the same dimension have different datatypes (e.g. 16bit integer and 64bit integer). This is not allowed and you should ensure for the same dimensions, datatypes are identical.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pyoframe"
7
- version = "0.0.4"
7
+ version = "0.0.5"
8
8
  authors = [{ name = "Bravos Power", email = "dev@bravospower.com" }]
9
9
  description = "Blazing fast linear program interface"
10
10
  readme = "README.md"
@@ -16,7 +16,7 @@ classifiers = [
16
16
  "License :: OSI Approved :: MIT License",
17
17
  "Natural Language :: English",
18
18
  ]
19
- dependencies = ["polars==0.20.13", "numpy", "pyarrow", "pandas"]
19
+ dependencies = ["polars", "numpy", "pyarrow", "pandas", "tqdm"]
20
20
 
21
21
  [project.optional-dependencies]
22
22
  dev = [
@@ -42,6 +42,12 @@ docs = [
42
42
  [tool.isort]
43
43
  profile = "black"
44
44
 
45
+ [tool.coverage.run]
46
+ include = ["src/pyoframe/*"]
47
+
48
+ [tool.pytest.ini_options]
49
+ addopts = "--doctest-modules --ignore=scripts"
50
+
45
51
  [project.urls]
46
52
  Homepage = "https://bravos-power.github.io/pyoframe/"
47
53
  documentation = "https://bravos-power.github.io/pyoframe/"
@@ -4,12 +4,21 @@ Also applies the monkey patch to the DataFrame libraries.
4
4
  """
5
5
 
6
6
  from pyoframe.monkey_patch import patch_dataframe_libraries
7
- from pyoframe.constraints import sum, sum_by, Set, Constraint
7
+ from pyoframe.core import sum, sum_by, Set, Constraint, Expression, Variable
8
8
  from pyoframe.constants import Config
9
- from pyoframe.variables import Variable
10
9
  from pyoframe.model import Model
11
10
  from pyoframe.constants import VType
12
11
 
13
12
  patch_dataframe_libraries()
14
13
 
15
- __all__ = ["sum", "sum_by", "Variable", "Model", "Set", "VType", "Config", "Constraint"]
14
+ __all__ = [
15
+ "sum",
16
+ "sum_by",
17
+ "Variable",
18
+ "Model",
19
+ "Set",
20
+ "VType",
21
+ "Config",
22
+ "Constraint",
23
+ "Expression",
24
+ ]
@@ -7,14 +7,11 @@ from pyoframe.constants import (
7
7
  VAR_KEY,
8
8
  UnmatchedStrategy,
9
9
  Config,
10
+ PyoframeError,
10
11
  )
11
12
 
12
13
  if TYPE_CHECKING: # pragma: no cover
13
- from pyoframe.constraints import Expression
14
-
15
-
16
- class PyoframeError(Exception):
17
- pass
14
+ from pyoframe.core import Expression
18
15
 
19
16
 
20
17
  def _add_expressions(*expressions: "Expression") -> "Expression":
@@ -9,7 +9,7 @@ MIT License
9
9
  from dataclasses import dataclass
10
10
  from enum import Enum
11
11
  import typing
12
- from typing import Any, Literal, Optional, Union
12
+ from typing import Literal, Optional, Union
13
13
  import polars as pl
14
14
 
15
15
 
@@ -18,7 +18,8 @@ VAR_KEY = "__variable_id"
18
18
  CONSTRAINT_KEY = "__constraint_id"
19
19
  SOLUTION_KEY = "solution"
20
20
  DUAL_KEY = "dual"
21
- NAME_COL = "__name"
21
+ RC_COL = "RC"
22
+ SLACK_COL = "slack"
22
23
 
23
24
  CONST_TERM = 0
24
25
 
@@ -28,7 +29,8 @@ RESERVED_COL_KEYS = (
28
29
  CONSTRAINT_KEY,
29
30
  SOLUTION_KEY,
30
31
  DUAL_KEY,
31
- NAME_COL,
32
+ RC_COL,
33
+ SLACK_COL,
32
34
  )
33
35
 
34
36
 
@@ -48,6 +50,9 @@ class Config(metaclass=_ConfigMeta):
48
50
  disable_unmatched_checks: bool = False
49
51
  print_float_precision: Optional[int] = 5
50
52
  print_uses_variable_names: bool = True
53
+ # Number of elements to show when printing a set to the console (additional elements are replaced with ...)
54
+ print_max_set_elements: int = 50
55
+ enable_is_duplicated_expression_safety_check: bool = False
51
56
 
52
57
  @classmethod
53
58
  def reset_defaults(cls):
@@ -65,8 +70,8 @@ class ConstraintSense(Enum):
65
70
 
66
71
 
67
72
  class ObjSense(Enum):
68
- MIN = "minimize"
69
- MAX = "maximize"
73
+ MIN = "min"
74
+ MAX = "max"
70
75
 
71
76
 
72
77
  class VType(Enum):
@@ -83,7 +88,7 @@ class UnmatchedStrategy(Enum):
83
88
 
84
89
  # This is a hack to get the Literal type for VType
85
90
  # See: https://stackoverflow.com/questions/67292470/type-hinting-enum-member-value-in-python
86
- ObjSenseValue = Literal["minimize", "maximize"]
91
+ ObjSenseValue = Literal["min", "max"]
87
92
  VTypeValue = Literal["continuous", "binary", "integer"]
88
93
  for enum, type in [(ObjSense, ObjSenseValue), (VType, VTypeValue)]:
89
94
  assert set(typing.get_args(type)) == {vtype.value for vtype in enum}
@@ -248,13 +253,8 @@ class Result:
248
253
 
249
254
  status: Status
250
255
  solution: Optional[Solution] = None
251
- solver_model: Optional[Any] = None
252
256
 
253
257
  def __repr__(self) -> str:
254
- solver_model_string = (
255
- "not available" if self.solver_model is None else "available"
256
- )
257
-
258
258
  res = (
259
259
  f"Status: {self.status.status.value}\n"
260
260
  f"Termination condition: {self.status.termination_condition.value}\n"
@@ -264,7 +264,6 @@ class Result:
264
264
  f"Solution: {len(self.solution.primal)} primals, {len(self.solution.dual) if self.solution.dual is not None else 0} duals\n"
265
265
  f"Objective: {self.solution.objective:.2e}\n"
266
266
  )
267
- res += f"Solver model: {solver_model_string}\n"
268
267
 
269
268
  return res
270
269
 
@@ -278,3 +277,7 @@ class Result:
278
277
  print(f" Optimization successful: \n{self}\n")
279
278
  else:
280
279
  print(f"Optimization failed: \n{self}\n")
280
+
281
+
282
+ class PyoframeError(Exception):
283
+ pass