Initializing help system before first use

Application Interface

Topics covered in this chapter:

The functions for interacting with the Insight server are provided by the xpressinsight.AppInterface class. The methods of that class can be used, e.g., for downloading and uploading attachments, and for getting scenario and application meta data.

You can access the application interface functions via the insight property of the Insight application. This property is inherited from the base class xpressinsight.AppBase. The following example code, can be used to upload an attachment from within the Insight application class:

    self.insight.put_scen_attach("attachment.txt")

Note that the Python keyword self represents the current instance of the Insight application class. The following example shows how to integrate this line of code in an application.

import xpressinsight as xi

@xi.AppConfig(name="Attachment Example")
class App(xi.AppBase):

    @xi.ExecModeLoad(descr="Uploads attachment.")
    def load(self):
        with open("attachment.txt", "w") as text_file:
            text_file.write("Hello!")

        self.insight.put_scen_attach("attachment.txt")
        print('Upload status:', self.insight.attach_status)

    @xi.ExecModeRun(descr="Downloads attachment.")
    def run(self):
        self.insight.get_scen_attach("attachment.txt")
        print('Download status:', self.insight.attach_status)

        if self.insight.attach_status == xi.AttachStatus.OK:
            with open("attachment.txt", "r") as text_file:
                print(text_file.readline())

App Interface Classes

This class represents the Xpress Insight application interface. Use this interface to access attachments and meta data like the scenario ID.
Retrieves information about a given app attachment.
Property for the id of the Xpress Insight application which is the parent of the model.
Property for the name of the Xpress Insight application which is the parent of the model.
Read-only property indicating the status of the most recent attempt to access or modify an attachment.
Deletes a scenario attachment.
Delete the internal working directory of the xpressinsight package.
Property for the execution mode in which Xpress Insight is running the model.
Retrieves an app attachment from the Insight server, placing it in the Python working directory where it can be read by the model.
Gets Insight attachments by tag
Gets Insight attachments by tag
Retrieves the the 'rules' used to validate attachments and attachment meta-data.
Gets Insight attachments by tag
Get information for a repository item with the supplied path.
Get information for items in the folder with the supplied path.
Retrieves an attachment from the Insight server either for a given scenario, placing it in the Python working directory where it can be read by the model.
Retrieves a list of all the files attached to the app.
Retrieves a list of all the files attached to the app with the given tag.
Retrieves a list of the attachment tags defined in the companion file.
Retrieves a list of all the files attached to a given scenario.
Retrieves a list of all the files attached to a scenario with the given tag.
Uploads a scenario attachment to the Insight server, reading it from the Python working directory.
Renames an existing scenario attachment.
Resets the progress state for each progress metric back to zero.
Retrieves information about a given scenario attachment.
Property for the id of the Xpress Insight scenario.
Property for the name of the Xpress Insight scenario.
Property for the path of the Xpress Insight scenario.
Sets the 'rules' used to validate attachments and attachment meta-data.
Sets the list of tags that can be used in attachments
Update the description of an existing scenario attachment.
Mark an existing scenario attachment as hidden or visible in the Xpress Insight UI.
Update the tags of an existing scenario attachment.
Property for the path to use for the attachments directory of the current app, when in test mode.
Property for the location to store mock attachments for app and scenario, when in test mode.
Property for the location of the app companion file to parse, when in test mode.
Read-only property to check whether the Insight application is running in test mode or in Insight.
Property for the path to use for the scenario attachments directory of the current scenario.
Sends a progress update notification for a single metric from the model to the Xpress Insight system.
Property for the username of the Insight user that initiated the current scenario execution.
Read-only property for the internal working directory of the xpressinsight package.
Indicates the type of metric a progress update is providing.
Indicates the direction of optimization.

xpressinsight.AppInterface

Purpose
This class represents the Xpress Insight application interface. Use this interface to access attachments and meta data like the scenario ID.

xpressinsight.AppInterface.app_attach_info

Purpose
Retrieves information about a given app attachment.
Synopsis
app_attach_info(self, filename: str) -> Optional[xpressinsight.Attachment]
Argument
filename 
The filename of the app attachment to request
Return value
Information about the attachment.
Example
Example of copying information about the attachment my_attach.dat on the app containing the current scenario into a record called my_attachment
>>> my_attachment = insight.app_attach_info('my_attach.dat')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment description: ", my_attachment.description)
... else:
...     print("Error querying attachment")		
Further information
Check the attachment status code using insight.attach_status to determine whether the attachments information was successfully retrieved. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.app_id

