gamspy 1.18.3__py3-none-any.whl → 1.19.0__py3-none-any.whl

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 (89) hide show
  1. gamspy/__init__.py +86 -98
  2. gamspy/__main__.py +6 -6
  3. gamspy/_algebra/__init__.py +13 -13
  4. gamspy/_algebra/condition.py +290 -194
  5. gamspy/_algebra/domain.py +103 -93
  6. gamspy/_algebra/expression.py +820 -799
  7. gamspy/_algebra/number.py +79 -70
  8. gamspy/_algebra/operable.py +185 -185
  9. gamspy/_algebra/operation.py +948 -845
  10. gamspy/_backend/backend.py +313 -311
  11. gamspy/_backend/engine.py +960 -960
  12. gamspy/_backend/local.py +124 -124
  13. gamspy/_backend/neos.py +567 -567
  14. gamspy/_cli/__init__.py +1 -1
  15. gamspy/_cli/cli.py +64 -64
  16. gamspy/_cli/gdx.py +377 -377
  17. gamspy/_cli/install.py +375 -372
  18. gamspy/_cli/list.py +94 -94
  19. gamspy/_cli/mps2gms.py +128 -128
  20. gamspy/_cli/probe.py +52 -52
  21. gamspy/_cli/retrieve.py +79 -79
  22. gamspy/_cli/run.py +158 -158
  23. gamspy/_cli/show.py +246 -255
  24. gamspy/_cli/uninstall.py +165 -165
  25. gamspy/_cli/util.py +94 -94
  26. gamspy/_communication.py +215 -215
  27. gamspy/_config.py +132 -132
  28. gamspy/_container.py +1694 -1452
  29. gamspy/_convert.py +720 -720
  30. gamspy/_database.py +271 -271
  31. gamspy/_extrinsic.py +181 -181
  32. gamspy/_miro.py +356 -352
  33. gamspy/_model.py +1803 -1615
  34. gamspy/_model_instance.py +701 -701
  35. gamspy/_options.py +780 -700
  36. gamspy/_serialization.py +156 -144
  37. gamspy/_symbols/__init__.py +17 -17
  38. gamspy/_symbols/alias.py +305 -299
  39. gamspy/_symbols/equation.py +1407 -1298
  40. gamspy/_symbols/implicits/__init__.py +11 -11
  41. gamspy/_symbols/implicits/implicit_equation.py +186 -186
  42. gamspy/_symbols/implicits/implicit_parameter.py +272 -272
  43. gamspy/_symbols/implicits/implicit_set.py +124 -124
  44. gamspy/_symbols/implicits/implicit_symbol.py +315 -315
  45. gamspy/_symbols/implicits/implicit_variable.py +255 -255
  46. gamspy/_symbols/parameter.py +648 -609
  47. gamspy/_symbols/set.py +985 -923
  48. gamspy/_symbols/symbol.py +395 -386
  49. gamspy/_symbols/universe_alias.py +182 -182
  50. gamspy/_symbols/variable.py +1101 -1017
  51. gamspy/_types.py +7 -7
  52. gamspy/_validation.py +735 -735
  53. gamspy/_workspace.py +72 -72
  54. gamspy/exceptions.py +128 -128
  55. gamspy/formulations/__init__.py +46 -46
  56. gamspy/formulations/ml/__init__.py +11 -11
  57. gamspy/formulations/ml/decision_tree_struct.py +80 -80
  58. gamspy/formulations/ml/gradient_boosting.py +203 -203
  59. gamspy/formulations/ml/random_forest.py +187 -187
  60. gamspy/formulations/ml/regression_tree.py +533 -533
  61. gamspy/formulations/nn/__init__.py +19 -19
  62. gamspy/formulations/nn/avgpool2d.py +232 -232
  63. gamspy/formulations/nn/conv1d.py +533 -533
  64. gamspy/formulations/nn/conv2d.py +529 -529
  65. gamspy/formulations/nn/linear.py +341 -341
  66. gamspy/formulations/nn/maxpool2d.py +88 -88
  67. gamspy/formulations/nn/minpool2d.py +88 -88
  68. gamspy/formulations/nn/mpool2d.py +245 -245
  69. gamspy/formulations/nn/torch_sequential.py +278 -278
  70. gamspy/formulations/piecewise.py +682 -682
  71. gamspy/formulations/result.py +119 -119
  72. gamspy/formulations/shape.py +188 -188
  73. gamspy/formulations/utils.py +173 -173
  74. gamspy/math/__init__.py +215 -215
  75. gamspy/math/activation.py +783 -767
  76. gamspy/math/log_power.py +435 -435
  77. gamspy/math/matrix.py +534 -534
  78. gamspy/math/misc.py +1709 -1625
  79. gamspy/math/probability.py +170 -170
  80. gamspy/math/trigonometric.py +232 -232
  81. gamspy/utils.py +810 -791
  82. gamspy/version.py +5 -5
  83. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/METADATA +90 -121
  84. gamspy-1.19.0.dist-info/RECORD +90 -0
  85. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/WHEEL +1 -1
  86. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/licenses/LICENSE +22 -22
  87. gamspy-1.18.3.dist-info/RECORD +0 -90
  88. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/entry_points.txt +0 -0
  89. {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/top_level.txt +0 -0
gamspy/_cli/retrieve.py CHANGED
@@ -1,79 +1,79 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- import subprocess
5
-
6
- import certifi
7
- import typer
8
-
9
- import gamspy.utils as utils
10
- from gamspy.exceptions import ValidationError
11
-
12
- app = typer.Typer(
13
- rich_markup_mode="rich",
14
- short_help="To retrieve a license with another node's information.",
15
- help="[bold][yellow]Examples[/yellow][/bold]: gamspy retrieve license <access_code> [--input <input_path>.json] [--output <output_path>.json]",
16
- context_settings={"help_option_names": ["-h", "--help"]},
17
- )
18
-
19
-
20
- @app.command(
21
- short_help="Retrives the license with the given node information.",
22
- help="[bold][yellow]Examples[/yellow][/bold]: gamspy retrieve license <access_code> [--input <input_path>.json] [--output <output_path>.json]",
23
- )
24
- def license(
25
- access_code: str = typer.Argument(..., help="Access code of the license."),
26
- input: str = typer.Option(
27
- None,
28
- "--input",
29
- "-i",
30
- help="Input json file path to retrieve the license based on the node information.",
31
- ),
32
- output: str = typer.Option(
33
- None, "--output", "-o", help="Output path for the license file."
34
- ),
35
- checkout_duration: int | None = typer.Option(
36
- None,
37
- "--checkout-duration",
38
- "-c",
39
- help="Specifies a duration in hours to checkout a session.",
40
- ),
41
- ) -> None:
42
- if input is None or not os.path.isfile(input):
43
- raise ValidationError(
44
- f"Given path `{input}` is not a json file. Please use `gamspy retrieve license <access_code> -i <json_file_path>`"
45
- )
46
-
47
- if access_code is None:
48
- raise ValidationError(f"Given licence id `{access_code}` is not valid!")
49
-
50
- environment_variables = os.environ.copy()
51
- if "CURL_CA_BUNDLE" not in environment_variables:
52
- environment_variables["CURL_CA_BUNDLE"] = certifi.where()
53
-
54
- gamspy_base_dir = utils._get_gamspy_base_directory()
55
- command = [
56
- os.path.join(gamspy_base_dir, "gamsgetkey"),
57
- access_code,
58
- "-i",
59
- input,
60
- ]
61
- if checkout_duration:
62
- command.append("-c")
63
- command.append(str(checkout_duration))
64
-
65
- process = subprocess.run(
66
- command, text=True, capture_output=True, env=environment_variables
67
- )
68
-
69
- if process.returncode:
70
- raise ValidationError(process.stderr)
71
-
72
- print(process.stdout)
73
- if output:
74
- with open(output, "w") as file:
75
- file.write(process.stdout)
76
-
77
-
78
- if __name__ == "__main__":
79
- app()
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import subprocess
5
+
6
+ import certifi
7
+ import typer
8
+
9
+ import gamspy.utils as utils
10
+ from gamspy.exceptions import ValidationError
11
+
12
+ app = typer.Typer(
13
+ rich_markup_mode="rich",
14
+ short_help="To retrieve a license with another node's information.",
15
+ help="[bold][yellow]Examples[/yellow][/bold]: gamspy retrieve license <access_code> [--input <input_path>.json] [--output <output_path>.json]",
16
+ context_settings={"help_option_names": ["-h", "--help"]},
17
+ )
18
+
19
+
20
+ @app.command(
21
+ short_help="Retrives the license with the given node information.",
22
+ help="[bold][yellow]Examples[/yellow][/bold]: gamspy retrieve license <access_code> [--input <input_path>.json] [--output <output_path>.json]",
23
+ )
24
+ def license(
25
+ access_code: str = typer.Argument(..., help="Access code of the license."),
26
+ input: str = typer.Option(
27
+ None,
28
+ "--input",
29
+ "-i",
30
+ help="Input json file path to retrieve the license based on the node information.",
31
+ ),
32
+ output: str = typer.Option(
33
+ None, "--output", "-o", help="Output path for the license file."
34
+ ),
35
+ checkout_duration: int | None = typer.Option(
36
+ None,
37
+ "--checkout-duration",
38
+ "-c",
39
+ help="Specifies a duration in hours to checkout a session.",
40
+ ),
41
+ ) -> None:
42
+ if input is None or not os.path.isfile(input):
43
+ raise ValidationError(
44
+ f"Given path `{input}` is not a json file. Please use `gamspy retrieve license <access_code> -i <json_file_path>`"
45
+ )
46
+
47
+ if access_code is None:
48
+ raise ValidationError(f"Given licence id `{access_code}` is not valid!")
49
+
50
+ environment_variables = os.environ.copy()
51
+ if "CURL_CA_BUNDLE" not in environment_variables:
52
+ environment_variables["CURL_CA_BUNDLE"] = certifi.where()
53
+
54
+ gamspy_base_dir = utils._get_gamspy_base_directory()
55
+ command = [
56
+ os.path.join(gamspy_base_dir, "gamsgetkey"),
57
+ access_code,
58
+ "-i",
59
+ input,
60
+ ]
61
+ if checkout_duration:
62
+ command.append("-c")
63
+ command.append(str(checkout_duration))
64
+
65
+ process = subprocess.run(
66
+ command, text=True, capture_output=True, env=environment_variables
67
+ )
68
+
69
+ if process.returncode:
70
+ raise ValidationError(process.stderr)
71
+
72
+ print(process.stdout)
73
+ if output:
74
+ with open(output, "w") as file:
75
+ file.write(process.stdout)
76
+
77
+
78
+ if __name__ == "__main__":
79
+ app()
gamspy/_cli/run.py CHANGED
@@ -1,158 +1,158 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- import platform
5
- import subprocess
6
- import sys
7
- from enum import Enum
8
- from pathlib import Path # noqa: TC003
9
- from typing import Annotated, Optional
10
-
11
- import typer
12
-
13
- from gamspy.exceptions import ValidationError
14
-
15
- app = typer.Typer(
16
- rich_markup_mode="rich",
17
- short_help="To run your model with GAMS MIRO.",
18
- help="[bold][yellow]Examples[/yellow][/bold]: gamspy run miro [--path <path_to_miro>] [--model <path_to_model>]",
19
- context_settings={"help_option_names": ["-h", "--help"]},
20
- )
21
-
22
-
23
- class ModeEnum(str, Enum):
24
- config = "config"
25
- base = "base"
26
- deploy = "deploy"
27
-
28
-
29
- @app.command(
30
- help="[bold][yellow]Examples[/yellow][/bold]: gamspy run miro [--path <path_to_miro>] [--model <path_to_model>]",
31
- short_help="Runs a GAMSPY model with GAMS MIRO app.",
32
- )
33
- def miro(
34
- mode: Annotated[
35
- ModeEnum,
36
- typer.Option("--mode", "-m", help="Execution mode of MIRO"),
37
- ] = ModeEnum.base, # type: ignore
38
- path: Annotated[
39
- Optional[Path], # noqa: UP045
40
- typer.Option(
41
- "--path",
42
- "-p",
43
- exists=True,
44
- help="Path to the MIRO executable (.exe, .app, or .AppImage)",
45
- ),
46
- ] = None,
47
- skip_execution: Annotated[
48
- bool,
49
- typer.Option("--skip-execution", help="Whether to skip model execution."),
50
- ] = False,
51
- model: Annotated[
52
- Optional[Path], # noqa: UP045,
53
- typer.Option("--model", "-g", exists=True, help="Path to the GAMSPy model."),
54
- ] = None,
55
- args: Annotated[
56
- list[str] | None,
57
- typer.Argument(help="Arguments to the GAMSPy model."),
58
- ] = None,
59
- ) -> None:
60
- if model is None:
61
- typer.echo("--model must be provided to run MIRO", file=sys.stderr)
62
- sys.exit(1)
63
-
64
- model = os.path.abspath(model)
65
- execution_mode = mode.value
66
- path = os.getenv("MIRO_PATH", path)
67
-
68
- if path is None:
69
- path = path if path is not None else discover_miro()
70
-
71
- if path is None:
72
- raise ValidationError("--path must be provided to run MIRO")
73
-
74
- if platform.system() == "Darwin" and os.path.splitext(path)[1] == ".app":
75
- path = os.path.join(path, "Contents", "MacOS", "GAMS MIRO")
76
-
77
- # Initialize MIRO
78
- if not skip_execution:
79
- subprocess_env = os.environ.copy()
80
- subprocess_env["MIRO"] = "1"
81
- command = [sys.executable, model]
82
- if args is not None:
83
- command += args
84
-
85
- process = subprocess.run(
86
- command,
87
- env=subprocess_env,
88
- capture_output=True,
89
- text=True,
90
- encoding="utf-8",
91
- )
92
- if process.returncode != 0:
93
- typer.echo(process.stderr, file=sys.stderr)
94
- sys.exit(process.returncode)
95
-
96
- # Run MIRO
97
- subprocess_env = os.environ.copy()
98
- if execution_mode == "deploy":
99
- subprocess_env["MIRO_BUILD"] = "true"
100
- execution_mode = "base"
101
-
102
- subprocess_env["MIRO_MODEL_PATH"] = model
103
- subprocess_env["MIRO_MODE"] = execution_mode
104
- subprocess_env["MIRO_DEV_MODE"] = "true"
105
- subprocess_env["MIRO_USE_TMP"] = "false"
106
- subprocess_env["PYTHON_EXEC_PATH"] = sys.executable
107
-
108
- subprocess.run([path], env=subprocess_env, check=True)
109
-
110
-
111
- def discover_miro():
112
- system = platform.system()
113
- if system == "Linux":
114
- return None
115
-
116
- home = os.path.expanduser("~")
117
- standard_locations = {
118
- "Darwin": [
119
- os.path.join(
120
- "/",
121
- "Applications",
122
- "GAMS MIRO.app",
123
- "Contents",
124
- "MacOS",
125
- "GAMS MIRO",
126
- ),
127
- os.path.join(
128
- home,
129
- "Applications",
130
- "GAMS MIRO.app",
131
- "Contents",
132
- "MacOS",
133
- "GAMS MIRO",
134
- ),
135
- ],
136
- "Windows": [
137
- os.path.join("C:\\", "Program Files", "GAMS MIRO", "GAMS MIRO.exe"),
138
- os.path.join(
139
- home,
140
- "AppData",
141
- "Local",
142
- "Programs",
143
- "GAMS MIRO",
144
- "GAMS MIRO.exe",
145
- ),
146
- ],
147
- }
148
-
149
- if system in ("Darwin", "Windows"):
150
- for location in standard_locations[system]:
151
- if os.path.isfile(location):
152
- return location
153
-
154
- return None
155
-
156
-
157
- if __name__ == "__main__":
158
- app()
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import platform
5
+ import subprocess
6
+ import sys
7
+ from enum import Enum
8
+ from pathlib import Path # noqa: TC003
9
+ from typing import Annotated, Optional
10
+
11
+ import typer
12
+
13
+ from gamspy.exceptions import ValidationError
14
+
15
+ app = typer.Typer(
16
+ rich_markup_mode="rich",
17
+ short_help="To run your model with GAMS MIRO.",
18
+ help="[bold][yellow]Examples[/yellow][/bold]: gamspy run miro [--path <path_to_miro>] [--model <path_to_model>]",
19
+ context_settings={"help_option_names": ["-h", "--help"]},
20
+ )
21
+
22
+
23
+ class ModeEnum(str, Enum):
24
+ config = "config"
25
+ base = "base"
26
+ deploy = "deploy"
27
+
28
+
29
+ @app.command(
30
+ help="[bold][yellow]Examples[/yellow][/bold]: gamspy run miro [--path <path_to_miro>] [--model <path_to_model>]",
31
+ short_help="Runs a GAMSPY model with GAMS MIRO app.",
32
+ )
33
+ def miro(
34
+ mode: Annotated[
35
+ ModeEnum,
36
+ typer.Option("--mode", "-m", help="Execution mode of MIRO"),
37
+ ] = ModeEnum.base, # type: ignore
38
+ path: Annotated[
39
+ Optional[Path], # noqa: UP045
40
+ typer.Option(
41
+ "--path",
42
+ "-p",
43
+ exists=True,
44
+ help="Path to the MIRO executable (.exe, .app, or .AppImage)",
45
+ ),
46
+ ] = None,
47
+ skip_execution: Annotated[
48
+ bool,
49
+ typer.Option("--skip-execution", help="Whether to skip model execution."),
50
+ ] = False,
51
+ model: Annotated[
52
+ Optional[Path], # noqa: UP045,
53
+ typer.Option("--model", "-g", exists=True, help="Path to the GAMSPy model."),
54
+ ] = None,
55
+ args: Annotated[
56
+ list[str] | None,
57
+ typer.Argument(help="Arguments to the GAMSPy model."),
58
+ ] = None,
59
+ ) -> None:
60
+ if model is None:
61
+ typer.echo("--model must be provided to run MIRO", file=sys.stderr)
62
+ sys.exit(1)
63
+
64
+ model = os.path.abspath(model)
65
+ execution_mode = mode.value
66
+ path = os.getenv("MIRO_PATH", path)
67
+
68
+ if path is None:
69
+ path = path if path is not None else discover_miro()
70
+
71
+ if path is None:
72
+ raise ValidationError("--path must be provided to run MIRO")
73
+
74
+ if platform.system() == "Darwin" and os.path.splitext(path)[1] == ".app":
75
+ path = os.path.join(path, "Contents", "MacOS", "GAMS MIRO")
76
+
77
+ # Initialize MIRO
78
+ if not skip_execution:
79
+ subprocess_env = os.environ.copy()
80
+ subprocess_env["MIRO"] = "1"
81
+ command = [sys.executable, model]
82
+ if args is not None:
83
+ command += args
84
+
85
+ process = subprocess.run(
86
+ command,
87
+ env=subprocess_env,
88
+ capture_output=True,
89
+ text=True,
90
+ encoding="utf-8",
91
+ )
92
+ if process.returncode != 0:
93
+ typer.echo(process.stderr, file=sys.stderr)
94
+ sys.exit(process.returncode)
95
+
96
+ # Run MIRO
97
+ subprocess_env = os.environ.copy()
98
+ if execution_mode == "deploy":
99
+ subprocess_env["MIRO_BUILD"] = "true"
100
+ execution_mode = "base"
101
+
102
+ subprocess_env["MIRO_MODEL_PATH"] = model
103
+ subprocess_env["MIRO_MODE"] = execution_mode
104
+ subprocess_env["MIRO_DEV_MODE"] = "true"
105
+ subprocess_env["MIRO_USE_TMP"] = "false"
106
+ subprocess_env["PYTHON_EXEC_PATH"] = sys.executable
107
+
108
+ subprocess.run([path], env=subprocess_env, check=True)
109
+
110
+
111
+ def discover_miro():
112
+ system = platform.system()
113
+ if system == "Linux":
114
+ return None
115
+
116
+ home = os.path.expanduser("~")
117
+ standard_locations = {
118
+ "Darwin": [
119
+ os.path.join(
120
+ "/",
121
+ "Applications",
122
+ "GAMS MIRO.app",
123
+ "Contents",
124
+ "MacOS",
125
+ "GAMS MIRO",
126
+ ),
127
+ os.path.join(
128
+ home,
129
+ "Applications",
130
+ "GAMS MIRO.app",
131
+ "Contents",
132
+ "MacOS",
133
+ "GAMS MIRO",
134
+ ),
135
+ ],
136
+ "Windows": [
137
+ os.path.join("C:\\", "Program Files", "GAMS MIRO", "GAMS MIRO.exe"),
138
+ os.path.join(
139
+ home,
140
+ "AppData",
141
+ "Local",
142
+ "Programs",
143
+ "GAMS MIRO",
144
+ "GAMS MIRO.exe",
145
+ ),
146
+ ],
147
+ }
148
+
149
+ if system in ("Darwin", "Windows"):
150
+ for location in standard_locations[system]:
151
+ if os.path.isfile(location):
152
+ return location
153
+
154
+ return None
155
+
156
+
157
+ if __name__ == "__main__":
158
+ app()