Functions to Implement

You can add a plugin for extending optiSLang by providing a Python file following a special naming convention, and by implementing a set of functions within it following special naming and signature conventions.

The following are the available functions forming the interface, and indicates where implementation is necessary or optional.

To provide a few simple string or integer settings, implement the default_settings function and optiSLang will provide generic standard entry fields (without any QML-based user interface technology). The execute_custom function is only required when you need advanced interactivity for user interfaces with QML-based settings. Otherwise, it is optional.

You do not need to declare anywhere explicitly the set of functions you are implementing. The code in the top-level ci.py file is the declaration. Based on the presence of function implementation, optiSLang creates the nodes. When you add or remove functions, you can trigger optiSLang to rescan the libraries by closing and restarting it.

The following functions are available:

load

This function is called when opening the node’s edit dialog box. In this function, define inputs (InputValueDefinition) and outputs (OutputValueDefinition) which are used in the node’s edit dialog box to register parameters and responses.

Incoming Arguments

Common Incoming Key Word Arguments (KWARGs),

Return Values

List of two elements:

execute

This function is used to call your solver.

Incoming Arguments

Return Values

List of HidSpecificOutputData.

default_settings

This function defines the set of default settings associated with each new node instance. In a dictionary, you supply name-value pairs. The value type is important, for example, by forwarding a boolean value this setting is determined to be a boolean switch. Your code should then not set any other value type later. Without supplying any QML code for drawing user interface elements, optiSLang will add generic user interface elements, and these are determined by the value type given here. For instance, a boolean value induces optiSLang to display a check box in the node edit dialog box, whereas for string values a text entry field is created. The value types supported are boolean, integer, float, and string.

This function returns a list of zero to two elements, where each element can be either a Python object or a list of tuples. If you intend to use the generic settings user interface only, a planar dictonary (name-value pairs) or a list of tuples is supported. If you intended to use QML code, the elements can be nested Python objects. By providing a list of tuples, you can preserve the order of the given settings. The first element is always treated as a set of settings that require a node reset when manipulated in the user interface. (modifying_settings). The second element is treated as a set of settings where you do not need to reset the node after they are manipulated in the user interface. (non_modifying_settings).


Note:  In default_settings, you define the sequence of setting names and value types for your new node type. In all other functions, the settings container stored with the node is input using arguments. Wherever settings are consumed, you assume the same dictionary/list structure (the same sequence of names and value types).


Incoming Arguments

Common Incoming Key Word Arguments (KWARGs)

Return Values

List with zero to two elements containing modifying_settings and/or non_modifying_settings as Python objects or lists of tuples.

execute_custom

This function serves as flexible, general-purpose, signal and information channel between the QML layer and the Python layer. When you access tabs, entries, and buttons in the QML-based settings user interface, the QML layer is running the process. If you need logic evaluation or other small computations, the QML layer allows for lines of JavaScript. However, if you cannot solve all settings-related work steps in the QML layer, then the execute_custom function allows you to trigger work in the Python layer and collect work results from there.

The execute_custom function can be triggered from the QML layer using the following:

backend.executeCustom(JSON.stringify(info_container))

Information exchange between the QML and Python layers using execute_custom occurs using JSON which is represented as a dictionary on the Python side.

The function can be used for as many types of tasks as needed, and as often as needed. Various different QML user interface elements created by you can trigger execute_custom, and in the QML code you can put together any kind of cargo-containing JSON to pass over to the Python layer. At the same time, in the Python layer, inside execute_custom you can trigger any kind of work on the Python side. When a task is resolve, you can send the result of the Python work back to the QML layer in the same way. A dictionary is used for the communication back to the QML layer.

Incoming Arguments

Return Values

Return cargo, can represent a JSON dictionary.

check

This function is called at the start of execution. You can use it to check if there are any issues preventing successful execution, and if there are, provide an early stop to prevent a potential time-consuming run.

Incoming Arguments

Common Incoming Key Word Arguments (KWARGs)

Return Values

RunStatus: An object for documenting success and logging.

reset

This function is called when the node is reset.

Incoming Arguments

Return Values

RunStatus: An object for documenting success and logging.

reset_hid

This function is called when the node is reset for a single HID.

Incoming Arguments

Return Values

RunStatus: An object for documenting success and logging.

initialize

You can use the initialize and shutdown functions to create and close a Python work environment. In some use cases, it can be difficult to use separate, atomic, agnostic functions, so it may be easier to work in a session-based manner. Initialize and shutdown allow you to, for example, avoid loading a heavy solver program multiple times during the lifecycle for one design and repeatedly for many designs by keeping a session/connection with one solver program instance alive all the time.

In the initialize function, you can generate a set of global variables which you can use in all other functions. A variable name can handle to simple things like numbers or strings, or, it can handle to more complex things like an open file, a spawned sub-process, an object of a class you write for managing solver program sessions, and so on.

You can find a simple demo exploiting the initialize-shutdown mechanism in the integration examples package.

Incoming Arguments

Common Incoming Key Word Arguments (KWARGs)

Return Values

Returns nothing or None.

shutdown

You can use the initialize and shutdown functions to create and close a Python work environment. In some use cases, it can be difficult to use separate, atomic, agnostic functions, so it may be easier to work in a session-based manner. The shutdown function allows you to close logs, any other open files, terminate sub-processes, close client program sessions, remote connections, and so on. In short, close down and tidy up the session workspace you have created with INI and which has evolved over many cycles of calling the other elementary integration functions.

Incoming Arguments

Common Incoming Key Word Arguments (KWARGs)

Return Values

Returns nothing or None.

get_required_license_caps

This function provides the license capabilities of the integration node plugin.

Incoming Arguments

Common Incoming Key Word Arguments (KWARGs)

Return Values

List of license capabilities as strings.

migrate_settings

This function can be used to update the settings of a node that was saved with an older version of the integration with different settings.

Incoming Arguments

Common Incoming Key Word Arguments (KWARGs)

Return Values

List with zero to two elements containing modifying_settings and/or non_modifying_settings as Python objects or lists of tuples.