Purpose
Property for the id of the Xpress Insight application which is the parent of the model.
Synopsis
app_id: str
Return value
The UID of the Xpress Insight application.
Example
Demonstration of setting the application ID (test mode only).
>>> insight.app_id = 'xyzzy'		
Demonstration of getting the application ID then outputting it.
>>> print('app id = ', insight.app_id)
app id = xyzzy		
Further information
1. The app_id property can only be set in test mode.
2. In test mode can be used to mock the Insight application state when testing code outside of an Insight scenario. By default, insight.app_id will return an empty string in test mode.
3. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.app_name

Purpose
Property for the name of the Xpress Insight application which is the parent of the model.
Synopsis
app_name: str
Return value
The name of the application.
Example
Demonstration of setting the application name (test mode only).
>>> insight.app_name = 'My App'		
Demonstration of getting the application name then outputting it.
>>> print('app name = ', insight.app_name)
app name = My App		
Further information
1. The app_name property can only be set in test mode.
2. The application name is not related to the name defined in the model's source code.
3. Used to mock the Insight application state when testing code outside of an Insight scenario. By default, insight.app_name will return an empty string in test mode.
4. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.attach_status

Purpose
Read-only property indicating the status of the most recent attempt to access or modify an attachment.
Synopsis
attach_status: AttachStatus
Further information
After every call to an attachment-related function or procedure, you should check the value of insight.attach_status to see if your request succeeded.
Related topics

xpressinsight.AppInterface.delete_scen_attach

Purpose
Deletes a scenario attachment.
Synopsis
delete_scen_attach(self, filename: str) -> None
Argument
filename 
The filename of the attachment to be deleted.
Example
Example of deleting an attachment called my_attach.dat from the current scenario.
>>> insight.delete_scen_attach('my_attach.dat')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment deleted")
... else:
...     print("Error deleting attachment")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment will be successfully deleted.
2. The attachment will still be available on the Insight server until the scenario completes.
3. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.delete_work_dir

Purpose
Delete the internal working directory of the xpressinsight package.
Synopsis
delete_work_dir(self)
Further information
1. In test mode, this function deletes the internal working directory. It is recommended to call this function at the beginning of a test, such that the test does not load data from the working directory of a previous test run.
2. If the working directory does not exist, the function returns immediately. If the working directory cannot be deleted, e.g., because another application has a lock on a file, the function raises an exception.
3. Setting this property when insight.test_mode is False will cause the model to abort with a runtime error.
Related topics

xpressinsight.AppInterface.exec_mode

Purpose
Property for the execution mode in which Xpress Insight is running the model.
Synopsis
exec_mode: str
Return value
The name of the current execution mode, as specified in the execution mode decorators. This can be a user-defined value, or can be one of these pre-defined standard values: xi.ExecMode.LOAD (when a scenario is being loaded), xi.ExecMode.RUN (when a scenario is being run), xi.ExecMode.NONE (when the application is being executed outside of Xpress Insight and no execution mode function is currently being executed).
Example
Demonstration of setting the execution mode (test mode only).
>>> insight.exec_mode = 'CALCULATE_STATS'		
Demonstration of getting the execution mode then outputting it.
>>> print('execution mode = ', insight.exec_mode)
execution mode = CALCULATE_STATS		
Further information
1. The exec_mode property can only be set in test mode.
2. In the LOAD execution mode function (or other user-defined execution modes with clear_input=True) your app should initialize its input data. In the RUN execution mode function (or user-defined execution modes with clear_input=False) it should then initialize its result data.
3. Used to mock the execution mode that requested the scenario execution, when testing code outside of an Insight scenario. By default, insight.exec_mode will be initialized automatically if you call an execution mode function. However, if you want to test another function, which is not an execution mode function, then it could make sense to set the exec_mode property manually.
4. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.get_app_attach

Purpose
Retrieves an app attachment from the Insight server, placing it in the Python working directory where it can be read by the model.
Synopsis
get_app_attach(self, filename: str) -> None
Argument
filename 
The filename of the attachment to be retrieved.
Example
Example of copying an app attachment called my_attach.dat to the working directory.
>>> insight.get_app_attach('my_attach.dat')
... if insight.attach_status == AttachStatus.OK:
...     with open('my_attach.dat') as f:
...         pass  # process the file
... else:
...     print("Error retrieving attachment")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment was successfully fetched.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.get_attach_by_tag

Purpose
Gets Insight attachments by tag
Synopsis
get_attach_by_tag(self, tag: str) -> Optional[xpressinsight.Attachment]
Argument
tag 
The tag to search for
Return value
An attachment object which will be populated with the details of the attachment that was retrieved.
Example
Example of searching for and retrieving an attachment with the tag tag1
>>> attachment = insight.get_attach_by_tag('mytag1')
... if insight.attach_status != AttachStatus.OK:
...     print("Error searching for attachments")
... else:
...     with open(attachment.filename) as f:
...         pass  # process the file		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment(s) were successfully retrieved.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.get_attach_filenames_by_tag

