gamsapi 52.5.0__cp312-cp312-win_amd64.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 (257) hide show
  1. gams/__init__.py +27 -0
  2. gams/_version.py +1 -0
  3. gams/connect/__init__.py +28 -0
  4. gams/connect/agents/__init__.py +24 -0
  5. gams/connect/agents/_excel/__init__.py +32 -0
  6. gams/connect/agents/_excel/excelagent.py +312 -0
  7. gams/connect/agents/_excel/workbook.py +155 -0
  8. gams/connect/agents/_sqlconnectors/__init__.py +42 -0
  9. gams/connect/agents/_sqlconnectors/_accesshandler.py +211 -0
  10. gams/connect/agents/_sqlconnectors/_databasehandler.py +250 -0
  11. gams/connect/agents/_sqlconnectors/_mysqlhandler.py +168 -0
  12. gams/connect/agents/_sqlconnectors/_postgreshandler.py +131 -0
  13. gams/connect/agents/_sqlconnectors/_pyodbchandler.py +112 -0
  14. gams/connect/agents/_sqlconnectors/_sqlalchemyhandler.py +74 -0
  15. gams/connect/agents/_sqlconnectors/_sqlitehandler.py +262 -0
  16. gams/connect/agents/_sqlconnectors/_sqlserverhandler.py +179 -0
  17. gams/connect/agents/concatenate.py +440 -0
  18. gams/connect/agents/connectagent.py +743 -0
  19. gams/connect/agents/csvreader.py +675 -0
  20. gams/connect/agents/csvwriter.py +151 -0
  21. gams/connect/agents/domainwriter.py +143 -0
  22. gams/connect/agents/excelreader.py +756 -0
  23. gams/connect/agents/excelwriter.py +467 -0
  24. gams/connect/agents/filter.py +223 -0
  25. gams/connect/agents/gamsreader.py +112 -0
  26. gams/connect/agents/gamswriter.py +239 -0
  27. gams/connect/agents/gdxreader.py +109 -0
  28. gams/connect/agents/gdxwriter.py +146 -0
  29. gams/connect/agents/labelmanipulator.py +303 -0
  30. gams/connect/agents/projection.py +539 -0
  31. gams/connect/agents/pythoncode.py +71 -0
  32. gams/connect/agents/rawcsvreader.py +248 -0
  33. gams/connect/agents/rawexcelreader.py +312 -0
  34. gams/connect/agents/schema/CSVReader.yaml +92 -0
  35. gams/connect/agents/schema/CSVWriter.yaml +44 -0
  36. gams/connect/agents/schema/Concatenate.yaml +52 -0
  37. gams/connect/agents/schema/DomainWriter.yaml +25 -0
  38. gams/connect/agents/schema/ExcelReader.yaml +121 -0
  39. gams/connect/agents/schema/ExcelWriter.yaml +78 -0
  40. gams/connect/agents/schema/Filter.yaml +74 -0
  41. gams/connect/agents/schema/GAMSReader.yaml +20 -0
  42. gams/connect/agents/schema/GAMSWriter.yaml +47 -0
  43. gams/connect/agents/schema/GDXReader.yaml +23 -0
  44. gams/connect/agents/schema/GDXWriter.yaml +32 -0
  45. gams/connect/agents/schema/LabelManipulator.yaml +99 -0
  46. gams/connect/agents/schema/Projection.yaml +24 -0
  47. gams/connect/agents/schema/PythonCode.yaml +6 -0
  48. gams/connect/agents/schema/RawCSVReader.yaml +34 -0
  49. gams/connect/agents/schema/RawExcelReader.yaml +42 -0
  50. gams/connect/agents/schema/SQLReader.yaml +75 -0
  51. gams/connect/agents/schema/SQLWriter.yaml +103 -0
  52. gams/connect/agents/sqlreader.py +301 -0
  53. gams/connect/agents/sqlwriter.py +276 -0
  54. gams/connect/connectdatabase.py +275 -0
  55. gams/connect/connectvalidator.py +93 -0
  56. gams/connect/errors.py +34 -0
  57. gams/control/__init__.py +136 -0
  58. gams/control/database.py +2231 -0
  59. gams/control/execution.py +1900 -0
  60. gams/control/options.py +2792 -0
  61. gams/control/workspace.py +1198 -0
  62. gams/core/__init__.py +24 -0
  63. gams/core/cfg/__init__.py +26 -0
  64. gams/core/cfg/_cfgmcc.cp312-win_amd64.pyd +0 -0
  65. gams/core/cfg/cfgmcc.py +519 -0
  66. gams/core/dct/__init__.py +26 -0
  67. gams/core/dct/_dctmcc.cp312-win_amd64.pyd +0 -0
  68. gams/core/dct/dctmcc.py +574 -0
  69. gams/core/embedded/__init__.py +26 -0
  70. gams/core/embedded/gamsemb.py +1024 -0
  71. gams/core/emp/__init__.py +24 -0
  72. gams/core/emp/emplexer.py +89 -0
  73. gams/core/emp/empyacc.py +281 -0
  74. gams/core/gdx/__init__.py +26 -0
  75. gams/core/gdx/_gdxcc.cp312-win_amd64.pyd +0 -0
  76. gams/core/gdx/gdxcc.py +866 -0
  77. gams/core/gev/__init__.py +26 -0
  78. gams/core/gev/_gevmcc.cp312-win_amd64.pyd +0 -0
  79. gams/core/gev/gevmcc.py +855 -0
  80. gams/core/gmd/__init__.py +26 -0
  81. gams/core/gmd/_gmdcc.cp312-win_amd64.pyd +0 -0
  82. gams/core/gmd/gmdcc.py +917 -0
  83. gams/core/gmo/__init__.py +26 -0
  84. gams/core/gmo/_gmomcc.cp312-win_amd64.pyd +0 -0
  85. gams/core/gmo/gmomcc.py +2046 -0
  86. gams/core/idx/__init__.py +26 -0
  87. gams/core/idx/_idxcc.cp312-win_amd64.pyd +0 -0
  88. gams/core/idx/idxcc.py +510 -0
  89. gams/core/numpy/__init__.py +29 -0
  90. gams/core/numpy/_gams2numpy.cp312-win_amd64.pyd +0 -0
  91. gams/core/numpy/gams2numpy.py +1048 -0
  92. gams/core/opt/__init__.py +26 -0
  93. gams/core/opt/_optcc.cp312-win_amd64.pyd +0 -0
  94. gams/core/opt/optcc.py +840 -0
  95. gams/engine/__init__.py +204 -0
  96. gams/engine/api/__init__.py +13 -0
  97. gams/engine/api/auth_api.py +7653 -0
  98. gams/engine/api/cleanup_api.py +751 -0
  99. gams/engine/api/default_api.py +887 -0
  100. gams/engine/api/hypercube_api.py +2629 -0
  101. gams/engine/api/jobs_api.py +5229 -0
  102. gams/engine/api/licenses_api.py +2220 -0
  103. gams/engine/api/namespaces_api.py +7783 -0
  104. gams/engine/api/usage_api.py +5627 -0
  105. gams/engine/api/users_api.py +5931 -0
  106. gams/engine/api_client.py +804 -0
  107. gams/engine/api_response.py +21 -0
  108. gams/engine/configuration.py +601 -0
  109. gams/engine/exceptions.py +216 -0
  110. gams/engine/models/__init__.py +86 -0
  111. gams/engine/models/bad_input.py +89 -0
  112. gams/engine/models/cleanable_job_result.py +104 -0
  113. gams/engine/models/cleanable_job_result_page.py +113 -0
  114. gams/engine/models/engine_license.py +107 -0
  115. gams/engine/models/files_not_found.py +93 -0
  116. gams/engine/models/forwarded_token_response.py +112 -0
  117. gams/engine/models/generic_key_value_pair.py +89 -0
  118. gams/engine/models/hypercube.py +160 -0
  119. gams/engine/models/hypercube_page.py +111 -0
  120. gams/engine/models/hypercube_summary.py +91 -0
  121. gams/engine/models/hypercube_token.py +97 -0
  122. gams/engine/models/identity_provider.py +107 -0
  123. gams/engine/models/identity_provider_ldap.py +121 -0
  124. gams/engine/models/identity_provider_oauth2.py +146 -0
  125. gams/engine/models/identity_provider_oauth2_scope.py +89 -0
  126. gams/engine/models/identity_provider_oauth2_with_secret.py +152 -0
  127. gams/engine/models/identity_provider_oidc.py +133 -0
  128. gams/engine/models/identity_provider_oidc_with_secret.py +143 -0
  129. gams/engine/models/inex.py +91 -0
  130. gams/engine/models/invitation.py +136 -0
  131. gams/engine/models/invitation_quota.py +106 -0
  132. gams/engine/models/invitation_token.py +87 -0
  133. gams/engine/models/job.py +165 -0
  134. gams/engine/models/job_no_text_entry.py +138 -0
  135. gams/engine/models/job_no_text_entry_page.py +111 -0
  136. gams/engine/models/license.py +91 -0
  137. gams/engine/models/log_piece.py +96 -0
  138. gams/engine/models/message.py +87 -0
  139. gams/engine/models/message_and_token.py +99 -0
  140. gams/engine/models/message_with_webhook_id.py +89 -0
  141. gams/engine/models/model_auth_token.py +87 -0
  142. gams/engine/models/model_configuration.py +125 -0
  143. gams/engine/models/model_default_instance.py +99 -0
  144. gams/engine/models/model_default_user_instance.py +98 -0
  145. gams/engine/models/model_hypercube_job.py +106 -0
  146. gams/engine/models/model_hypercube_usage.py +130 -0
  147. gams/engine/models/model_instance_info.py +116 -0
  148. gams/engine/models/model_instance_info_full.py +123 -0
  149. gams/engine/models/model_instance_pool_info.py +112 -0
  150. gams/engine/models/model_job_labels.py +179 -0
  151. gams/engine/models/model_job_usage.py +133 -0
  152. gams/engine/models/model_pool_usage.py +124 -0
  153. gams/engine/models/model_usage.py +115 -0
  154. gams/engine/models/model_user.py +96 -0
  155. gams/engine/models/model_userinstance_info.py +119 -0
  156. gams/engine/models/model_userinstancepool_info.py +95 -0
  157. gams/engine/models/model_version.py +91 -0
  158. gams/engine/models/models.py +120 -0
  159. gams/engine/models/namespace.py +104 -0
  160. gams/engine/models/namespace_quota.py +96 -0
  161. gams/engine/models/namespace_with_permission.py +96 -0
  162. gams/engine/models/not_found.py +91 -0
  163. gams/engine/models/password_policy.py +97 -0
  164. gams/engine/models/perm_and_username.py +89 -0
  165. gams/engine/models/quota.py +117 -0
  166. gams/engine/models/quota_exceeded.py +97 -0
  167. gams/engine/models/status_code_meaning.py +89 -0
  168. gams/engine/models/stream_entry.py +89 -0
  169. gams/engine/models/system_wide_license.py +92 -0
  170. gams/engine/models/text_entries.py +87 -0
  171. gams/engine/models/text_entry.py +101 -0
  172. gams/engine/models/time_span.py +95 -0
  173. gams/engine/models/time_span_pool_worker.py +99 -0
  174. gams/engine/models/token_forward_error.py +87 -0
  175. gams/engine/models/user.py +127 -0
  176. gams/engine/models/user_group_member.py +96 -0
  177. gams/engine/models/user_groups.py +108 -0
  178. gams/engine/models/vapid_info.py +87 -0
  179. gams/engine/models/webhook.py +138 -0
  180. gams/engine/models/webhook_parameterized_event.py +99 -0
  181. gams/engine/py.typed +0 -0
  182. gams/engine/rest.py +258 -0
  183. gams/magic/__init__.py +32 -0
  184. gams/magic/gams_magic.py +142 -0
  185. gams/magic/interactive.py +402 -0
  186. gams/tools/__init__.py +30 -0
  187. gams/tools/errors.py +34 -0
  188. gams/tools/toolcollection/__init__.py +24 -0
  189. gams/tools/toolcollection/alg/__init__.py +24 -0
  190. gams/tools/toolcollection/alg/rank.py +51 -0
  191. gams/tools/toolcollection/data/__init__.py +24 -0
  192. gams/tools/toolcollection/data/csvread.py +444 -0
  193. gams/tools/toolcollection/data/csvwrite.py +311 -0
  194. gams/tools/toolcollection/data/exceldump.py +47 -0
  195. gams/tools/toolcollection/data/sqlitewrite.py +276 -0
  196. gams/tools/toolcollection/gdxservice/__init__.py +24 -0
  197. gams/tools/toolcollection/gdxservice/gdxencoding.py +104 -0
  198. gams/tools/toolcollection/gdxservice/gdxrename.py +94 -0
  199. gams/tools/toolcollection/linalg/__init__.py +24 -0
  200. gams/tools/toolcollection/linalg/cholesky.py +57 -0
  201. gams/tools/toolcollection/linalg/eigenvalue.py +56 -0
  202. gams/tools/toolcollection/linalg/eigenvector.py +58 -0
  203. gams/tools/toolcollection/linalg/invert.py +55 -0
  204. gams/tools/toolcollection/linalg/ols.py +138 -0
  205. gams/tools/toolcollection/tooltemplate.py +321 -0
  206. gams/tools/toolcollection/win32/__init__.py +24 -0
  207. gams/tools/toolcollection/win32/excelmerge.py +93 -0
  208. gams/tools/toolcollection/win32/exceltalk.py +76 -0
  209. gams/tools/toolcollection/win32/msappavail.py +49 -0
  210. gams/tools/toolcollection/win32/shellexecute.py +54 -0
  211. gams/tools/tools.py +116 -0
  212. gams/transfer/__init__.py +35 -0
  213. gams/transfer/_abcs/__init__.py +37 -0
  214. gams/transfer/_abcs/container_abcs.py +433 -0
  215. gams/transfer/_internals/__init__.py +63 -0
  216. gams/transfer/_internals/algorithms.py +436 -0
  217. gams/transfer/_internals/casepreservingdict.py +124 -0
  218. gams/transfer/_internals/constants.py +270 -0
  219. gams/transfer/_internals/domainviolation.py +103 -0
  220. gams/transfer/_internals/specialvalues.py +172 -0
  221. gams/transfer/containers/__init__.py +26 -0
  222. gams/transfer/containers/_container.py +1794 -0
  223. gams/transfer/containers/_io/__init__.py +28 -0
  224. gams/transfer/containers/_io/containers.py +164 -0
  225. gams/transfer/containers/_io/gdx.py +1029 -0
  226. gams/transfer/containers/_io/gmd.py +872 -0
  227. gams/transfer/containers/_mixins/__init__.py +26 -0
  228. gams/transfer/containers/_mixins/ccc.py +1274 -0
  229. gams/transfer/syms/__init__.py +33 -0
  230. gams/transfer/syms/_methods/__init__.py +24 -0
  231. gams/transfer/syms/_methods/tables.py +120 -0
  232. gams/transfer/syms/_methods/toDict.py +115 -0
  233. gams/transfer/syms/_methods/toList.py +83 -0
  234. gams/transfer/syms/_methods/toValue.py +60 -0
  235. gams/transfer/syms/_mixins/__init__.py +32 -0
  236. gams/transfer/syms/_mixins/equals.py +626 -0
  237. gams/transfer/syms/_mixins/generateRecords.py +499 -0
  238. gams/transfer/syms/_mixins/pivot.py +313 -0
  239. gams/transfer/syms/_mixins/pve.py +627 -0
  240. gams/transfer/syms/_mixins/sa.py +27 -0
  241. gams/transfer/syms/_mixins/sapve.py +27 -0
  242. gams/transfer/syms/_mixins/saua.py +27 -0
  243. gams/transfer/syms/_mixins/sauapve.py +199 -0
  244. gams/transfer/syms/_mixins/spve.py +1528 -0
  245. gams/transfer/syms/_mixins/ve.py +936 -0
  246. gams/transfer/syms/container_syms/__init__.py +31 -0
  247. gams/transfer/syms/container_syms/_alias.py +984 -0
  248. gams/transfer/syms/container_syms/_equation.py +333 -0
  249. gams/transfer/syms/container_syms/_parameter.py +973 -0
  250. gams/transfer/syms/container_syms/_set.py +604 -0
  251. gams/transfer/syms/container_syms/_universe_alias.py +461 -0
  252. gams/transfer/syms/container_syms/_variable.py +321 -0
  253. gamsapi-52.5.0.dist-info/METADATA +150 -0
  254. gamsapi-52.5.0.dist-info/RECORD +257 -0
  255. gamsapi-52.5.0.dist-info/WHEEL +5 -0
  256. gamsapi-52.5.0.dist-info/licenses/LICENSE +22 -0
  257. gamsapi-52.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,872 @@
