Container#

class gamspy.Container(load_from: str | os.PathLike | Container | gt.Container | None = None, system_directory: str | os.PathLike | None = None, working_directory: str | os.PathLike | None = None, debugging_level: Literal['keep', 'keep_on_error', 'delete'] = 'keep_on_error', options: Options | None = None, output: io.TextIOWrapper | None = None)[source]#

Bases: Container

A container is an object that holds all symbols and operates on them.

Parameters:
load_fromstr, os.PathLike, Container, gt.Container, optional

Path to the GDX file to be loaded from, by default None

system_directorystr, os.PathLike, optional

Path to the directory that holds the GAMS installation, by default None

working_directorystr, os.PathLike, optional

Path to the working directory to store temporary files such .lst, .gms, .gdx, .g00 files.

debugging_levelstr, optional

Decides on keeping the temporary files generate by GAMS, by default “keep_on_error”

optionsOptions, optional

Global options for the overall execution

Attributes:
in_miro

When running a GAMSPy job from GAMS MIRO, you may not want to perform certain expensive operations, such as loading MIRO input data from an Excel workbook, as this data comes from MIRO.

summary

This property returns a summary of the container.

system_directory

This property returns the path to the GAMS system directory.

working_directory

Working directory path.

Methods

addAlias([name, alias_with])

Creates a new Alias and adds it to the container

addEquation([name, type, domain, ...])

Creates an Equation and adds it to the Container

addGamsCode(gams_code)

Adds an arbitrary GAMS code to the generate .gms file.

addModel([name, description, problem, ...])

Creates a Model and adds it to the Container

addParameter([name, domain, records, ...])

Creates a Parameter and adds it to the Container

addSet([name, domain, is_singleton, ...])

Creates a Set and adds it to the container

addUniverseAlias(name)

Add a Universe Alias to the Container

addVariable([name, type, domain, records, ...])

Creates a Variable and adds it to the Container

close()

Stops the socket and releases resources.

copy(working_directory)

Creates a copy of the Container.

describeAliases([symbols])

Generate a DataFrame describing alias symbols in the Container.

describeEquations([symbols])

Generate a DataFrame describing equation symbols in the Container.

describeParameters([symbols])

Generate a DataFrame describing parameter symbols in the Container.

describeSets([symbols])

Generate a DataFrame describing sets within the Container.

describeVariables([symbols])

Generate a DataFrame describing variable symbols in the Container.

gamsJobName()

Returns the name of the latest GAMS job that was executed

gdxInputPath()

Path to the input GDX file

gdxOutputPath()

Path to the output GDX file

generateGamsString([path, show_raw])

Generates the GAMS code

getAliases([is_valid])

Retrieve alias objects from the Container.

getEquations()

Returns all equation symbols in the Container.

getParameters([is_valid])

Retrieve parameter objects from the Container.

getSets([is_valid])

Retrieve set objects from the Container.

getSymbols([symbols])

Retrieve symbol objects from the Container.

getVariables([is_valid, types])

Retrieve variable objects from the Container.

hasSymbols(symbols)

Checks if specific symbol names exist in a Container

importExtrinsicLibrary(lib_path, functions)

Imports an extrinsic library to the GAMS environment.

isValid([symbols, verbose, force])

Check the validity of symbols in the Container.

loadRecordsFromGdx(load_from[, symbol_names])

Loads data of the given symbols from a GDX file.

read(load_from[, symbol_names, ...])

Reads specified symbols from the GDX file.

setRecords(records, *[, uels_on_axes])

Batched setRecords call where one can set the records of many symbols at once.

write(write_to[, symbol_names, compress, ...])

Writes specified symbols to the GDX file.

writeSolverOptions(solver, solver_options[, ...])

Writes solver options of the specified solver to the working directory.

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i")
addAlias(name: str | None = None, alias_with: Set | Alias = None) Alias[source]#

Creates a new Alias and adds it to the container

Parameters:
namestr, optional

Name of the alias.

alias_withSet | Alias