Purpose
Gets Insight attachments by tag
Synopsis
get_attach_filenames_by_tag(self, tag: str) -> List[str]
Argument
tag 
The tag to search for
Return value
A list which will be populated with the filenames of the attachments that were retrieved.
Example
Example of searching for and retrieving an attachment with the tag tag1
>>> filenames = insight.get_attach_by_tag('mytag1')
... if insight.attach_status != AttachStatus.OK:
...     print("Error searching for attachments")
... else:
...     for f in filenames:
...         print(f)		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment(s) were successfully retrieved.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.get_attach_rules

Purpose
Retrieves the the 'rules' used to validate attachments and attachment meta-data.
Synopsis
get_attach_rules(self) -> xpressinsight.AttachmentRules
Return value
The attachment rules.
Example
Demonstration of getting the example rules
>>> rules = insight.get_attach_rules()		
Further information
1. Used to retrieve the rules that are used to validate new attachments - for example, maximum attachment size.
2. This will only be necessary if you want to validate new attachments within the model, before they trigger Insight attachment errors for violating any of these rules.

xpressinsight.AppInterface.get_attachs_by_tag

Purpose
Gets Insight attachments by tag
Synopsis
get_attachs_by_tag(self, tag: str) -> Optional[List[xpressinsight.Attachment]]
Argument
tag 
The tag to search for
Return value
A list which will be populated with the details of the attachments that were retrieved.
Example
Example of searching for and retrieving all attachments with the tag tag1
>>> attachments = insight.get_attachs_by_tag('mytag1')
... if insight.attach_status != AttachStatus.OK:
...     print("Error searching for attachments")
... else:
...     for a in attachments:
...         print(a.filename)		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment(s) were successfully retrieved.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.get_item_info

Purpose
Get information for a repository item with the supplied path.
Synopsis
get_item_info(self, path: str) -> xpressinsight.ItemInfo
Argument
path: str 
Path to the repository item.
Return value
Information about the repository item (scenario / folder).
Example
Example of using get_item_info to obtain info for a scenario.
>>> info = insight.get_item_info('/my_app/my_scenario')		
Example of using get_item_info with error handling to obtain info for the current scenario.
>>> @xi.ExecModeLoad()
>>> def load(self):
>>>     try:
>>>         info = self.insight.get_item_info(".")
>>>         print(info)
>>>     except xi.InterfaceError as ex:
>>>         print(ex)		
Further information
Raises InterfaceError on failure.
Related topics

xpressinsight.AppInterface.get_item_infos

Purpose
Get information for items in the folder with the supplied path.
Synopsis
get_item_infos(self, folder_path: str) -> List[xpressinsight.ItemInfo]
Argument
folder_path: str 
Path to the repository folder.
Return value
Information about the items (folders / scenarios) in the given folder. The function does not return information about Virtual Scenario Groups.
Example
Example of using get_item_infos to obtain info for items in a folder.
>>> info = insight.get_item_infos('/my_app/my_folder')		
Example of using get_item_infos with error handling to obtain info for items in the same folder as the current scenario.
>>> @xi.ExecModeLoad()
>>> def load(self):
>>>     try:
>>>         infos = self.insight.get_item_infos(".")
>>>         print(infos)
>>>     except xi.InterfaceError as ex:
>>>         print(ex)		
Further information
Raises InterfaceError on failure.
Related topics

xpressinsight.AppInterface.get_scen_attach

Purpose
Retrieves an attachment from the Insight server either for a given scenario, placing it in the Python working directory where it can be read by the model.
Synopsis
get_scen_attach(self, filename: str, scenario_path: str = None) -> None
Arguments
filename 
The filename of the attachment to be retrieved.
scenario_path 
The path of a scenario. A scenario path is the full path to a scenario name starting from the repository root and including the app name. E.g. /myapp/DirA/myscenario If the scenario path is not specified, the attachment is retrieved for the current scenario.
Example
Example of copying a scenario attachment called my_attach.dat to the working directory.
>>> insight.get_scen_attach('my_attach.dat')
... if insight.attach_status == AttachStatus.OK:
...     with open('my_attach.dat') as f:
...         pass  # process the file
... else:
...     print("Error retrieving attachment")		
Getting an attachment for the current scenario.
>>> insight.get_scen_attach('my_attach.dat', '/myapp/DirA/myscenario')
... if insight.attach_status == AttachStatus.OK:
...     with open('my_attach.dat') as f:
...         pass  # process the file
... else:
...     print("Error retrieving attachment")		
Getting an attachment for a scenario with path /myapp/DirA/myscenario.
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment was successfully fetched.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.list_app_attach

