concepts.dsl.constraint.EqualityConstraint#
- class EqualityConstraint[source]#
Bases:
Constraint
A special constraint for equality constraints. It is equivalent to:
Constraint(Constraint.EQUAL, [left, right], rv)
Basically, it states
(left == right) == rv
Therefore, when rv is True, it states that left and right are equal, and when rv is False, it states that left and right are not equal.
Methods
Return the string representation of the constraint.
from_bool
(left, right[, rv, timestamp])Create an equality constraint from bool or optimistic values (represented as integers).
from_function
(function, args, rv)Create a constraint given a function, arguments, and return value.
replace_constants
(assignments)set_group
(group)Set the group of the constraint.
Attributes
Magic name for equality constraints.
Check if the constraint is an equality constraint.
Return True if the constraint is a group constraint.
Check if the constraint is in a group.
The function identifier, which is always
Constraint.EQUAL
.The arguments to the function.
The expected return value of the function.
An optional note for the constraint.
The group of the constraint.
The timestamp of the constraint.
- __init__(left, right, rv=None, timestamp=0)[source]#
Initialize an equality constraint.
- Parameters:
left (TensorValue | OptimisticValue) – the left hand side of the equality constraint.
right (TensorValue | OptimisticValue) – the right hand side of the equality constraint.
rv (TensorValue | OptimisticValue | None) – the expected return value of the equality constraint. If None, it will be set to True (i.e., left == right).
timestamp (int) – the timestamp of the constraint.
- __new__(**kwargs)#
- constraint_str()#
Return the string representation of the constraint.
- classmethod from_bool(left, right, rv=None, timestamp=0)[source]#
Create an equality constraint from bool or optimistic values (represented as integers).
- Parameters:
left (bool | int | OptimisticValue) – the left hand side of the equality constraint.
right (bool | int | OptimisticValue) – the right hand side of the equality constraint.
rv (bool | int | OptimisticValue | None) – the expected return value of the equality constraint. If None, it will be set to True (i.e., left == right).
timestamp (int) – the timestamp of the constraint.
- Returns:
The created equality constraint.
- Return type:
- classmethod from_function(function, args, rv)#
Create a constraint given a function, arguments, and return value.
- Parameters:
function (Function) – the function object.
args (Sequence[bool | int | Tensor | TensorValue | Any]) – the arguments of the function. The arguments can be bool, int, or torch.Tensor.
rv (bool | int | Tensor | TensorValue | Any) – the return value of the function. The return value can be bool, int, or torch.Tensor.
- Returns:
The created constraint.
- Return type:
- replace_constants(assignments)#
- Parameters:
assignments (Dict[int, TensorValue])
- Return type:
- set_group(group)#
Set the group of the constraint.
- Parameters:
group (GroupConstraint)
- EQUAL = '__EQ__'#
Magic name for equality constraints.
- arguments: Tuple[TensorValue | OptimisticValue, TensorValue | OptimisticValue]#
The arguments to the function.
- group: GroupConstraint | None#
The group of the constraint. None if the constraint is not in a group.
- rv: TensorValue | OptimisticValue#
The expected return value of the function.