Alias set object.

Returns:
Alias
Raises:
TypeError

In case the alias_with is different than a Set or an Alias

ValueError

If there is symbol with same name but different type in the Container

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = m.addSet("i")
>>> a = m.addAlias("a", i)
addEquation(name: str | None = None, type: str | EquationType = 'regular', domain: Sequence[Set | Alias] | Set | Alias | None = None, definition: Variable | Operation | Expression | None = None, records: Any | None = None, domain_forwarding: bool | list[bool] = False, description: str = '', uels_on_axes: bool = False, is_miro_output: bool = False, definition_domain: list | None = None) Equation[source]#

Creates an Equation and adds it to the Container

Parameters:
namestr, optional

Name of the equation. Name is autogenerated by default.

typestr

Type of the equation. “regular” by default.

domainSequence[Set | Alias] | Set | Alias, optional

Domain of the variable.

definition: Expression, optional

Definition of the equation.

recordsAny, optional

Records of the equation.

domain_forwardingbool | list[bool], optional

Whether the equation forwards the domain.

descriptionstr, optional

Description of the equation.

uels_on_axes: bool

Assume that symbol domain information is contained in the axes of the given records.

definition_domain: list, optional

Definiton domain of the equation.

is_miro_outputbool

Whether the symbol is a GAMS MIRO output symbol. See: https://gams.com/miro/tutorial.html

Returns:
Equation
Raises:
err

In case arguments are not valid

ValueError

If there is symbol with same name but different type in the Container

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = m.addEquation("i")
addGamsCode(gams_code: str) None[source]#

Adds an arbitrary GAMS code to the generate .gms file. Using addGAMSCode might result in a license error if no GAMSpy++ license is used.

Parameters:
gams_codestr

GAMS code that you want to insert.

Examples

>>> from gamspy import Container
>>> m = Container()
>>> m.addGamsCode("scalar piHalf / [pi/2] /;")
>>> m["piHalf"].toValue()
np.float64(1.5707963267948966)
addModel(name: str | None = None, description: str = '', problem: Problem | str = Problem.MIP, equations: Sequence[Equation] = [], sense: Sense | str = Sense.FEASIBILITY, objective: Variable | Expression | None = None, matches: dict[Equation | Sequence[Equation], Variable | Sequence[Variable]] | None = None, limited_variables: Sequence[ImplicitVariable] | None = None, external_module: str | None = None) Model[source]#

Creates a Model and adds it to the Container

Parameters:
namestr, optional

Name of the model. Name is autogenerated by default.

descriptionstr, optional

Description of the model.

equationsSequence[Equation]

Sequence of Equation objects.

problemProblem or str, optional

‘LP’, ‘NLP’, ‘QCP’, ‘DNLP’, ‘MIP’, ‘RMIP’, ‘MINLP’, ‘RMINLP’, ‘MIQCP’, ‘RMIQCP’, ‘MCP’, ‘CNS’, ‘MPEC’, ‘RMPEC’, ‘EMP’, or ‘MPSGE’, by default Problem.LP.

senseSense, optional

“MIN”, “MAX”, or “FEASIBILITY”.

objectiveVariable | Expression, optional

Objective variable to minimize or maximize or objective itself.

matchesdict[Equation | Sequence[Equation], Variable | Sequence[Variable]], optional

Equation - Variable matches for MCP models.

limited_variablesSequence[ImplicitVariable], optional

Allows limiting the domain of variables used in a model.

external_module: str, optional

The name of the external module in which the external equations are implemented

Returns:
Model

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> e = gp.Equation(m, "e")
>>> model = m.addModel("my_model", "LP", [e])
addParameter(name: str | None = None, domain: Sequence[Set | Alias | str] | Set | Alias | Dim | str | None = None, records: Any | None = None, domain_forwarding: bool | list[bool] = False, description: str = '', uels_on_axes: bool = False, is_miro_input: bool = False, is_miro_output: bool = False, is_miro_table: bool = False) Parameter[source]#

Creates a Parameter and adds it to the Container