Purpose
Retrieves a list of all the files attached to the app.
Synopsis
list_app_attach(self) -> List[xpressinsight.Attachment]
Return value
A list of the app attachments.
Example
Example of fetching information about all attachments on the app containing the current scenario into a list called atts
>>> atts = insight.list_app_attach()
... if insight.attach_status == AttachStatus.OK:
...     print("Attachments: ", atts)
... else:
...     print("Error listing attachments")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachments list was successfully retrieved.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.list_app_attach_by_tag

Purpose
Retrieves a list of all the files attached to the app with the given tag.
Synopsis
list_app_attach_by_tag(self, tag: str) -> List[xpressinsight.Attachment]
Argument
tag 
The tag to search for
Return value
A list of the app attachments.
Example
Example of fetching information about all attachments on the app with the tag tag1 into a list called atts
>>> atts = insight_list_app_attach_by_tag('mytag1')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachments: ", atts)
... else:
...     print("Error listing attachments")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachments list was successfully retrieved.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.list_attach_tags

Purpose
Retrieves a list of the attachment tags defined in the companion file.
Synopsis
list_attach_tags(self) -> List[xpressinsight.AttachTag]
Return value
A list of the defined tags.
Example
Example of outputting list of tags defined in companion file
>>> tags = insight.list_attach_tags()
... if insight.attach_status == AttachStatus.OK:
...     print("Defined tags: ", tagslist)
... else:
...     print("Error retrieving tags list")		
Further information
Check the attachment status code using insight.attach_status to determine whether the attachment was successfully fetched.
Related topics

xpressinsight.AppInterface.list_scen_attach

Purpose
Retrieves a list of all the files attached to a given scenario.
Synopsis
list_scen_attach(self, scenario_path: str = None) -> List[xpressinsight.Attachment]
Argument
scenario_path 
The path of a scenario. A scenario path is the full path to a scenario name starting from the repository root and including the app name. E.g. /myapp/DirA/myscenario If the scenario path is not specified, the attachment is retrieved for the current scenario
Return value
A list of the scenario attachments.
Example
Example of fetching information about all attachments of a scenario into a list called atts
>>> atts = insight.list_scen_attach()
... if insight.attach_status == AttachStatus.OK:
...     print("Attachments: ", atts)
... else:
...     print("Error listing attachments")		
Getting the list of attachments for the current scenario
>>> atts = insight.list_scen_attach('/myapp/DirA/myscenario')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachments: ", atts)
... else:
...     print("Error listing attachments")		
Getting the list of attachments for a scenario with path /myapp/DirA/myscenario
Further information
Check the attachment status code using insight.attach_status to determine whether the attachments list was successfully retrieved. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.list_scen_attach_by_tag

Purpose
Retrieves a list of all the files attached to a scenario with the given tag.
Synopsis
list_scen_attach_by_tag(self, tag: str, scenario_path: str = None) -> List[xpressinsight.Attachment]
Arguments
tag 
The tag to search for
scenario_path 
The path of a scenario. A scenario path is the full path to a scenario name starting from the repository root and including the app name. E.g. /myapp/DirA/myscenario. If the scenario path is not specified, the attachment is retrieved for the current scenario.
Return value
A list of the scenario attachments.
Example
Example of fetching information about all attachments on a scenario with the tag tag1 into a list called atts
>>> atts = insight.list_scen_attach_by_tag('mytag1')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachments: ", atts)
... else:
...     print("Error listing attachments")		
Getting the list of attachments for the current scenario with the given tag.
>>> atts = insight.list_scen_attach_by_tag('mytag1',
...                                        '/myapp/DirA/myscenario')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachments: ", atts)
... else:
...     print("Error listing attachments")		
Getting the list of attachments with the given tag for a scenario with path /myapp/DirA/myscenario.
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachments list was successfully retrieved.
2. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.put_scen_attach

Purpose
Uploads a scenario attachment to the Insight server, reading it from the Python working directory.
Synopsis
put_scen_attach(self, filename: str, overwrite: bool = True) -> None
Arguments
filename 
The filename of the attachment to be uploaded
overwrite 
If True, will overwrite attachment if it already exists. If False and attachment already exists, will fail with insight.attach_status returning AttachStatus.ALREADY_EXISTS. Defaults to True if not given.
Example
Example of taking a file my_attach.dat in the working directory, and saving it as a new scenario attachment called my_attach.dat.
>>> insight.put_scen_attach('my_attach.dat', False)
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment added ok")
... elif insight.attach_status == AttachStatus.ALREADY_EXISTS:
...     print("Attachment already exists")
... else:
...     print("Error adding attachment:", insight.attach_status)		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the attachment was successfully added.
2. The new attachment will not be available on the Insight server until the scenario completes.
3. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.rename_scen_attach

