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.
- gamspy/__init__.py +86 -98
- gamspy/__main__.py +6 -6
- gamspy/_algebra/__init__.py +13 -13
- gamspy/_algebra/condition.py +290 -194
- gamspy/_algebra/domain.py +103 -93
- gamspy/_algebra/expression.py +820 -799
- gamspy/_algebra/number.py +79 -70
- gamspy/_algebra/operable.py +185 -185
- gamspy/_algebra/operation.py +948 -845
- gamspy/_backend/backend.py +313 -311
- gamspy/_backend/engine.py +960 -960
- gamspy/_backend/local.py +124 -124
- gamspy/_backend/neos.py +567 -567
- gamspy/_cli/__init__.py +1 -1
- gamspy/_cli/cli.py +64 -64
- gamspy/_cli/gdx.py +377 -377
- gamspy/_cli/install.py +375 -372
- gamspy/_cli/list.py +94 -94
- gamspy/_cli/mps2gms.py +128 -128
- gamspy/_cli/probe.py +52 -52
- gamspy/_cli/retrieve.py +79 -79
- gamspy/_cli/run.py +158 -158
- gamspy/_cli/show.py +246 -255
- gamspy/_cli/uninstall.py +165 -165
- gamspy/_cli/util.py +94 -94
- gamspy/_communication.py +215 -215
- gamspy/_config.py +132 -132
- gamspy/_container.py +1694 -1452
- gamspy/_convert.py +720 -720
- gamspy/_database.py +271 -271
- gamspy/_extrinsic.py +181 -181
- gamspy/_miro.py +356 -352
- gamspy/_model.py +1803 -1615
- gamspy/_model_instance.py +701 -701
- gamspy/_options.py +780 -700
- gamspy/_serialization.py +156 -144
- gamspy/_symbols/__init__.py +17 -17
- gamspy/_symbols/alias.py +305 -299
- gamspy/_symbols/equation.py +1407 -1298
- gamspy/_symbols/implicits/__init__.py +11 -11
- gamspy/_symbols/implicits/implicit_equation.py +186 -186
- gamspy/_symbols/implicits/implicit_parameter.py +272 -272
- gamspy/_symbols/implicits/implicit_set.py +124 -124
- gamspy/_symbols/implicits/implicit_symbol.py +315 -315
- gamspy/_symbols/implicits/implicit_variable.py +255 -255
- gamspy/_symbols/parameter.py +648 -609
- gamspy/_symbols/set.py +985 -923
- gamspy/_symbols/symbol.py +395 -386
- gamspy/_symbols/universe_alias.py +182 -182
- gamspy/_symbols/variable.py +1101 -1017
- gamspy/_types.py +7 -7
- gamspy/_validation.py +735 -735
- gamspy/_workspace.py +72 -72
- gamspy/exceptions.py +128 -128
- gamspy/formulations/__init__.py +46 -46
- gamspy/formulations/ml/__init__.py +11 -11
- gamspy/formulations/ml/decision_tree_struct.py +80 -80
- gamspy/formulations/ml/gradient_boosting.py +203 -203
- gamspy/formulations/ml/random_forest.py +187 -187
- gamspy/formulations/ml/regression_tree.py +533 -533
- gamspy/formulations/nn/__init__.py +19 -19
- gamspy/formulations/nn/avgpool2d.py +232 -232
- gamspy/formulations/nn/conv1d.py +533 -533
- gamspy/formulations/nn/conv2d.py +529 -529
- gamspy/formulations/nn/linear.py +341 -341
- gamspy/formulations/nn/maxpool2d.py +88 -88
- gamspy/formulations/nn/minpool2d.py +88 -88
- gamspy/formulations/nn/mpool2d.py +245 -245
- gamspy/formulations/nn/torch_sequential.py +278 -278
- gamspy/formulations/piecewise.py +682 -682
- gamspy/formulations/result.py +119 -119
- gamspy/formulations/shape.py +188 -188
- gamspy/formulations/utils.py +173 -173
- gamspy/math/__init__.py +215 -215
- gamspy/math/activation.py +783 -767
- gamspy/math/log_power.py +435 -435
- gamspy/math/matrix.py +534 -534
- gamspy/math/misc.py +1709 -1625
- gamspy/math/probability.py +170 -170
- gamspy/math/trigonometric.py +232 -232
- gamspy/utils.py +810 -791
- gamspy/version.py +5 -5
- {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/METADATA +90 -121
- gamspy-1.19.0.dist-info/RECORD +90 -0
- {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/WHEEL +1 -1
- {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/licenses/LICENSE +22 -22
- gamspy-1.18.3.dist-info/RECORD +0 -90
- {gamspy-1.18.3.dist-info → gamspy-1.19.0.dist-info}/entry_points.txt +0 -0
- {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()
|