Parameters:
namestr, optional

Name of the parameter. Name is autogenerated by default.

domainSequence[Set | Alias | str] | Set | Alias | Dim | str, optional

Domain of the parameter.

recordsint | float | pd.DataFrame | np.ndarray | list, optional

Records of the parameter.

domain_forwardingbool | list[bool], optional

Whether the parameter forwards the domain.

descriptionstr, optional

Description of the parameter.

uels_on_axesbool

Assume that symbol domain information is contained in the axes of the given records.

is_miro_inputbool

Whether the symbol is a GAMS MIRO input symbol. See: https://gams.com/miro/tutorial.html

is_miro_outputbool

Whether the symbol is a GAMS MIRO output symbol. See: https://gams.com/miro/tutorial.html

is_miro_tablebool

Whether the symbol is a GAMS MIRO table symbol. See: https://gams.com/miro/tutorial.html

Returns:
Parameter
Raises:
err

In case arguments are not valid

ValueError

If there is symbol with same name but different type in the Container

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> a = m.addParameter("a")
addSet(name: str | None = None, domain: Sequence[Set | Alias | str] | Set | Alias | str | None = None, is_singleton: bool = False, records: Any | None = None, domain_forwarding: bool | list[bool] = False, description: str = '', uels_on_axes: bool = False, is_miro_input: bool = False, is_miro_output: bool = False) Set[source]#

Creates a Set and adds it to the container

Parameters:
namestr, optional

Name of the set. Name is autogenerated by default.

domainSequence[Set | Alias | str] | Set | Alias | str, optional

Domain of the set.

is_singletonbool, optional

Whether the set is a singleton set. Singleton sets cannot contain more than one element.

recordspd.DataFrame | np.ndarray | list, optional

Records of the set.

domain_forwardingbool | list[bool], optional

Whether the set forwards the domain.

descriptionstr, optional

Description of the set.

uels_on_axesbool

Assume that symbol domain information is contained in the axes of the given records.

is_miro_inputbool

Whether the symbol is a GAMS MIRO input symbol. See: https://gams.com/miro/tutorial.html

is_miro_outputbool

Whether the symbol is a GAMS MIRO output symbol. See: https://gams.com/miro/tutorial.html

Returns:
Set
Raises:
err

In case arguments are not valid

ValueError

When there is symbol with same name in the Container

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = m.addSet("i")
addUniverseAlias(name: str) UniverseAlias[source]#

Add a Universe Alias to the Container

Parameters:
namestr

The name of the Universe Alias symbol

Returns:
UniverseAlias

The Universe Alias object that was added

Examples

>>> import gams.transfer as gt
>>> m = gt.Container()
>>> i = m.addSet("i", records=['i1','i2'])
>>> j = m.addSet("j", records=['j1','j2','j3'])
>>> ij = m.addUniverseAlias("ij")
>>> print(ij.getUELs())
['i1', 'i2', 'j1', 'j2', 'j3']
addVariable(name: str | None = None, type: str = 'free', domain: Sequence[Set | Alias | str] | Set | Alias | Dim | str | None = None, records: Any | None = None, domain_forwarding: bool | list[bool] = False, description: str = '', uels_on_axes: bool = False, is_miro_output: bool = False) Variable[source]#

Creates a Variable and adds it to the Container

Parameters:
namestr, optional

Name of the variable. Name is autogenerated by default.

typestr, optional

Type of the variable. “free” by default.

domainSequence[Set | Alias | str] | Set | Alias | Dim | str, optional

Domain of the variable.

recordsAny, optional

Records of the variable.

domain_forwardingbool | list[bool], optional

Whether the variable forwards the domain.

descriptionstr, optional

Description of the variable.

is_miro_outputbool

Whether the symbol is a GAMS MIRO output symbol. See: https://gams.com/miro/tutorial.html

Returns:
Variable
Raises:
err

In case arguments are not valid

ValueError

If there is symbol with same name but different type in the Container

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> v = m.addVariable("v")
close() None[source]#