Purpose
Renames an existing scenario attachment.
Synopsis
rename_scen_attach(self, old_name: str, new_name: str) -> None
Arguments
old_name 
The existing filename of the attachment to be renamed
new_name 
The new filename of the attachment. Must not already be used for a scenario attachment.
Example
Example of renaming an existing attachment of the current scenario from my_attach.dat to my_attach-2015.dat.
>>> insight.rename_scen_attach('my_attach.dat', 'my_attach-2015.dat')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment renamed ok")
... else:
...     print("Error renaming attachment")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the new attachment name was accepted.
2. The attachment will not be renamed on the Insight server until the scenario completes.
3. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.reset_progress

Purpose
Resets the progress state for each progress metric back to zero.
Synopsis
reset_progress(self) -> None
Example
Reset the progress state for each progress metric back to zero.
>>> insight.reset_progress()		
Further information
The insight.update function can be used to report a number of optimization metrics to the Xpress Insight system. This method sends notifications to reset the value for each metric to zero.
Related topics

xpressinsight.AppInterface.scen_attach_info

Purpose
Retrieves information about a given scenario attachment.
Synopsis
scen_attach_info(self, filename: str) -> Optional[xpressinsight.Attachment]
Argument
filename 
The filename of the scenario attachment to request
Return value
Information about the attachment.
Example
Example of copying information about the attachment my_attach.dat on the current scenario into a record called my_attachment
>>> my_attachment = insight.scen_attach_info('my_attach.dat')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment description: ", my_attachment.description)
... else:
...     print("Error querying attachment")		
Further information
Check the attachment status code using insight.attach_status to determine whether the attachments information was successfully retrieved. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.scenario_id

Purpose
Property for the id of the Xpress Insight scenario.
Synopsis
scenario_id: str
Return value
The UID of the Xpress Insight scenario.
Example
Demonstration of setting the scenario id (test mode only).
>>> insight.scenario_id = 'xyzzy'		
Demonstration of getting the scenario id.
>>> print('scenario id = ', insight.scenario_id)
scenario id = xyzzy		
Further information
1. The scenario_id property can only be set in test mode.
2. In test mode can be used to mock the Insight scenario id. By default, insight.scenario_id will return an empty string in test mode.
3. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.scenario_name

Purpose
Property for the name of the Xpress Insight scenario.
Synopsis
scenario_name: str
Return value
The name of the Xpress Insight scenario.
Example
Demonstration of setting the scenario name (test mode only).
>>> insight.scenario_name = 'Scenario B'		
Demonstration of getting the scenario name.
>>> print('scenario name = ', insight.scenario_name)
scenario name = Scenario B		
Further information
1. The scenario_name property can only be set in test mode.
2. In test mode can be used to mock the Insight scenario name. By default, insight.scenario_name will return an empty string in test mode.
3. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.scenario_path

Purpose
Property for the path of the Xpress Insight scenario.
Synopsis
scenario_path: str
Return value
The name of the Xpress Insight scenario.
Example
Demonstration of setting the scenario path (test mode only).
>>> insight.scenario_path = '/myapp/DirA/myscenario'		
Demonstration of getting the scenario path.
>>> print('scenario path = ', insight.scenario_path)
scenario path = /myapp/DirA/myscenario		
Further information
1. A scenario path is the full path to a scenario name starting from the repository root and including the app name. E.g. /myapp/DirA/myscenario.
2. The scenario_path property can only be set in test mode.
3. In test mode can be used to mock the Insight scenario name. By default, insight.scenario_path will return an empty string in test mode.
4. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.set_attach_rules

Purpose
Sets the 'rules' used to validate attachments and attachment meta-data.
Synopsis
set_attach_rules(self, new_rules: xpressinsight.AttachmentRules)
Argument
new_rules 
Populated insightattachmentrules record
Example
Demonstration of setting the example rules
>>> insight.set_attach_rules(AttachmentRules(
...     max_size=1*1024*1024,
...     max_attach_count=25,
...     max_filename_len=32,
...     invalid_filename_chars=['/', r'', ' '],
...     max_description_len=128,
... ))		
Further information
1. Used to change the rules that are applied to new attachments - for example, if you want to test how your code responds to the AttachStatus.TOO_MANY error code without actually creating a lot of attachments, you can use this procedure to set a lower number of attachments per scenario.
2. Setting this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.set_attach_tags

