API Reference¶
This section details the MOS Python API.
Interface¶
- class mos.interface.interface.Interface(url=None, token=None)¶
MOS interface class.
- Parameters:
- urlREST API url (string). If not provided, it is constructed from
env vars MOS_BACKEND_HOST and MOS_BACKEND_PORT
- tokenauthorization token (string). If not provided, it is obtained
from the env var MOS_BACKEND_TOKEN.
- delete_model_with_id(id)¶
Deletes model with a given id.
- Parameters:
- idmodel id (string)
- delete_model_with_name(name)¶
Deletes model with a give name.
- Parameters:
- namemodel name (string)
- get_model_with_id(id)¶
Gets a model associated with a given ID.
- Parameters:
- idmodel ID (integer)
- Returns:
- modelModel
- get_model_with_name(name)¶
Gets model with a given name.
- Parameters:
- namemodel name (string)
- Returns:
- modelModel
- get_models()¶
Gets models.
- Returns:
- models: list of dictionaries
- get_user_token(usr, pwd)¶
Gets user token.
- Parameters:
- usruser name (string)
- owduser password (string)
- Returns:
- tokenuser token (string)
- new_model(filepath, quiet=True)¶
Creates new model from file.
- Parameters:
- filepathpath to model file (string)
- quietflag (boolean)
- Returns:
- modelModel
- set_token(token)¶
Sets interface token.
- Parameters:
- tokenuser token (string)
Model¶
- class mos.interface.model.Model(base_url, data, requests)¶
MOS model class.
- get_constraint_state(name, field='all', typed=True)¶
Gets state of a constraint, all current information stored on that constraint. Note currently only returns values for scalar constraints.
- Parameters:
- namevariable name (string)
- fieldfield name (string)
- typedflag (boolean)
- Returns:
- statelist or appropriate type
- get_constraint_type_and_shape(name)¶
Gets constraint type and shape.
- Parameters:
- nameconstraint name (string)
- Returns:
- typestring
- shapetuple
- get_description()¶
Gets model description.
- Returns:
- descriptionmodel description (string)
- get_execution_log()¶
Gets execution log.
- Returns:
- logstring
- get_function_state(name, field='all', typed=True)¶
Gets state of a function, returning all current information on that function. Note currently only returns values for functions with scalar outputs.
- Parameters:
- namefunction name (string)
- fieldfield name (string)
- typedflag (boolean)
- Returns:
- statelist or appropriate type
- get_helper_object(name)¶
Gets value of any helper object
- Parameters:
- nameobject name (string)
- Returns:
- objecthelper object (Python object)
- get_id()¶
Gets model ID.
- Returns:
- idinteger
- get_interface_file(name, filepath=None)¶
Gets interface file.
- Parameters:
- namefile name (string)
- filepathpath to write interface file (string)
- Returns:
- filepathpath to interface file (string)
- get_interface_object(name)¶
Gets interface object.
- Parameters:
- nameobject name (string)
- Returns:
- objectinterface object (Python object)
- get_name()¶
Gets model name.
- Returns:
- namemodel name (string)
- get_owner_id()¶
Gets ID of owner.
- Returns:
- idinteger
- get_problem_state()¶
Gets problem state, information about problem
- Returns:
- statedict
- get_solver_state()¶
Gets solver state, information about solver settings and performance on problem.
- Returns:
- statedict
- get_source()¶
Gets model source code.
- Returns:
- sourcemodel source code (string)
- get_status()¶
Gets solution status of model
- Returns:
- statusstring
- get_system()¶
Gets modeling system.
- Returns:
- systemstring
- get_variable_state(name, field='all', typed=True)¶
Gets state of a variable, all current information stored on that variable. Note currently only returns values for scalar variables.
- Parameters:
- namevariable name (string)
- fieldfield name (string)
- typedflag (boolean)
- Returns:
- statelist or appropriate type
- get_variable_type_and_shape(name)¶
Gets variable type and shape.
- Parameters:
- namevariable name (string)
- Returns:
- typestring
- shapetuple
- has_constraint(name)¶
Checks if model has a constraint of a certain name
- Parameters:
- nameconstraint name (string)
- Returns:
- has_constraintboolean
- has_function(name)¶
Checks if model has a function of a certain name
- Parameters:
- namefunction name (string)
- Returns:
- has_functionboolean
- has_helper_object(name)¶
Checks if model has a helper object of a certain name
- Parameters:
- namehelper object name (string)
- Returns:
- has_helper_objectboolean
- has_interface_file(name)¶
Checks if model has an interface file of a certain name
- Parameters:
- namefilename (string)
- Returns:
- has_interface_fileboolean
- has_interface_object(name)¶
Checks if model has an interface object of a certain name
- Parameters:
- nameobject name (string)
- Returns:
- has_interface_objectboolean
- has_problem()¶
Checks if model has a problem defined
- Returns:
- has_variableboolean
- has_solver()¶
Checks if model has a solver defined
- Returns:
- has_solverboolean
- has_variable(name)¶
Checks if model has a variable of a certain name
- Parameters:
- namevariable name (string)
- Returns:
- has_variableboolean
- reload()¶
Reloads data
- run(blocking=True, poll_time=1)¶
Runs model.
- Parameters:
- blockingwhen True, blocks other actions while model status queued or running (boolean)
- poll_timeinteger
- set_interface_file(name, filepath)¶
Sets model interface file (assigns filepath to name)
- Parameters:
- nameinterface file name (string)
- filepathinterface file filepath (string)
- set_interface_object(name, data, encoder=None)¶
Sets model interface object
- Parameters:
- nameinterface object name (string)
- datainterface object data (Python object)
- encoderoptional specific encoder for conversion of data to JSON format
- show_components()¶
Prints model components to screen
- show_recipe()¶
Prints model recipe to screen