Stops the socket and releases resources. The container should not be used afterwards to communicate with the GAMS execution engine, e.g. creating new symbols, changing data, solves, etc. The container data (Container.data) is still available for read operations.

copy(working_directory: str) Container[source]#

Creates a copy of the Container. Should not be invoked after creating the model.

Parameters:
working_directorystr, optional

Working directory of the new Container, by default None

Returns:
Container
Raises:
ValidationError

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i")
>>> new_cont = m.copy(working_directory="test")
>>> new_cont.data.keys() == m.data.keys()
True
describeAliases(symbols: str | List[str] | None = None) DataFrame | None#

Generate a DataFrame describing alias symbols in the Container.

This method generates a DataFrame providing detailed information about alias symbols in the Container.

Parameters:
symbolsstr | List[str], optional

An optional parameter specifying the alias symbol names to describe. If None (default), Describe all alias symbols in the Container.

Returns:
DataFrame | None

A pandas DataFrame containing the description of alias symbols that match the specified symbol names. If no matching alias symbols are found, None is returned.

Raises:
ValueError
  • If the ‘symbols’ argument is not of type str, list, or NoneType.

  • If an alias symbol name specified in ‘symbols’ does not exist in the Container.

Notes

  • This method provides a tabular summary of alias symbols, including information such as alias relationships, dimension, sparsity, etc.

  • The ‘symbols’ parameter allows you to describe one or more alias symbols in the Container.

  • If ‘symbols’ is None (default), the method describes all alias symbols in the Container.

  • The method raises a ValueError if any alias symbol name specified in ‘symbols’ does not exist in the Container.

describeEquations(symbols: str | List[str] | None = None) DataFrame | None#

Generate a DataFrame describing equation symbols in the Container.

This method generates a DataFrame providing detailed information about equation symbols in the Container.

Parameters:
symbolsstr | List[str], optional

An optional parameter specifying the equation symbol names to describe. If None (default), Describe all equation symbols in the Container.

Returns:
DataFrame | None

A pandas DataFrame containing the description of equation symbols that match the specified symbol names. If no matching equation symbols are found, None is returned.

Raises:
ValueError
  • If the ‘symbols’ argument is not of type str, iterable, or NoneType.
  • If an equation symbol name specified in ‘symbols’ does not exist in the Container.

Notes

  • This method provides a tabular summary of equation symbols, including information such as type, domain, dimension, sparsity, etc.

  • The ‘symbols’ parameter allows you to describe one or more equation symbols in the Container.

  • If ‘symbols’ is None (default), the method describes all equation symbols in the Container.

  • The method raises a ValueError if any equation symbol name specified in ‘symbols’ does not exist in the Container.

describeParameters(symbols: str | List[str] | None = None) DataFrame | None#

Generate a DataFrame describing parameter symbols in the Container.

This method generates a DataFrame providing detailed information about parameter symbols in the Container.

Parameters:
symbolsstr | List[str], optional

An optional parameter specifying the parameter symbol names to describe. If None (default), Describe all parameter symbols in the Container.

Returns:
DataFrame | None

A pandas DataFrame containing the description of parameter symbols that match the specified symbol names. If no matching parameter symbols are found, None is returned.

Raises:
ValueError
  • If the ‘symbols’ argument is not of type str, iterable, or NoneType.

  • If a parameter symbol name specified in ‘symbols’ does not exist in the Container.

Notes

  • This method provides a tabular summary of parameter symbols, including information such as domain, dimension, sparsity, etc.

  • The ‘symbols’ parameter allows you to describe one or more parameter symbols in the Container.

  • If ‘symbols’ is None (default), the method describes all parameter symbols in the Container.

  • The method raises a ValueError if any parameter symbol name specified in ‘symbols’ does not exist in the Container.

describeSets(symbols: str | List[str] | None = None) DataFrame | None#

Generate a DataFrame describing sets within the Container.

This method creates a DataFrame that provides descriptive information about sets within the Container. You can specify the sets to describe using the ‘symbols’ parameter. If ‘symbols’ is None (default), all sets are described.