Purpose
Sets the list of tags that can be used in attachments
Synopsis
set_attach_tags(self, new_tags: List[xpressinsight.AttachTag])
Argument
new_tags 
List of populated insightattachmenttag records.
Example
Demonstration of setting the available tags
>>> insight.set_attach_tags([
...     AttachTag(name='first', usage=AttachTagUsage.SINGLE_FILE),
...     AttachTag(name='test', usage=AttachTagUsage.MULTI_FILE),
... ])		
Further information
1. Used to mock the available attachment tags when testing code outside of an Insight scenario.
2. The AttachTagUsage.SINGLE_FILE usage constraint will only be applied during future calls to modify attachment tags. It will not be applied to attachments that are already tagged when insight.set_attach_tags is called.
3. Setting this property when insight.test_mode is False will cause the model to abort with a runtime error.
Related topics

xpressinsight.AppInterface.set_scen_attach_desc

Purpose
Update the description of an existing scenario attachment.
Synopsis
set_scen_attach_desc(self, filename: str, description: str) -> None
Arguments
filename 
The filename of the scenario attachment to update
description 
The new description of the attachment
Example
Example of setting the description of a scenario attachment my_attach.dat to be " This is my first attachment"
>>> insight.set_scen_attach_desc('my_attach.dat',
...                              'This is my attachment')
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment description updated ok")
... else:
...     print("Error updating attachment")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the new attachment description was accepted.
2. The attachment will not be updated on the Insight server until the scenario completes.
3. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.set_scen_attach_hidden

Purpose
Mark an existing scenario attachment as hidden or visible in the Xpress Insight UI.
Synopsis
set_scen_attach_hidden(self, filename: str, hidden: bool) -> None
Arguments
filename 
The filename of the scenario attachment to hide or show.
hidden 
If True, the attachment will be hidden in the Xpress Insight UI; if False, it will be visible.
Example
Example of hiding of a scenario attachment my_attach.dat
>>> insight.set_scen_attach_hidden('my_attach.dat', True)
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment hidden ok")
... else:
...     print("Error hiding attachment")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the update was successful.
2. The attachment will not be updated on the Insight server until the scenario completes.
3. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
Related topics

xpressinsight.AppInterface.set_scen_attach_tags

Purpose
Update the tags of an existing scenario attachment.
Synopsis
set_scen_attach_tags(self, filename: str, tags: List[str]) -> None
Arguments
filename 
The filename of the scenario attachment to update.
tags 
The new tags to apply to the attachment. Any existing tags will be removed.
Example
Example of setting the tags of a scenario attachment my_attach.dat to be "mytag1" and "mytag2"
>>> insight.set_scen_attach_tags('my_attach.dat',
...                              ['mytag1', 'mytag2'])
... if insight.attach_status == AttachStatus.OK:
...     print("Attachment tags updated ok")
... else:
...     print("Error updating attachment")		
Further information
1. Check the attachment status code using insight.attach_status to determine whether the new attachment tags were accepted.
2. The attachment will not be updated on the Insight server until the scenario completes.
3. Attempting to access attachments when the model is not being run through Xpress Insight will cause the model to abort with an error.
4. If any of the specified tags are single-file tags, they will be removed from other scenarios as part of this operation.
Related topics

xpressinsight.AppInterface.test_app_attach_dir

Purpose
Property for the path to use for the attachments directory of the current app, when in test mode.
Synopsis
test_app_attach_dir: str
Return value
The path to the app attachments directory.
Example
Demonstration of getting the app attachment directory (test mode only).
>>> print(insight.test_app_attach_dir)		
Demonstration of setting the app attachment directory (test mode only).
>>> insight.test_app_attach_dir = 'C:/dev/appattachments'		
Further information
1. When you set a path using this function, it will be used instead of the appattach subdirectory of the directory specified by insight.test_attach_dir property.
2. Setting this propery when insight.test_mode is False will cause the model to abort with a runtime error.
Related topics

xpressinsight.AppInterface.test_attach_dir

Purpose
Property for the location to store mock attachments for app and scenario, when in test mode.
Synopsis
test_attach_dir: str
Return value
The path to the attachments directory.
Example
Demonstration of setting the attachment directory (test mode only).
>>> insight.test_attach_dir = 'C:/dev/appattachments'		
Demonstration of getting the attachment directory (test mode only).
>>> print(insight.test_attach_dir)		
Related topics

xpressinsight.AppInterface.test_cfile_path

Purpose
Property for the location of the app companion file to parse, when in test mode.
Synopsis
test_cfile_path: str
Return value
The path to the app companion file.
Example
Demonstration of setting the companion file path (test mode only).
>>> insight.test_cfile_path = 'C:/dev/app/application.xml'		
Demonstration of getting the companion file path (test mode only).
>>> print(insight.test_cfile_path)		

xpressinsight.AppInterface.test_mode

