-
Notifications
You must be signed in to change notification settings - Fork 3
Operator.md
ChunningZhou edited this page Mar 14, 2025
·
1 revision
The "Operator class" is a fundamental component in our graph modeling framework, which represents a constraint/operator object. It represents a type of node that can only be linked to Variable nodes, handling operations or constraints between groups of variables.
-
input_vars: List of input variables associated with the operator. -
output_vars: List of output variables associated with the operator. -
model_version: Integer indicating the version of the model that this operator is associated with. -
ID: Unique identifier string for the operator.
Returns the name of the operator's class.
- Returns a string representing the name of the operator's class.
op = Operator(input_vars=[var1, var2], output_vars=[var3], ID="op1")
print(op.display()) # Output: OperatorReturns the ID of a variable at a specified index from either the input or output list. It allows for returning either the full ID or a compressed version based on the unroll parameter.
-
in_out: String specifying whether to access an input ('in') or an output ('out') variable. -
index: Integer index of the variable in the specified list. -
index2(optional): Integer index for nested lists of variables, applicable when variables are structured in multi-dimensional arrays. -
unroll(optional): Boolean indicating whether to return the full ID or a compressed version. Defaults toFalsewhich compresses the ID.
-
String: The ID of the variable at the specified index. The format of the ID depends on the
unrollparameter.
# Example setup: Creating an instance of Operator with input and output variables
op = Operator(input_vars=[Variable(bitsize=8, ID="in_1"), Variable(bitsize=8, ID="in_2")],
output_vars=[Variable(bitsize=8, ID="out_1")],
ID="op1")
# Example 1: Get the ID of the first input variable without unrolling
input_id = op.get_var_ID('in', 0)
print(input_id) # Expected Output: "in_1"
# Example 2: Get the ID of the output variable with unrolling
output_id = op.get_var_ID('out', 0, unroll=True)
print(output_id) # Expected Output: "out_1"
# Example 3: Accessing a nested variable, assuming nested structure in inputs
# Here the second parameter index2 is used for nested structures
nested_input_id = op.get_var_ID('in', 0, 1, unroll=False)
print(nested_input_id) # Output depends on nested structure and ID compression