Parameters:
symbolsstr | List[str], optional

An optional parameter specifying which sets to describe.

Returns:
DataFrame | None

A Pandas DataFrame containing descriptive information about the specified sets. The DataFrame includes the following columns: - ‘name’: The name of the set. - ‘is_singleton’: Whether the set is a singleton set (True) or not (False). - ‘domain’: The domain of the set. - ‘domain_type’: The type of the set’s domain. - ‘dimension’: The dimension of the set. - ‘number_records’: The number of records (size) of the set. - ‘sparsity’: The sparsity of the set.

If ‘symbols’ includes alias sets, the DataFrame will also contain the following additional columns: - ‘is_alias’: Whether the set is an alias set (True) or not (False). - ‘alias_with’: The name of the set that the alias set is associated with (if it is an alias set).

The DataFrame is sorted by set name in ascending order.

Raises:
TypeError

If the ‘symbols’ argument is not of type str, list, or NoneType. If ‘symbols’ contains elements that are not of type str.

Notes

  • This method generates a descriptive summary of sets within the Container, including their properties and characteristics.

  • The ‘symbols’ parameter allows you to specify which sets to describe. If None (default), all sets are described.

  • The resulting DataFrame provides insights into each set’s attributes, such as dimensionality, size, and sparsity.

describeVariables(symbols: str | List[str] | None = None) DataFrame | None#

Generate a DataFrame describing variable symbols in the Container.

This method generates a DataFrame providing detailed information about variable symbols in the Container.

Parameters:
symbolsstr | List[str], optional

An optional parameter specifying the variable symbol names to describe. If None (default), Describe all variable symbols in the Container.

Returns:
DataFrame | None

A pandas DataFrame containing the description of variable symbols that match the specified symbol names. If no matching variable symbols are found, None is returned.

Raises:
ValueError
  • If the ‘symbols’ argument is not of type str, iterable, or NoneType.
  • If a variable symbol name specified in ‘symbols’ does not exist in the Container.

Notes

  • This method provides a tabular summary of variable symbols, including information such as type, domain, dimension, sparsity, etc.

  • The ‘symbols’ parameter allows you to describe one or more variable symbols in the Container.

  • If ‘symbols’ is None (default), the method describes all variable symbols in the Container.

  • The method raises a ValueError if any variable symbol name specified in ‘symbols’ does not exist in the Container.

gamsJobName() str | None[source]#

Returns the name of the latest GAMS job that was executed

Returns:
str | None

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=["seattle", "san-diego"], description="canning plants")
>>> gams_file_name = f"{m.gamsJobName()}.gms"
gdxInputPath() str[source]#

Path to the input GDX file

Returns:
str

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=["seattle", "san-diego"], description="canning plants")
>>> gdx_path = m.gdxInputPath()
gdxOutputPath() str[source]#

Path to the output GDX file

Returns:
str

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, name="i", records=["seattle", "san-diego"], description="canning plants")
>>> ii = gp.Set(m, name="ii", domain=i, description="seattle plant")
>>> ii['seattle'] = True
>>> gdx_path = m.gdxOutputPath()
generateGamsString(path: str | None = None, *, show_raw: bool = False) str[source]#

Generates the GAMS code

Parameters:
pathstr, optional

Path to the file that will contain the executed GAMS code.

show_rawbool, optional

Shows the raw model without data and other necessary GAMS statements, by default False.

Returns:
str

Examples

>>> import gamspy as gp
>>> m = gp.Container(debugging_level="keep")
>>> i = gp.Set(m, name="i")
>>> gams_code = m.generateGamsString()
getAliases(is_valid: bool | None = None) List[ABCAlias]#

Retrieve alias objects from the Container.

This method allows you to retrieve alias objects from the Container based on their names.

Parameters:
is_validbool, optional

An optional boolean flag used to filter the list of aliases. If None (default), all aliases in the Container are returned. If True, only valid aliases are included in the list. If False, only invalid aliases are included in the list.