Purpose
Read-only property to check whether the Insight application is running in test mode or in Insight.
Synopsis
test_mode: bool
Return value
True if the application is executed in test mode and False if it is running in Insight.
Further information
When the application is running in Insight, then the value is False, otherwise the value is True.

xpressinsight.AppInterface.test_scen_attach_dir

Purpose
Property for the path to use for the scenario attachments directory of the current scenario.
Synopsis
test_scen_attach_dir: str
Return value
The path to the scenario attachments directory.
Example
Demonstration of setting scenario attachment directory (test mode only).
>>> insight.test_scen_attach_dir = 'C:/dev/scenattachments'		
Demonstration of getting scenario attachment directory (test mode only).
>>> print(insight.test_scen_attach_dir)		
Further information
1. When you set a path using this function, it will be used instead of the scenattach subdirectory of the directory specified by insight.test_attach_dir property.
2. Setting this property when insight.test_mode is False will cause the model to abort with a runtime error.
Related topics

xpressinsight.AppInterface.update

Purpose
Sends a progress update notification for a single metric from the model to the Xpress Insight system.
Synopsis
update(self, metric: xpressinsight.Metric, value: Union[float, int, xpressinsight.ObjSense]) -> None
Arguments
metric 
The type of metric to update.
value 
The value of the metric to update.
Example
Notify Insight that the current best solution value is 51.9.
>>> insight.update(Metric.OBJVAL, 51.9)		
Automatic updating of metrics during optimization can be achieved by calling the update function from within a suitable solver callback:
>>> def on_gap_notify(prob, app):
...
...     num_sol = prob.attributes.mipsols
...     app.insight.update(xi.Metric.NUMSOLS, num_sol)
...
...     if num_sol == 0:
...         # Can only occur when mipabsgapnotifybound is used.
...         # Don't call gapnotify again.
...         return None, None, None, None
...
...     objective = prob.attributes.mipobjval
...     best_bound = prob.attributes.bestbound
...
...     if best_bound != 0 or objective != 0:
...         gap = abs(objective - best_bound) / \
...               max(abs(best_bound), abs(objective))
...     else:
...         gap = 0
...
...     app.insight.update(xi.Metric.OBJVAL, objective)
...     app.insight.update(xi.Metric.GAP, gap)
...
...     if gap > 1e-6:
...         new_rel_gap_notify_target = gap - 1e-6
...     else:
...         # Don't call gapnotify again.
...         new_rel_gap_notify_target = -1
...
...     return new_rel_gap_notify_target, None, None, None		
The above callback can then be attached via the Xpress Python API:
>>> prob = xp.problem()
...
... # TODO: Define the optimization problem
...
... # Optionally reset progress and set the objective sense
... self.insight.reset_progress()
... self.insight.update(xi.Metric.OBJSENSE, prob.attributes.objsense)
...
... prob.controls.miprelgapnotify = 1e20
... prob.addcbgapnotify(on_gap_notify, self, 0)
...
... prob.solve()		
Further information
This function allows the model to report back progress to the system where it is accessible by a client for display.
Related topics

xpressinsight.AppInterface.username

Purpose
Property for the username of the Insight user that initiated the current scenario execution.
Synopsis
username: str
Return value
The user name.
Example
Demonstration of setting the user name (test mode only).
>>> insight.username = 'LouisXIV'		
Demonstration of getting the user name then outputting it.
>>> print('user name = ', insight.username)
user name = LouisXIV		
Further information
1. The username property can only be set in test mode.
2. When called while the model is not running within Insight, this returns DEV.
3. The username returned will be the username suitable for human display - be aware that this is not a unique identifier for the user's account, as users can change their names.
4. Used to mock the user who requested the scenario execution, when testing code outside of an Insight scenario.
5. Modifying this property when insight.test_mode is False will cause the model to abort with a runtime error.

xpressinsight.AppInterface.work_dir

Purpose
Read-only property for the internal working directory of the xpressinsight package.
Synopsis
work_dir: str
Return value
Absolute path to the internal working directory of the xpressinsight package.

xpressinsight.Metric

Purpose
Indicates the type of metric a progress update is providing.
Synopsis
class xi.Metric(Enum)
Arguments
xi.Metric.GAP 
The gap to the optimal solution, as a percentage.
xi.Metric.OBJVAL 
The best solution value found so far.
xi.Metric.NUMSOLS 
The count of feasible solutions found so far.
xi.Metric.OBJSENSE 
The direction of the solve.
Further information
This enumeration is used in the Insight progress updates methods.
Related topics

xpressinsight.ObjSense

Purpose
Indicates the direction of optimization.
Synopsis
class xi.ObjSense(Enum)
Arguments
xi.ObjSense.MINIMIZE 
This is a minimization problem.
xi.ObjSense.MAXIMIZE 
This is a maximization problem.
Further information
This enumeration is used in the Insight progress updates methods.
Related topics

