-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild_verify_install_sample.py
More file actions
90 lines (72 loc) · 2.76 KB
/
Copy pathbuild_verify_install_sample.py
File metadata and controls
90 lines (72 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Generate src/gdxpds/_verify_install/sample.gdx.
The resulting sample.gdx is committed to the repo; this script only needs to
be re-run if the schema of the install verification test changes.
Usage (from repo root, with the venv active and $env:GAMS_DIR set):
python dev\\build_verify_install_sample.py
Schema (chosen to exercise the distinct code paths gdxpds handles):
Set t : 1D wildcard root Set, 3 elements (domain_type == NONE)
Set sub_t : 1D subset of t, 2 elements (strict / REGULAR domain)
Parameter p : 2D over t x t, 6 records: 1 normal value + 5 specials
Variable v : 1D over t, exercises the 5-value-column shape
"""
import os
import numpy as np
import pandas as pd
import gdxpds
import gdxpds.gdx
OUT_PATH = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"..",
"src",
"gdxpds",
"_verify_install",
"sample.gdx",
)
)
def main():
eps = np.finfo(float).eps
# Pin the gdxcc oracle so the committed sample is written deterministically
# regardless of any ambient GDXPDS_ENGINE.
with gdxpds.gdx.GdxFile(engine="gdxcc") as gdx:
# Root Set with a wildcard domain: domain_type == NONE on read.
gdx.append(gdxpds.gdx.GdxSymbol("t", gdxpds.gdx.GamsDataType.Set, dims=["*"]))
gdx[-1].dataframe = pd.DataFrame(
[["a", True], ["b", True], ["c", True]], columns=["*", "Value"]
)
gdx.append(
gdxpds.gdx.GdxSymbol(
"sub_t", gdxpds.gdx.GamsDataType.Set, dims=["t"], domain=[gdx["t"]]
)
)
gdx[-1].dataframe = pd.DataFrame([["a", True], ["c", True]], columns=["t", "Value"])
gdx.append(gdxpds.gdx.GdxSymbol("p", gdxpds.gdx.GamsDataType.Parameter, dims=["t1", "t2"]))
gdx[-1].dataframe = pd.DataFrame(
[
["a", "a", 1.0],
["a", "b", None],
["b", "a", np.nan],
["b", "b", np.inf],
["c", "a", -np.inf],
["c", "b", eps],
],
columns=["t1", "t2", "Value"],
)
gdx.append(
gdxpds.gdx.GdxSymbol(
"v",
gdxpds.gdx.GamsDataType.Variable,
dims=["t"],
variable_type=gdxpds.gdx.GamsVariableType.Free,
)
)
v_df = pd.DataFrame([["a"], ["b"], ["c"]], columns=["t"])
for col in gdx[-1].value_col_names:
v_df[col] = gdx[-1].get_value_col_default(col)
v_df["Level"] = [10.0, 20.0, 30.0]
gdx[-1].dataframe = v_df
os.makedirs(os.path.dirname(OUT_PATH), exist_ok=True)
gdx.write(OUT_PATH)
print(f"Wrote {OUT_PATH} ({os.path.getsize(OUT_PATH)} bytes)")
if __name__ == "__main__":
main()