Returns:
List[ABCAlias]

A list of alias objects that match the specified names.

getEquations() list[Equation][source]#

Returns all equation symbols in the Container.

Returns:
list[Equation]

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> eq1 = gp.Equation(m, name="eq1")
>>> eq2 = gp.Equation(m, name="eq2")
>>> equation_objects = m.getEquations()
getParameters(is_valid: bool | None = None) List[ABCParameter]#

Retrieve parameter objects from the Container.

This method allows you to retrieve parameter objects from the Container based on their names.

Parameters:
is_validbool, optional

An optional boolean flag used to filter the list of parameters. If None (default), all parameters in the Container are returned. If True, only valid parameters are included in the list. If False, only invalid parameters are included in the list.

Returns:
List[ABCAlias]

A list of parameter objects that match the specified names.

getSets(is_valid: bool | None = None) List[ABCSet]#

Retrieve set objects from the Container.

This method allows you to retrieve set objects from the Container based on their names.

Parameters:
is_validbool, optional

An optional boolean flag used to filter the list of sets. If None (default), all sets in the Container are returned. If True, only valid sets are included in the list. If False, only invalid sets are included in the list.

Returns:
List[ABCSet]

A list of set objects that match the specified names.

getSymbols(symbols: str | Sequence[str] | None = None) List[AnyContainerSymbol]#

Retrieve symbol objects from the Container.

This method allows you to retrieve symbol objects from the Container based on their names.

Parameters:
symbolsstr | Sequence[str], optional

An optional parameter specifying the symbol names to retrieve. If None (default), Retrieve all symbols stored in the Container.

Returns:
List[AnyContainerSymbol]

A list of symbol objects that match the specified symbol names.

Raises:
ValueError
  • If the ‘symbols’ argument is not of type str, iterable, or NoneType.

  • If a symbol name specified in ‘symbols’ does not exist in the Container.

getVariables(is_valid: bool | None = None, types: str | List[str] | None = None) List[ABCVariable]#

Retrieve variable objects from the Container.

This method allows you to retrieve variable objects from the Container based on their names.

Parameters:
is_validbool, optional

An optional boolean flag used to filter the list of variables. If None (default), all variables in the Container are returned. If True, only valid variables are included in the list. If False, only invalid variables are included in the list.

typesstr | List[str], optional

An optional string or list of strings specifying the types of variables to include in the list. If None (default), all variable types are included in the list. If a string or list of strings is provided, only variables of the specified types are included in the list.

Returns:
List[ABCVariable]

A list of variable objects that match the specified names.

hasSymbols(symbols: List[str] | str) List[bool] | bool[source]#

Checks if specific symbol names exist in a Container

Parameters:
symbolsList[str] | str

Symbols to check from the Container

Returns:
List[bool] | bool

Flag to indicate whether a symbol exists or not

importExtrinsicLibrary(lib_path: str, functions: dict[str, str]) ExtrinsicLibrary[source]#

Imports an extrinsic library to the GAMS environment.

Parameters:
lib_pathstr

Path to the .so, .dylib or .dll file that contains the extrinsic library

functionsdict[str, str]

Names of the functions as a dictionary. Key is the desired function name in GAMSPy and value is the function name in the extrinsic library.

Returns:
ExtrinsicLibrary
Raises:
FileNotFoundError

In case the extrinsic library does not exist in the given path.

isValid(symbols: str | List[str] | None = None, verbose: bool = False, force: bool = False) bool#

Check the validity of symbols in the Container.

This method checks the validity of symbols in the Container to ensure that they are consistent and correctly defined. It can check the validity of specific symbols or all symbols in the Container.

Parameters:
symbolsstr | List[str], optional

A list of symbol names or a single symbol name to be checked for validity. If None, all symbols in the Container will be checked.

verbosebool, by default False

A boolean flag indicating whether to raise an exception if an invalid symbol is found. If True, an exception is raised; if False, the method returns False for invalid symbols.

forcebool, by default False