Attachments Classes

An object containing information about a single attachment.
A class containing information about the rules used by Insight when verifying attachments.
Indicates the status of the most recent attempt to access or modify an attachment.
A class containing information about a tag defined in the app's companion file.
Possible values for attachment tag usage.

xpressinsight.AttachStatus

Purpose
Indicates the status of the most recent attempt to access or modify an attachment.
Synopsis
class xi.AttachStatus(Enum)
Arguments
xi.AttachStatus.OK 
The operation completed successfully.
xi.AttachStatus.NOT_FOUND 
The specified attachment does not exist.
xi.AttachStatus.INVALID_FILENAME 
An attachment could not be created or renamed because the specified filename is invalid. It may be too long, too short, or contain invalid characters.
xi.AttachStatus.INVALID_DESCRIPTION 
The specified description is invalid. The description can be a maximum of 2500 characters in length.
xi.AttachStatus.ALREADY_EXISTS 
An attachment could not be created because another attachment with the same name already exists.
xi.AttachStatus.TOO_LARGE 
An attachment could not be created because the attached file is too large. Attachments can be a maximum of 150Mb in size.
xi.AttachStatus.TOO_MANY 
An attachment could not be created because the maximum number of attachments (250) has been reached for the app or scenario.
xi.AttachStatus.INVALID_TAGS 
Invalid tags were provided.
xi.AttachStatus.SEVERAL_FOUND 
Several attachments match the given tag but the proxpressinsight
Further information
After every call to an attachment-related function or procedure, you should check the value of insight.attach_status to see if your request succeeded.

xpressinsight.Attachment

Purpose
An object containing information about a single attachment.
Arguments
filename: str 
filename of the attachment
description: str 
description of the attachment
tags: List[str] 
collection of tags associated with the attachment
size: int 
size of the attachment, in bytes
last_modified_user: str 
name of the last Insight user to modify the attachment
last_modified_date: datetime.datetime 
date and time of last modification to attachment
hidden: bool 
whether the attachment is hidden from the UI

xpressinsight.AttachmentRules

Purpose
A class containing information about the rules used by Insight when verifying attachments.
Arguments
max_size: int 
The maximum size, in bytes, that an attachment may have.
max_attach_count: int 
The maximum number of attachments that can be attached to a single scenario.
max_filename_len: int 
The maximum permitted length, in characters, of an attachment filename.
invalid_filename_chars: List[str] 
A list of characters that are not permitted in attachment filenames. Must be a list of single-character string values.
max_description_len: int 
The maximum permitted length, in characters, of an attachment description.
Further information
This object is used only in test mode.
Related topics

xpressinsight.AttachTag

Purpose
A class containing information about a tag defined in the app's companion file.
Arguments
name: str 
Name of the tag.
description: str 
Description of the tag.
mandatory: bool 
Whether the tag is mandatory.
usage: AttachTagUsage 
Tag usage restrictions, either AttachTagUsage.SINGLE_FILE or AttachTagUsage.MULTI_FILE.
Further information
Modifying an AttachTag record will not modify the attachment tag information on the server.
Related topics

xpressinsight.AttachTagUsage

Purpose
Possible values for attachment tag usage.
Synopsis
class xi.AttachTagUsage(Enum)
Arguments
xi.AttachTagUsage.SINGLE_FILE: str 
This tag may only be assigned to at most one attachment file.
xi.AttachTagUsage.MULTI_FILE: str 
This tag may only be assigned to any number of attachment files.

Repository Classes

An exception that occurred during a call to certain AppInterface methods.
A class containing information for a repository item.

xpressinsight.InterfaceError

Purpose
An exception that occurred during a call to certain AppInterface methods.
Argument
message: str 
The error message.
Example
Example of using AppInterface.get_item_info with error handling to obtain info for the current scenario.
>>> @xi.ExecModeLoad()
>>> def load(self):
>>>     try:
>>>         info = self.insight.get_item_info(".")
>>>         print(info)
>>>     except xi.InterfaceError as ex:
>>>         print(ex)  # Print error type and message.
>>>         # print("ERROR:", ex.message)  # Print error message.		
Further information
1. InterfaceError is only used by certain AppInterface functions. For each function that uses this exception, the documentaiton explicitly mentions that the function may raise an InterfaceError.
2. InterfaceError defines __str__() so the error type and message can be printed directly.
Related topics

xpressinsight.ItemInfo

Purpose
A class containing information for a repository item.
Arguments
id: str 
Item id.
type: str 
Item type ( "FOLDER" or scenario type identifier).
name: str 
Item name.
path: str 
Item path.
parent_path: str 
Item parent path.
Related topics

© 2001-2021 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.