1
+ #
2
+ # GAMS - General Algebraic Modeling System Python API
3
+ #
4
+ # Copyright (c) 2017-2026 GAMS Development Corp. <support@gams.com>
5
+ # Copyright (c) 2017-2026 GAMS Software GmbH <support@gams.com>
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+
26
+ import copy
27
+ import pandas as pd
28
+ import numpy as np
29
+ from gams.core import gmd
30
+ import gams.transfer._abcs as abcs
31
+ from gams.transfer.syms import (
32
+ Set,
33
+ Parameter,
34
+ Variable,
35
+ Equation,
36
+ Alias,
37
+ UniverseAlias,
38
+ )
39
+ from gams.transfer._internals import (
40
+ CasePreservingDict,
41
+ SpecialValues,
42
+ DomainStatus,
43
+ convert_to_categoricals_cat,
44
+ convert_to_categoricals_str,
45
+ get_keys_and_values,
46
+ generate_unique_labels,
47
+ GAMS_VARIABLE_SUBTYPES,
48
+ GAMS_EQUATION_SUBTYPES,
49
+ )
50
+
51
+
52
+ def container_read(container, load_from, symbols, records, mode, encoding):
53
+ if len(container) == 0:
54
+ initially_empty_container = True
55
+ else:
56
+ initially_empty_container = False
57
+
58
+ save_spec_values = gmd.doubleArray(gmd.GMS_SVIDX_MAX)
59
+ gmd.gmdGetUserSpecialValues(load_from, save_spec_values)
60
+
61
+ # setting special values
62
+ specVals = gmd.doubleArray(gmd.GMS_SVIDX_MAX)
63
+ specVals[gmd.GMS_SVIDX_UNDEF] = SpecialValues.UNDEF
64
+ specVals[gmd.GMS_SVIDX_NA] = SpecialValues.NA
65
+ specVals[gmd.GMS_SVIDX_EPS] = SpecialValues.EPS
66
+ specVals[gmd.GMS_SVIDX_PINF] = SpecialValues.POSINF
67
+ specVals[gmd.GMS_SVIDX_MINF] = SpecialValues.NEGINF
68
+
69
+ ret = gmd.gmdSetSpecialValues(load_from, specVals)
70
+ assert ret
71
+
72
+ # get number of symbols
73
+ ret = gmd.gmdInfo(load_from, gmd.GMD_NRSYMBOLSWITHALIAS)
74
+ symCount = ret[1]
75
+
76
+ # find symbol metadata if not reading in all
77
+ read_all_symbols = True
78
+ SYMBOL_METADATA = []
79
+ LINK_DOMAINS = []
80
+ SYMBOLS_W_RECORDS = []
81
+
82
+ rc = gmd.new_intp()
83
+
84
+ if symbols is not None:
85
+ read_all_symbols = False
86
+ for sym in symbols:
87
+ symptr = gmd.gmdFindSymbolWithAliasPy(load_from, sym, rc)
88
+ if symptr is None:
89
+ raise ValueError(
90
+ f"User specified to read symbol `{sym}`, "
91
+ "but it does not exist in the GMD object."
92
+ )
93
+
94
+ ret = gmd.gmdSymbolInfo(load_from, symptr, gmd.GMD_NUMBER)
95
+ symnr = ret[1]
96
+ SYMBOL_METADATA.append(
97
+ gmd_get_metadata_by_number(container, load_from, symnr, encoding, rc)
98
+ )
99
+
100
+ # sort symbols by gmd number in order to read symbols in gmd order not user order
101
+ SYMBOL_METADATA = sorted(SYMBOL_METADATA, key=lambda x: x["gmd_symbol_number"])
102
+
103
+ # two paths to creating symbol objects
104
+ if read_all_symbols:
105
+ #
106
+ #
107
+ # fastpath if reading in all symbols (by number)
108
+ for i in range(1, symCount + 1):
109
+ md = gmd_get_metadata_by_number(container, load_from, i, encoding, rc)
110
+
111
+ # capture metadata
112
+ SYMBOL_METADATA.append(md)
113
+
114
+ # check if symbol already exists in container
115
+ if not initially_empty_container:
116
+ if md["name"] in container:
117
+ raise Exception(
118
+ f"Attempting to create a new symbol (through a read operation) named `{md['name']}` "
119
+ "but an object with this name already exists in the Container. "
120
+ "Symbol replacement is only possible if the existing symbol is "
121
+ "first removed from the Container with the `<container>.removeSymbols()` method."
122
+ )
123
+
124
+ # capture symbols to link later
125
+ if (
126
+ any(True if i is not None else False for i in md["domains_as_ptrs"])
127
+ and md["type"] != gmd.GMS_DT_ALIAS
128
+ ):
129
+ LINK_DOMAINS.append(md)
130
+
131
+ # capture symbols that have records (not aliases)
132
+ if md["number_records"] > 0 and md["type"] != gmd.GMS_DT_ALIAS:
133
+ SYMBOLS_W_RECORDS.append(md)
134
+
135
+ # create the symbol object in the container
136
+ create_symbol_from_metadata(container, md)
137
+ else:
138
+ #
139
+ #
140
+ # other
141
+
142
+ for md in SYMBOL_METADATA:
143
+ # check if symbol already exists in container
144
+ if not initially_empty_container:
145
+ if md["name"] in container:
146
+ raise Exception(
147
+ f"Attempting to create a new symbol (through a read operation) named `{md['name']}` "
148
+ "but an object with this name already exists in the Container. "
149
+ "Symbol replacement is only possible if the existing symbol is "
150
+ "first removed from the Container with the `<container>.removeSymbols()` method."
151
+ )
152
+
153
+ # capture symbols to link later
154
+ if (
155
+ any(True if i is not None else False for i in md["domains_as_ptrs"])
156
+ and md["type"] != gmd.GMS_DT_ALIAS
157
+ ):
158
+ LINK_DOMAINS.append(md)
159
+
160
+ # capture symbols that have records (not aliases)
161
+ if md["number_records"] > 0 and md["type"] != gmd.GMS_DT_ALIAS:
162
+ SYMBOLS_W_RECORDS.append(md)
163
+
164
+ # create the symbol object in the container
165
+ create_symbol_from_metadata(container, md)
166
+
167
+ #
168
+ #
169
+ # link domain objects
170
+ READ_SYMBOLS = [md["name"] for md in SYMBOL_METADATA]
171
+ for md in LINK_DOMAINS:
172
+ domain = md["domain"]
173
+ for n, d in enumerate(domain):
174
+ if md["link_domains"][n] and d != "*" and d in READ_SYMBOLS:
175
+ domain[n] = container[d]
176
+
177
+ container[md["name"]]._domain
178
+
179
+ # main records read
180
+ if records:
181
+ # get and store GMD_UELS
182
+ GMD_UELS = container._gams2np.gmdGetUelList(load_from, encoding=encoding)
183
+ GMD_UELS[0] = "*"
184
+
185
+ for md in SYMBOLS_W_RECORDS:
186
+ # get symbol object
187
+ symobj = container[md["name"]]
188
+
189
+ # fastpath for scalar symbols
190
+ if md["dimension"] == 0 and md["number_records"] == 1:
191
+ symptr = gmd.gmdGetSymbolByNumberPy(
192
+ load_from, md["gmd_symbol_number"], rc
193
+ )
194
+ recptr = gmd.gmdFindFirstRecordPy(load_from, symptr, rc)
195
+
196
+ ret = gmd.gmdGetLevel(load_from, recptr)
197
+ level = ret[1]
198
+
199
+ marginal = 0.0
200
+ lower = 0.0
201
+ upper = 0.0
202
+ scale = 0.0
203
+
204
+ if md["type"] == gmd.GMS_DT_VAR or md["type"] == gmd.GMS_DT_EQU:
205
+ ret = gmd.gmdGetMarginal(load_from, recptr)
206
+ marginal = ret[1]
207
+ ret = gmd.gmdGetLower(load_from, recptr)
208
+ lower = ret[1]
209
+ ret = gmd.gmdGetUpper(load_from, recptr)
210
+ upper = ret[1]
211
+ ret = gmd.gmdGetScale(load_from, recptr)
212
+ scale = ret[1]
213
+
214
+ vals = [level, marginal, lower, upper, scale]
215
+
216
+ symobj._records = pd.DataFrame(
217
+ [vals[: len(symobj._attributes)]],
218
+ columns=symobj._attributes,
219
+ dtype=float,
220
+ )
221
+
222
+ else:
223
+ if mode.casefold() == "category":
224
+ try:
225
+ (
226
+ arrkeys,
227
+ arrvals,
228
+ unique_uels,
229
+ ) = container._gams2np.gmdReadSymbolCat(
230
+ load_from,
231
+ md["name"],
232
+ GMD_UELS,
233
+ encoding=encoding,
234
+ )
235
+ except:
236
+ raise Exception(
237
+ f"Could not properly read symbol {md['name']} from GMD object. "
238
+ "Try setting read argument mode='string'"
239
+ )
240
+
241
+ # convert to categorical dataframe (return None if no data)
242
+ df = convert_to_categoricals_cat(arrkeys, arrvals, unique_uels)
243
+
244
+ elif mode.casefold() == "string":
245
+ try:
246
+ arrkeys, arrvals = container._gams2np.gmdReadSymbolStr(
247
+ load_from,
248
+ md["name"],
249
+ encoding=encoding,
250
+ )
251
+ except:
252
+ raise Exception(
253
+ f"Could not properly read symbol {md['name']} from GMD object."
254
+ )
255
+
256
+ # convert to categorical dataframe (return None if no data)
257
+ df = convert_to_categoricals_str(arrkeys, arrvals, GMD_UELS[1:])
258
+
259
+ else:
260
+ raise ValueError("Unrecognized read `mode`")
261
+
262
+ # set records
263
+ symobj._records = df
264
+
265
+ # set column names
266
+ symobj._records.columns = (
267
+ generate_unique_labels(symobj.domain_names) + symobj._attributes
268
+ )
269
+
270
+ gmd.delete_intp(rc)
271
+
272
+ # reset GMD special values
273
+ gmd.gmdSetSpecialValues(load_from, save_spec_values)
274
+
275
+
276
+ def gmd_get_metadata_by_number(container, load_from, symbol_number, encoding, rc):
277
+ symptr = gmd.gmdGetSymbolByNumberPy(load_from, symbol_number, rc)
278
+ ret = gmd.gmdSymbolInfo(load_from, symptr, gmd.GMD_NAME)
279
+ syid = ret[3]
280
+ ret = gmd.gmdSymbolInfo(load_from, symptr, gmd.GMD_USERINFO)
281
+ userinfo = ret[1]
282
+ ret = gmd.gmdSymbolInfo(load_from, symptr, gmd.GMD_DIM)
283
+ dimen = ret[1]
284
+ ret = gmd.gmdSymbolInfo(load_from, symptr, gmd.GMD_NRRECORDS)
285
+ nrecs = ret[1]
286
+ expltxt = container._gams2np._gmdGetSymbolExplTxt(
287
+ load_from, symptr, encoding=encoding
288
+ )
289
+ ret = gmd.gmdGetDomain(load_from, symptr, dimen)
290
+ domains_as_ptrs = ret[1]
291
+ domain = ret[2]
292
+ ret = gmd.gmdSymbolType(load_from, symptr)
293
+ typ = ret[1]
294
+
295
+ if typ == gmd.GMS_DT_ALIAS:
296
+ symptr = gmd.gmdFindSymbolPy(load_from, syid, rc)
297
+ ret = gmd.gmdSymbolInfo(load_from, symptr, gmd.GMD_NAME)
298
+ parent_set = ret[3]
299
+ else:
300
+ parent_set = None
301
+
302
+ return {
303
+ "name": syid,
304
+ "gmd_symbol_number": symbol_number,
305
+ "dimension": dimen,
306
+ "type": typ,
307
+ "userinfo": userinfo,
308
+ "number_records": nrecs,
309
+ "description": expltxt,
310
+ "link_domains": [True if i is not None else False for i in domains_as_ptrs],
311
+ "domains_as_ptrs": domains_as_ptrs,
312
+ "domain": domain,
313
+ "parent_set": parent_set,
314
+ }
315
+
316
+
317
+ def create_symbol_from_metadata(container, metadata):
318
+ # create the symbols in the container
319
+ if metadata["type"] == gmd.GMS_DT_ALIAS:
320
+ # test for universe alias
321
+ if metadata["userinfo"] > 0:
322
+ try:
323
+ Alias._from_gams(
324
+ container, metadata["name"], container[metadata["parent_set"]]
325
+ )
326
+ except Exception as err:
327
+ raise Exception(
328
+ (
329
+ f"Cannot create the Alias symbol `{metadata['name']}` "
330
+ f"because the parent set (`{metadata['parent_set']}`) is not "
331
+ "being read into the in the Container. "
332
+ "Alias symbols require the parent set object to exist in the Container. "
333
+ f"Add `{metadata['parent_set']}` to the list of symbols to read."
334
+ )
335
+ )
336
+ else: # symbol number of universe (*) is 0
337
+ UniverseAlias._from_gams(container, metadata["name"])
338
+
339
+ # regular set
340
+ elif metadata["type"] == gmd.GMS_DT_SET and metadata["userinfo"] == 0:
341
+ Set._from_gams(
342
+ container,
343
+ metadata["name"],
344
+ metadata["domain"],
345
+ is_singleton=False,
346
+ description=metadata["description"],
347
+ )
348
+
349
+ # singleton set
350
+ elif metadata["type"] == gmd.GMS_DT_SET and metadata["userinfo"] == 1:
351
+ Set._from_gams(
352
+ container,
353
+ metadata["name"],
354
+ metadata["domain"],
355
+ is_singleton=True,
356
+ description=metadata["description"],
357
+ )
358
+
359
+ # parameters
360
+ elif metadata["type"] == gmd.GMS_DT_PAR:
361
+ Parameter._from_gams(
362
+ container,
363
+ metadata["name"],
364
+ metadata["domain"],
365
+ description=metadata["description"],
366
+ )
367
+
368
+ # variables
369
+ elif metadata["type"] == gmd.GMS_DT_VAR:
370
+ Variable._from_gams(
371
+ container,
372
+ metadata["name"],
373
+ GAMS_VARIABLE_SUBTYPES.get(metadata["userinfo"], "free"),
374
+ metadata["domain"],
375
+ description=metadata["description"],
376
+ )
377
+
378
+ # equations
379
+ elif metadata["type"] == gmd.GMS_DT_EQU:
380
+ Equation._from_gams(
381
+ container,
382
+ metadata["name"],
383
+ GAMS_EQUATION_SUBTYPES.get(metadata["userinfo"], "eq"),
384
+ metadata["domain"],
385
+ description=metadata["description"],
386
+ )
387
+
388
+ # unknown symbols
389
+ else:
390
+ raise Exception(
391
+ f"Unknown GamsDatabase (GMD) symbol classification (GAMS Type= {metadata['type']}, "
392
+ f"GAMS Subtype= {metadata['userinfo']}). ",
393
+ f"Cannot load symbol `{metadata['name']}`",
394
+ )
395
+
396
+
397
+ def container_write(
398
+ container, write_to, symbols, uel_priority, merge_symbols, mode, eps_to_zero
399
+ ):
400
+ if symbols is None:
401
+ write_all_symbols = True
402
+ else:
403
+ write_all_symbols = False
404
+
405
+ if write_all_symbols:
406
+ symbols = container.listSymbols()
407
+
408
+ # assert valid records
409
+ container._assert_valid_records(symbols=symbols)
410
+
411
+ # check if domain columns have valid categories
412
+ symobjs = container.getSymbols(symbols)
413
+ symnames = [sym.name for sym in symobjs]
414
+
415
+ # GMD work
416
+ save_spec_values = gmd.doubleArray(gmd.GMS_SVIDX_MAX)
417
+ gmd.gmdGetUserSpecialValues(write_to, save_spec_values)
418
+
419
+ # setting special values
420
+ specVals = gmd.doubleArray(gmd.GMS_SVIDX_MAX)
421
+ specVals[gmd.GMS_SVIDX_UNDEF] = SpecialValues.UNDEF
422
+ specVals[gmd.GMS_SVIDX_NA] = SpecialValues.NA
423
+ specVals[gmd.GMS_SVIDX_EPS] = (
424
+ SpecialValues.EPS if not eps_to_zero else gmd.GMS_SV_EPS
425
+ )
426
+ specVals[gmd.GMS_SVIDX_PINF] = SpecialValues.POSINF
427
+ specVals[gmd.GMS_SVIDX_MINF] = SpecialValues.NEGINF
428
+
429
+ ret = gmd.gmdSetSpecialValues(write_to, specVals)
430
+ assert ret
431
+
432
+ # get number of symbols
433
+ ret = gmd.gmdInfo(write_to, gmd.GMD_NRSYMBOLSWITHALIAS)
434
+ symCount = ret[1]
435
+
436
+ # read in all symbol metadata from GMD
437
+ rc = gmd.new_intp()
438
+ GMD_SYMBOL_METADATA = []
439
+ for symnr in range(1, symCount + 1):
440
+ GMD_SYMBOL_METADATA.append(
441
+ gmd_get_metadata_by_number(container, write_to, symnr, None, rc)
442
+ )
443
+ GMD_SYMBOLS = [md["name"] for md in GMD_SYMBOL_METADATA]
444
+
445
+ # casefold key symbol lists
446
+ CF_GMD_SYMBOLS = list(map(str.casefold, GMD_SYMBOLS))
447
+ CF_CONTAINER_SYMBOLS = list(map(str.casefold, symnames))
448
+ CF_MERGE_SYMBOLS = list(map(str.casefold, merge_symbols))
449
+
450
+ # check if partial write is possible
451
+ if not write_all_symbols:
452
+ if any(i not in CF_GMD_SYMBOLS for i in CF_CONTAINER_SYMBOLS):
453
+ raise Exception(
454
+ "Writing a subset of symbols from a Container is only enabled for "
455
+ "symbols that currently exist in the GamsDatabase (GMD) object."
456
+ "This restriction may be relaxed in a future release."
457
+ )
458
+
459
+ # check symbols
460
+ for symobj in symobjs:
461
+ if not symobj.isValid():
462
+ raise Exception(
463
+ f"Cannot write to GMD because symbol `{symobj.name}` is invalid. "
464
+ "Use `<symbol>.isValid(verbose=True)` to debug."
465
+ )
466
+
467
+ # check if merge is possible
468
+ for i in merge_symbols:
469
+ gmd_idx = CF_GMD_SYMBOLS.index(i.casefold())
470
+
471
+ if i.casefold() not in CF_CONTAINER_SYMBOLS:
472
+ raise Exception(
473
+ f"User specified merge operation for symbol `{i}`, "
474
+ f"however user did not specify that `{i}` should be written. "
475
+ f"Add `{i}` to the 'symbols' argument."
476
+ )
477
+
478
+ if i.casefold() not in CF_GMD_SYMBOLS:
479
+ raise Exception(
480
+ f"User specified merge operation for symbol `{i}`, "
481
+ "however symbol does not exist in the GMD object"
482
+ )
483
+
484
+ # check if symbol types are the same
485
+ chk_type = GMD_SYMBOL_METADATA[gmd_idx]["type"]
486
+ chk_userinfo = GMD_SYMBOL_METADATA[gmd_idx]["userinfo"]
487
+ if (
488
+ container[i]._gams_type != chk_type
489
+ or container[i]._gams_subtype != chk_userinfo
490
+ ):
491
+ raise Exception(
492
+ f"User specified merge operation for symbol `{i}`. "
493
+ "However, symbols cannot be merged because container and GMD symbol types do not match"
494
+ )
495
+
496
+ if isinstance(container[i], abcs.ABCAlias):
497
+ raise Exception(
498
+ f"Alias symbols cannot be merged, remove symbol `{i}` "
499
+ "from the merge_symbols list."
500
+ )
501
+
502
+ # check if the dimension is the same
503
+ if container[i].dimension != GMD_SYMBOL_METADATA[gmd_idx]["dimension"]:
504
+ raise Exception(
505
+ f"User specified merge operation for symbol `{i}`. "
506
+ "However, symbols cannot be merged because container and GMD symbol dimensions do not match"
507
+ )
508
+
509
+ # reorder symbols if necessary
510
+ if container._isValidSymbolOrder() == False:
511
+ container.reorderSymbols()
512
+
513
+ #
514
+ # register the universe
515
+ # get UELS only once
516
+ if uel_priority is None:
517
+ uel_priority = []
518
+
519
+ CONTAINER_UELS = uel_priority + container.getUELs(symbols=symbols)
520
+
521
+ # register UELs
522
+ for uel in CONTAINER_UELS:
523
+ try:
524
+ ret = gmd.gmdMergeUel(write_to, uel)
525
+ except Exception as err:
526
+ raise Exception(f"Unable to register UEL `{uel}` to GMD. Reason: {err}")
527
+
528
+ # main write
529
+ for symname, symobj in zip(CF_CONTAINER_SYMBOLS, symobjs):
530
+ # True: merge, False: replace, None: new
531
+ if symname in CF_MERGE_SYMBOLS:
532
+ merge = True
533
+ elif symname in CF_GMD_SYMBOLS and symname not in CF_MERGE_SYMBOLS:
534
+ merge = False
535
+ else:
536
+ merge = None
537
+
538
+ # write any aliases
539
+ if isinstance(symobj, abcs.AnyContainerAlias):
540
+ power_write_alias(write_to, symobj, rc)
541
+
542
+ # all other symbols
543
+ else:
544
+ if symobj.number_records == 0:
545
+ power_write_symbol_no_records(write_to, symobj, merge, rc)
546
+
547
+ elif symobj.number_records == 1 and symobj.dimension == 0:
548
+ power_write_symbol_scalar_record(
549
+ write_to, symobj, merge, eps_to_zero, rc
550
+ )
551
+
552
+ else:
553
+ if mode.casefold() == "category":
554
+ power_write_category(
555
+ container, write_to, symobj, merge, eps_to_zero, rc
556
+ )
557
+
558
+ elif mode.casefold() == "string":
559
+ power_write_string(
560
+ container, write_to, symobj, merge, eps_to_zero, rc
561
+ )
562
+
563
+ else:
564
+ raise Exception(f"Write mode not supported: {mode}")
565
+
566
+ gmd.delete_intp(rc)
567
+
568
+ # reset GMD special values
569
+ gmd.gmdSetSpecialValues(write_to, save_spec_values)
570
+
571
+
572
+ def power_write_alias(write_to, symobj, rc):
573
+ if isinstance(symobj, abcs.ABCAlias):
574
+ _, idx, _, _ = gmd.gmdSymbolInfo(
575
+ write_to,
576
+ gmd.gmdFindSymbolPy(write_to, symobj.alias_with.name, rc),
577
+ gmd.GMD_NUMBER,
578
+ )
579
+
580
+ ret = gmd.gmdAddSymbolXPy(
581
+ write_to,
582
+ symobj.name,
583
+ symobj.dimension,
584
+ gmd.GMS_DT_ALIAS,
585
+ idx,
586
+ f"Aliased with {symobj.alias_with.name}",
587
+ [None] * symobj.dimension,
588
+ [""] * symobj.dimension,
589
+ rc,
590
+ )
591
+ else:
592
+ # universe aliases
593
+ ret = gmd.gmdAddSymbolXPy(
594
+ write_to,
595
+ symobj.name,
596
+ symobj.dimension,
597
+ gmd.GMS_DT_ALIAS,
598
+ 0, # universe (*) symbol number in GMD is 0
599
+ f"Aliased with {symobj.alias_with}",
600
+ [None] * symobj.dimension,
601
+ [""] * symobj.dimension,
602
+ rc,
603
+ )
604
+
605
+
606
+ def power_write_symbol_no_records(write_to, symobj, merge, rc):
607
+ if merge is True:
608
+ ...
609
+
610
+ elif merge is False:
611
+ symptr = gmd.gmdFindSymbolPy(write_to, symobj.name, rc)
612
+ assert gmd.intp_value(
613
+ rc
614
+ ), f"internal error: could not find symbol {symobj.name} in gmd object"
615
+
616
+ ret = gmd.gmdClearSymbol(write_to, symptr)
617
+ assert (
618
+ ret
619
+ ), f"internal error: could not clear symbol {symobj.name} in gmd object"
620
+
621
+ else:
622
+ # get domain
623
+ if symobj._domain_status is DomainStatus.regular:
624
+ domain = []
625
+ for d in symobj.domain_names:
626
+ ret = gmd.gmdFindSymbolPy(write_to, d, rc)
627
+ domain.append(ret)
628
+ else:
629
+ domain = [None] * symobj.dimension
630
+
631
+ # create new symbol
632
+ gmd.gmdAddSymbolXPy(
633
+ write_to,
634
+ symobj.name,
635
+ symobj.dimension,
636
+ symobj._gams_type,
637
+ symobj._gams_subtype,
638
+ symobj.description,
639
+ domain,
640
+ symobj.domain_names,
641
+ rc,
642
+ )
643
+
644
+
645
+ def power_write_symbol_scalar_record(write_to, symobj, merge, eps_to_zero, rc):
646
+ def write_scalar_record(write_to, recptr, symobj):
647
+ vals = symobj.records.to_numpy().reshape((-1,))
648
+
649
+ if eps_to_zero:
650
+ vals = [0.0 if val == 0 else val for val in vals]
651
+
652
+ if symobj._gams_type == gmd.GMS_DT_PAR:
653
+ ret = gmd.gmdSetLevel(write_to, recptr, vals[0])
654
+
655
+ if symobj._gams_type == gmd.GMS_DT_VAR or symobj._gams_type == gmd.GMS_DT_EQU:
656
+ ret = gmd.gmdSetLevel(write_to, recptr, vals[0])
657
+ ret = gmd.gmdSetMarginal(write_to, recptr, vals[1])
658
+ ret = gmd.gmdSetLower(write_to, recptr, vals[2])
659
+ ret = gmd.gmdSetUpper(write_to, recptr, vals[3])
660
+ ret = gmd.gmdSetScale(write_to, recptr, vals[4])
661
+
662
+ if isinstance(merge, bool):
663
+ symptr = gmd.gmdFindSymbolPy(write_to, symobj.name, rc)
664
+ assert gmd.intp_value(rc), f"internal error: finding gmd symbol {symobj.name}"
665
+ recptr = gmd.gmdMergeRecordPy(write_to, symptr, [], rc)
666
+ assert gmd.intp_value(rc), "internal error: writing scalar record"
667
+ write_scalar_record(write_to, recptr, symobj)
668
+
669
+ else:
670
+ symptr = gmd.gmdAddSymbolXPy(
671
+ write_to,
672
+ symobj.name,
673
+ symobj.dimension,
674
+ symobj._gams_type,
675
+ symobj._gams_subtype,
676
+ symobj.description,
677
+ [],
678
+ symobj.domain_names,
679
+ rc,
680
+ )
681
+ recptr = gmd.gmdAddRecordPy(write_to, symptr, [], rc)
682
+ write_scalar_record(write_to, recptr, symobj)
683
+
684
+
685
+ def power_write_string(container, write_to, symobj, merge, eps_to_zero, rc):
686
+ # get keys and values arrays
687
+ arrkeys, arrvals = get_keys_and_values(symobj, mode="string")
688
+
689
+ if merge is True:
690
+ symptr = gmd.gmdFindSymbolPy(write_to, symobj.name, rc)
691
+ try:
692
+ container._gams2np.gmdFillSymbolStr(
693
+ write_to,
694
+ symptr,
695
+ arrkeys,
696
+ arrvals,
697
+ merge=True,
698
+ relaxedType=False,
699
+ epsToZero=eps_to_zero,
700
+ )
701
+ except Exception as err:
702
+ # clear symbol records
703
+ ret = gmd.gmdClearSymbol(write_to, symptr)
704
+ raise Exception(
705
+ f"Unable to successfully write symbol `{symobj.name}`. Reason: {err}"
706
+ )
707
+
708
+ elif merge is False:
709
+ symptr = gmd.gmdFindSymbolPy(write_to, symobj.name, rc)
710
+ ret = gmd.gmdClearSymbol(write_to, symptr)
711
+
712
+ try:
713
+ container._gams2np.gmdFillSymbolStr(
714
+ write_to,
715
+ symptr,
716
+ arrkeys,
717
+ arrvals,
718
+ merge=False,
719
+ relaxedType=False,
720
+ epsToZero=eps_to_zero,
721
+ )
722
+ except Exception as err:
723
+ # clear symbol records
724
+ ret = gmd.gmdClearSymbol(write_to, symptr)
725
+ raise Exception(
726
+ f"Unable to successfully write symbol `{symobj.name}`. Reason: {err}"
727
+ )
728
+ else:
729
+ # get domain
730
+ if symobj._domain_status is DomainStatus.regular:
731
+ domain = []
732
+ for d in symobj.domain_names:
733
+ ret = gmd.gmdFindSymbolPy(write_to, d, rc)
734
+ domain.append(ret)
735
+ else:
736
+ domain = [None] * symobj.dimension
737
+
738
+ # create new symbol
739
+ symptr = gmd.gmdAddSymbolXPy(
740
+ write_to,
741
+ symobj.name,
742
+ symobj.dimension,
743
+ symobj._gams_type,
744
+ symobj._gams_subtype,
745
+ symobj.description,
746
+ domain,
747
+ symobj.domain_names,
748
+ rc,
749
+ )
750
+
751
+ # fill new symbol
752
+ try:
753
+ container._gams2np.gmdFillSymbolStr(
754
+ write_to,
755
+ symptr,
756
+ arrkeys,
757
+ arrvals,
758
+ merge=True,
759
+ relaxedType=False,
760
+ epsToZero=eps_to_zero,
761
+ )
762
+
763
+ except Exception as err:
764
+ # clear symbol records
765
+ ret = gmd.gmdClearSymbol(write_to, symptr)
766
+ raise Exception(
767
+ f"Unable to successfully write symbol `{symobj.name}`. Reason: {err}"
768
+ )
769
+
770
+
771
+ def power_write_category(container, write_to, symobj, merge, eps_to_zero, rc):
772
+ # initialize major list
773
+ majorList = [[]] * symobj.dimension
774
+
775
+ for i in range(symobj.dimension):
776
+ # create major list
777
+ majorList[i] = symobj.getUELs(i)
778
+
779
+ # get keys and values arrays
780
+ arrkeys, arrvals = get_keys_and_values(symobj, mode="category")
781
+
782
+ # final type checking
783
+ if not np.issubdtype(arrkeys.dtype, np.integer):
784
+ arrkeys = arrkeys.astype(int)
785
+
786
+ if not isinstance(symobj, abcs.ABCSet):
787
+ if not np.issubdtype(arrvals.dtype, np.floating):
788
+ arrvals = arrvals.astype(float)
789
+
790
+ if merge is True:
791
+ symptr = gmd.gmdFindSymbolPy(write_to, symobj.name, rc)
792
+ try:
793
+ container._gams2np.gmdFillSymbolCat(
794
+ write_to,
795
+ symptr,
796
+ arrkeys,
797
+ arrvals,
798
+ majorList,
799
+ merge=True,
800
+ relaxedType=False,
801
+ epsToZero=eps_to_zero,
802
+ )
803
+ except Exception as err:
804
+ # clear symbol records
805
+ ret = gmd.gmdClearSymbol(write_to, symptr)
806
+ raise Exception(
807
+ f"Unable to successfully write symbol `{symobj.name}`. Reason: {err}"
808
+ )
809
+
810
+ elif merge is False:
811
+ symptr = gmd.gmdFindSymbolPy(write_to, symobj.name, rc)
812
+ ret = gmd.gmdClearSymbol(write_to, symptr)
813
+
814
+ try:
815
+ container._gams2np.gmdFillSymbolCat(
816
+ write_to,
817
+ symptr,
818
+ arrkeys,
819
+ arrvals,
820
+ majorList,
821
+ merge=True,
822
+ relaxedType=False,
823
+ epsToZero=eps_to_zero,
824
+ )
825
+ except Exception as err:
826
+ # clear symbol records
827
+ ret = gmd.gmdClearSymbol(write_to, symptr)
828
+ raise Exception(
829
+ f"Unable to successfully write symbol `{symobj.name}`. Reason: {err}"
830
+ )
831
+ else:
832
+ # get domain
833
+ if symobj._domain_status is DomainStatus.regular:
834
+ domain = []
835
+ for d in symobj.domain_names:
836
+ ret = gmd.gmdFindSymbolPy(write_to, d, rc)
837
+ domain.append(ret)
838
+ else:
839
+ domain = [None] * symobj.dimension
840
+
841
+ # create new symbol
842
+ symptr = gmd.gmdAddSymbolXPy(
843
+ write_to,
844
+ symobj.name,
845
+ symobj.dimension,
846
+ symobj._gams_type,
847
+ symobj._gams_subtype,
848
+ symobj.description,
849
+ domain,
850
+ symobj.domain_names,
851
+ rc,
852
+ )
853
+
854
+ # fill new symbol
855
+ try:
856
+ container._gams2np.gmdFillSymbolCat(
857
+ write_to,
858
+ symptr,
859
+ arrkeys,
860
+ arrvals,
861
+ majorList,
862
+ merge=True,
863
+ relaxedType=False,
864
+ epsToZero=eps_to_zero,
865
+ )
866
+
867
+ except Exception as err:
868
+ # clear symbol records
869
+ ret = gmd.gmdClearSymbol(write_to, symptr)
870
+ raise Exception(
871
+ f"Unable to successfully write symbol `{symobj.name}`. Reason: {err}"
872
+ )