A boolean flag indicating whether to force a recheck of the symbols’ validity.

Returns:
bool

Returns True if specified symbols (or all symbols in the Container) are valid. If any symbol is invalid and verbose is False, it returns False. If verbose is True, an exception is raised for the first invalid symbol encountered.

loadRecordsFromGdx(load_from: str, symbol_names: Iterable[str] | dict[str, str] | None = None) None[source]#

Loads data of the given symbols from a GDX file. If no symbol names are given, data of all symbols are loaded.

Parameters:
load_fromstr

Path to the GDX file

symbol_namesIterable[str], dict[str, str], optional

Symbol names whose data will be load from GDX, by default None. Default option loads records of all symbols in the GDX file. If given as a dict, keys are the symbol names in the GDX file, and values are the names of the GAMSPy symbols.

Examples

>>> from gamspy import Container, Set
>>> m = Container()
>>> i = Set(m, "i", records=["i1", "i2"])
>>> m.write("test.gdx")
>>> m2 = Container()
>>> m2.loadRecordsFromGdx("test.gdx")
>>> print(i.records.equals(m2["i"].records))
True
read(load_from: str | PathLike | Container | Container, symbol_names: list[str] | None = None, load_records: bool = True, mode: str | None = None, encoding: str | None = None) None[source]#

Reads specified symbols from the GDX file. If symbol_names are not provided, it reads all symbols from the GDX file.

Parameters:
load_fromstr, os.PathLike, Container, gt.Container
symbol_namesList[str], optional
load_recordsbool
modestr, optional
encodingstr, optional

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=['i1', 'i2'])
>>> m.write("test.gdx")
>>> new_container = gp.Container()
>>> new_container.read("test.gdx")
>>> new_container.data.keys() == m.data.keys()
True
setRecords(records: dict[SymbolType, Any], *, uels_on_axes: bool | list[bool] = False) None[source]#

Batched setRecords call where one can set the records of many symbols at once.

Parameters:
recordsdict[SymbolType, Any]

Dictionary of records where keys are symbols are values are their records.

uels_on_axesbool, optional

If uels_on_axes=True setRecords will assume that all domain information is contained in the axes of the pandas object. Data will be flattened (if necessary).

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i")
>>> k = gp.Set(m, "k")
>>> m.setRecords({i: range(10), k: range(5)})
write(write_to: str, symbol_names: list[str] | None = None, compress: bool = False, mode: str | None = None, eps_to_zero: bool = True) None[source]#

Writes specified symbols to the GDX file. If symbol_names are not provided, it writes all symbols to the GDX file.

Parameters:
write_tostr
symbol_namesList[str], optional
compressbool
modestr, optional
eps_to_zerobool

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> i = gp.Set(m, "i", records=['i1', 'i2'])
>>> m.write("test.gdx")
writeSolverOptions(solver: str, solver_options: dict | str | Path, file_number: int = 1) None[source]#

Writes solver options of the specified solver to the working directory.

Parameters:
solverstr

Name of the solver.

solver_optionsdict | str | Path

Options of the specified solver or path to an existing solver options file.

file_numberint

Solver option file number. Equivalent to optfile option of GAMS. See https://gams.com/latest/docs/UG_GamsCall.html#GAMSAOoptfile for more details.

Examples

>>> import gamspy as gp
>>> m = gp.Container()
>>> m.writeSolverOptions("conopt", solver_options={"rtmaxv": "1.e12"})
property in_miro: bool#

When running a GAMSPy job from GAMS MIRO, you may not want to perform certain expensive operations, such as loading MIRO input data from an Excel workbook, as this data comes from MIRO. In that case, one can conditionally load the data by using the in_miro attribute of Container.

Returns:
bool
property summary: dict#

This property returns a summary of the container.

Returns:
dict

A summary including the container’s system directory and its number of symbols.

property system_directory#

This property returns the path to the GAMS system directory.

Returns:
str

The path to the system directory.

property working_directory: str#

Working directory path.

Returns:
str