Canonicalizers¶
Canonicalizers translate a verification problem into a solver-ready formulation (MIP or SDP), including optimization-based bound tightening (OBBT).
Canonicalizer
¶
A base class for mathematical-optimization canonicalizers. This class defines a common interface for mixed-integer programming (MIP) and semidefinite programming (SDP) encodings.
Subclasses declare a class-level _CANONICALIZERS dict mapping the
lowercase step class name (e.g. "relu") to the function that
encodes it. canonicalize looks up the function in this dict and
raises NotImplementedError if absent.
Attributes:
| Name | Type | Description |
|---|---|---|
solver |
Solver
|
A ready-to-use instance of a subclass of |
Source code in fomtools/canonicalizers/canonicalizer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
__init__
¶
__init__(solver_params: dict = None, solver: str = 'highs')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver_params
|
dict
|
Key-value pairs with solver parameters and their corresponding configuration values. |
None
|
solver
|
str
|
Case-insensitive identifier for the solver to use. Supported
values and common aliases include:
- |
'highs'
|
Source code in fomtools/canonicalizers/canonicalizer.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
add_constraint
¶
add_constraint(constraint: Constraint) -> None
Add a constraint to the canonicalizer instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
Constraint
|
Constraint object to add to the canonicalizer. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in fomtools/canonicalizers/canonicalizer.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
add_var
¶
add_var(iterate, **kwargs) -> None
Add a variable to the canonicalizer instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterate
|
LinearExpression
|
Linear expression object to add to the canonicalizer. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in fomtools/canonicalizers/canonicalizer.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
canonicalize
¶
canonicalize(step: Step)
Dispatch the provided step into a backend-specific encoding.
Looks up the lowercase step class name (e.g. "relu") in this
canonicalizer's _CANONICALIZERS registry and invokes the
corresponding encoder. Raises NotImplementedError if the step
type is not registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Step
|
The concrete step class to canonicalize. This class encapsulates the thresholding or activation operator. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If this canonicalizer's |
Source code in fomtools/canonicalizers/canonicalizer.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
copy
abstractmethod
¶
copy() -> Canonicalizer
Create an independent copy of this canonicalizer.
The copy shares no mutable state with the original and can be modified (e.g., adding objectives) without affecting the original.
Returns:
| Type | Description |
|---|---|
Canonicalizer
|
A new canonicalizer instance with copied state. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in fomtools/canonicalizers/canonicalizer.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
get_expression_bounds
¶
get_expression_bounds(expr: LinearExpression) -> tuple[ndarray, ndarray]
Compute bounds for a linear expression.
Uses OBBT if available for tighter bounds, otherwise falls back to interval bound propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
LinearExpression
|
The expression whose bounds are to be computed. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
A tuple (lb, ub) of lower and upper bounds. |
Source code in fomtools/canonicalizers/canonicalizer.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
set_infinity_norm_objective
¶
set_infinity_norm_objective(expr_list: list[LinearExpression], lb=None, ub=None) -> None
Set the objective to maximize the infinity-norm (maximum absolute value).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr_list
|
list[LinearExpression]
|
List of expressions whose maximum absolute value is the objective. |
required |
lb
|
ndarray
|
Lower bounds for the expressions (may be used by some backends). |
None
|
ub
|
ndarray
|
Upper bounds for the expressions (may be used by some backends). |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses that support this objective type. |
Source code in fomtools/canonicalizers/canonicalizer.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
set_one_norm_objective
¶
set_one_norm_objective(expr_list: list[LinearExpression]) -> None
Set the objective to maximize the one-norm (sum of absolute values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr_list
|
list[LinearExpression]
|
List of expressions whose one-norms are summed in the objective. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses that support this objective type. |
Source code in fomtools/canonicalizers/canonicalizer.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
set_two_norm_objective
¶
set_two_norm_objective(expr_list: list[LinearExpression], lb_list=None, ub_list=None) -> None
Set the objective to maximize the sum of squared two-norms.
Configures the optimization objective to compute sum_i ||expr_i||_2^2 over the given list of expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr_list
|
list[LinearExpression]
|
List of expressions whose squared norms are summed in the objective. |
required |
lb_list
|
list[ndarray]
|
Lower bounds for each expression (may be used by some backends). |
None
|
ub_list
|
list[ndarray]
|
Upper bounds for each expression (may be used by some backends). |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses that support this objective type. |
Source code in fomtools/canonicalizers/canonicalizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
update_bounds
¶
update_bounds(expression: LinearExpression, lb: float | ndarray, ub: float | ndarray) -> None
Update the lower and upper bounds of the solver variables corresponding
to the given LinearExpression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
LinearExpression
|
A |
required |
lb
|
float or ndarray
|
New lower bound(s). |
required |
ub
|
float or ndarray
|
New upper bound(s). |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in fomtools/canonicalizers/canonicalizer.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
MIP canonicalizer¶
MIP
¶
Bases: Canonicalizer
An interface for mixed-integer programming (MIP) methods.
Attributes:
| Name | Type | Description |
|---|---|---|
solver |
Solver
|
A ready-to-use instance of a subclass of |
_objective_spec |
tuple or None
|
Stored objective specification for deferred application. Applied to a copy of the solver at solve time. |
_solved_copy |
Solver or None
|
Reference to the solved copy of the solver, used for extracting solution values after solve. |
objective_branch_priority |
int
|
Branching priority given to the binaries of the infinity-norm objective (component selectors and signs); step binaries keep priority 0. Branching on the objective first splits the worst case by component and sign, which closes the bound much faster once the objective's big-M constants are tight. Set to 0 to disable. Solvers without branching priorities ignore it. |
Source code in fomtools/canonicalizers/mip.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 | |
add_constraint
¶
add_constraint(constraint: Constraint) -> None
Add a constraint to the MIP instance. This method registers a new constraint with the MIP problem and attaches it to the internal model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
Constraint
|
Constraint object to add to the MIP instance. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
add_constraints
¶
add_constraints(constraints: List[Constraint]) -> None
Add a list of constraints to the MIP instance. This method registers multiple constraints with the MIP problem and attaches them to the internal model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
List[Constraint]
|
List of constraints to add to the MIP instance. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
add_theory_cut
¶
add_theory_cut(margin: float, target_expr: LinearExpression, lb: float | ndarray, ub: float | ndarray)
Add relaxed bound constraints on the target expression up to the provided relaxation margin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
margin
|
float
|
Relaxation margin for the bounds. If finite, the lower bound is
shifted to |
required |
target_expr
|
LinearExpression
|
The expression whose bounds are to be relaxed. |
required |
lb
|
float | ndarray
|
Lower bound(s) for |
required |
ub
|
float | ndarray
|
Upper bound(s) for |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
add_var
¶
add_var(var: LinearExpression, **kwargs) -> None
Add a variable to the MIP instance. This method registers a new variable with the MIP program and attaches it to the internal model so it can be referenced in the constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
LinearExpression
|
Linear expression object to add to the MIP instance. Later to be used in an objective function, constraints, or parameters. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
canonicalize_affine
¶
canonicalize_affine(step: Affine) -> None
Construct the linear equality constraint corresponding to the affine iteration step. The constraint is used to express the affine update step in the verification problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Affine
|
An instance of the |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | |
canonicalize_relu
¶
canonicalize_relu(step: Relu)
Construct the convex-hull linear constraints corresponding
to the Rectified Linear Unit (ReLU) operator.
Given a ReLU step: \((\phi(v,x))_i = \mathbf{ReLU}(a^T y) = \max\{a^T y, 0\}.\)
This method derives the convex hull of the region defined by:
It then expresses it as a set of Constraint objects. The convex hull of the region is:
with
where:
- vector \(l^{0} \in \mathbb{R}^{d}\) with entries \(l_i^{0} = \underline{y}_i \text{ if } a_i \geq 0 \text{ and } \overline{y}_i\) otherwise,
- vector \(u^{0} \in \mathbb{R}^{d}\) with entries \(u_i^{0} = \overline{y}_i \text{ if } a_i \geq 0 \text{ and } \underline{y}_i\) otherwise,
- Given \(\textbf{I} \subseteq \textbf{J} = \left\{1, ..., n\right\}\), the lower bound is defined as \(l_I = \sum_{i \in I} a_i l_i^{0} + \sum_{i \notin I} a_i u_i^{0}\)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Relu
|
An instance of the |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | |
canonicalize_saturatedlinear
¶
canonicalize_saturatedlinear(step: SaturatedLinear)
Construct the convex-hull linear constraints corresponding to the saturated linear unit operator.
Given a saturated linear unit operator, defined as:
This method derives the convex hull of the region defined by:
It then expresses it as a set of Constraint objects. The convex hull of the region is:
with
where:
- vector \(l^{0} \in \mathbb{R}^{d}\) with entries \(l_i^{0} = \underline{y}_i \text{ if } a_i \geq 0 \text{ and } \overline{y}_i\) otherwise,
- vector \(u^{0} \in \mathbb{R}^{d}\) with entries \(u_i^{0} = \overline{y}_i \text{ if } a_i \geq 0 \text{ and } \underline{y}_i\) otherwise,
- Given \(\textbf{I} \subseteq \textbf{J} = \left\{1, ..., n\right\}\), the lower bound is defined as \(l_I = \sum_{i \in I} a_i l_i^{0} + \sum_{i \notin I} a_i u_i^{0}\) and the upper bound is \(u_I = \sum_{i \in I} a_i u_i^{0} + \sum_{i \notin I} a_i l_i^{0}\),
- \(\mathcal{I}^+ = \{ (I, o) \in 2^J \times J \mid \ell_I \ge b,\; \ell_{I \cup \{o\}} < b,\; w_I \neq 0 \},\)
- \(\mathcal{I}^- = \{ (I, o) \in 2^J \times J \mid u_I \le c,\; u_{I \cup \{o\}} > c,\; w_I \neq 0 \}.\)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
SaturatedLinear
|
An instance of the |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 | |
canonicalize_softthreshold
¶
canonicalize_softthreshold(step: SoftThreshold)
Construct the convex-hull linear constraints corresponding to the soft-thresholding operator.
Given a soft-thresholding operator for shrinkage, defined as:
where \(\mathcal{T}_{\lambda}\) is the soft-thresholding operator with constant \(\lambda>0\), and \(a\in\mathbf{R}^d\).
This method derives the convex hull of the region defined by:
It then expresses it as a set of Constraint objects. The convex hull of the region is:
with
where:
- vector \(l^{0} \in \mathbb{R}^{d}\) with entries \(l_i^{0} = \underline{y}_i \text{ if } a_i \geq 0 \text{ and } \overline{y}_i\) otherwise,
- vector \(u^{0} \in \mathbb{R}^{d}\) with entries \(u_i^{0} = \overline{y}_i \text{ if } a_i \geq 0 \text{ and } \underline{y}_i\) otherwise,
- Given \(\textbf{I} \subseteq \textbf{J} = \left\{1, ..., n\right\}\), the lower bound is defined as \(l_I = \sum_{i \in I} a_i l_i^{0} + \sum_{i \notin I} a_i u_i^{0}\) and the upper bound is \(u_I = \sum_{i \in I} a_i u_i^{0} + \sum_{i \notin I} a_i l_i^{0}\),
- \(\mathcal{I}^+ = \{ (I, o) \in 2^J \times J \mid \ell_I \ge \lambda,\; \ell_{I \cup \{o\}} < \lambda,\; w_I \neq 0 \},\)
- \(\mathcal{I}^- = \{ (I, o) \in 2^J \times J \mid u_I \le - \lambda,\; u_{I \cup \{o\}} > -\lambda,\; w_I \neq 0 \}.\)
- \(w_I\) is the slice of vector \(w\) over \(I\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
SoftThreshold
|
An instance of the |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 | |
copy
¶
copy() -> MIP
Create an independent copy of this MIP canonicalizer.
Returns a new MIP canonicalizer with a copied solver. The copy can be modified without affecting the original.
Returns:
| Type | Description |
|---|---|
MIP
|
A new canonicalizer instance with copied state. |
Source code in fomtools/canonicalizers/mip.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
get_solution_value
¶
get_solution_value(expression: LinearExpression) -> ndarray
Return the solution value for the given LinearExpression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
LinearExpression
|
The expression whose solution value is to be computed. Each element in its decomposition must have been registered with the solver. |
required |
Returns:
| Type | Description |
|---|---|
ndarray[float]
|
A 1-D array of shape |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no solution is available (solve_model() not called). |
Source code in fomtools/canonicalizers/mip.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
separate_hull_cuts
¶
separate_hull_cuts(tol: float = 1e-06) -> List[Constraint]
Separate the root LP optimum from the convex hulls of the steps.
Copies the model (which carries every cut added so far), applies the
objective, solves the continuous relaxation and returns the most violated
hull inequality of every unstable step component. The model itself is not
modified; Verifier.solve adds the returned cuts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tol
|
float
|
Minimum violation for a cut to be returned. |
1e-06
|
Returns:
| Type | Description |
|---|---|
List[Constraint]
|
The separated cuts. |
Source code in fomtools/canonicalizers/mip.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
set_infinity_norm_objective
¶
set_infinity_norm_objective(expr_list, lb_list, ub_list)
Store infinity-norm objective specification for deferred application.
Source code in fomtools/canonicalizers/mip.py
281 282 283 | |
set_one_norm_objective
¶
set_one_norm_objective(expr_list)
Store one-norm objective specification for deferred application.
Source code in fomtools/canonicalizers/mip.py
289 290 291 | |
set_start_samples
¶
set_start_samples(samples: dict) -> None
Samples of input leaves for the sample-max warm start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
dict
|
|
required |
Source code in fomtools/canonicalizers/mip.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
set_two_norm_objective
¶
set_two_norm_objective(expr_list, lb_list, ub_list)
Store two-norm objective specification for deferred application.
Source code in fomtools/canonicalizers/mip.py
285 286 287 | |
set_zero_objective
¶
set_zero_objective()
Store zero objective specification for deferred application.
Source code in fomtools/canonicalizers/mip.py
277 278 279 | |
solve_model
¶
solve_model(warm_start: bool = True, **solver_kwargs) -> float
Optimize the underlying MIP problem.
Creates a copy of the solver, applies the objective to the copy,
solves it, and keeps a reference for solution extraction.
This prevents objective constraints from accumulating across
multiple solve calls. Convex hull cuts are added to the model
beforehand by Verifier.solve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warm_start
|
bool
|
Give the solver up to two starts: the inputs of the previous
solution's worst case run through the current steps, and the
worst sample of |
True
|
**solver_kwargs
|
Native solver options forwarded verbatim to the backend
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
The finite best upper bound on the maximization objective, including
after a time limit. Raises |
Source code in fomtools/canonicalizers/mip.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
tighten_objective_bounds
¶
tighten_objective_bounds(pad: float = 1e-06) -> dict | None
Replace the interval bounds of an infinity-norm objective with OBBT bounds.
The infinity-norm encoding takes its big-M constants (the global M and
the per-component sign constants) from bounds on each residual component.
Any bounds that hold on every feasible point keep the optimum exact, so the
interval-propagation bounds set with the objective are intersected with
the minimum and maximum of each component over the OBBT LP. The OBBT
values are padded outward by pad * max(1, |bound|) to absorb the LP
solver's feasibility tolerance, then clipped back into the interval
bounds, which are exactly valid.
Does nothing unless the objective is an infinity norm and an OBBT handler is attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
float
|
Relative outward padding of the OBBT bounds. |
1e-06
|
Returns:
| Type | Description |
|---|---|
dict or None
|
|
Source code in fomtools/canonicalizers/mip.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
update_bounds
¶
update_bounds(expression: LinearExpression, lb: float | ndarray, ub: float | ndarray)
Update the lower and upper bounds of the solver variables corresponding
to the given LinearExpression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
LinearExpression
|
A |
required |
lb
|
float | ndarray
|
New lower bound(s). |
required |
ub
|
float | ndarray
|
New upper bound(s). |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/mip.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
OBBT handler¶
OBBTHandler
¶
Bases: Canonicalizer
Handler for Optimization-Based Bound Tightening (OBBT).
This class provides an interface for tightening variable bounds using optimization. It maintains a separate solver instance that is used to compute tighter lower and upper bounds on variables by solving minimization and maximization problems.
Attributes:
| Name | Type | Description |
|---|---|---|
solver |
Solver
|
A ready-to-use instance of a subclass of |
crossing_tol |
float
|
Largest relative crossing |
crossing_repairs |
int
|
Number of bound entries repaired this way so far. |
Source code in fomtools/canonicalizers/obbt_handler.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
__init__
¶
__init__(solver: str, solver_params: dict = None, crossing_tol: float = 1e-06)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
str
|
Case-insensitive identifier for the solver to use. Supported
values (and common aliases) include:
- |
required |
solver_params
|
dict or None
|
Parameters passed verbatim to the OBBT solver (e.g.
|
None
|
crossing_tol
|
float
|
See the class attribute of the same name. |
1e-6
|
Source code in fomtools/canonicalizers/obbt_handler.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
add_constraint
¶
add_constraint(constraint: Constraint) -> None
Add a constraint to the OBBT handler instance.
This method registers a constraint with the OBBT solver so it is considered during bound tightening optimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
Constraint
|
Constraint object to add to the OBBT instance. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/obbt_handler.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
add_constraints
¶
add_constraints(constraints: List[Constraint]) -> None
Add a list of constraints to the OBBT handler instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
List[Constraint]
|
Constraint objects to add to the OBBT instance. Every constraint must be binary-free (the OBBT model is a pure linear program). |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/obbt_handler.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
add_var
¶
add_var(var: LinearExpression) -> None
Add a variable to the OBBT handler instance.
This method registers a new variable with the OBBT solver so it can be used in bound tightening optimization problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
LinearExpression
|
Linear expression object to add to the OBBT instance. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/obbt_handler.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
canonicalize_affine
¶
canonicalize_affine(step: Affine) -> None
Add the affine equality output_mat @ output == arg to the OBBT LP.
output_mat is a documented attribute of the Affine step
interface; this mirrors MIP.canonicalize_affine exactly (both rely
on the same equality), so the two stay consistent if Affine is
refactored.
Source code in fomtools/canonicalizers/obbt_handler.py
240 241 242 243 244 245 246 247 248 249 | |
canonicalize_relu
¶
canonicalize_relu(step: Relu) -> None
Add the binary-free ReLU relaxation rows to the OBBT LP.
Mirrors MIP._build_relu_constraints keeping only the equality
cases and, for the uncertain region, the triangle envelope
{ output >= arg, output <= ub/(ub-lb) * (arg - lb) }. The big-M rows are
dropped. Iterates proj_indices only — for partial-projection
ReLU the non-proj rows of step.output share decomposition with
step.arg (composite passthrough), so emitting output[i] == arg[i]
would reduce to a degenerate 0 == 0 that the solver rejects.
Source code in fomtools/canonicalizers/obbt_handler.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
canonicalize_saturatedlinear
¶
canonicalize_saturatedlinear(step: SaturatedLinear) -> None
Add the binary-free saturated-linear relaxation rows to the OBBT LP.
Mirrors MIP.canonicalize_saturatedlinear keeping only the
saturated/pass-through equalities and the convex-envelope slope rows;
all big-M rows are dropped.
Source code in fomtools/canonicalizers/obbt_handler.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
canonicalize_softthreshold
¶
canonicalize_softthreshold(step: SoftThreshold) -> None
Add the binary-free soft-threshold relaxation rows to the OBBT LP.
Mirrors MIP.canonicalize_softthreshold keeping only the fixed-region
equalities and the convex-envelope rows; all big-M rows are dropped.
Source code in fomtools/canonicalizers/obbt_handler.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
obbt
¶
obbt(linexpr: LinearExpression, lb: ndarray, ub: ndarray) -> tuple[ndarray, ndarray] | None
Perform Optimization-Based Bound Tightening on a linear expression.
For each element in the linear expression, this method solves
minimization and maximization problems to compute potentially
tighter bounds. The returned bounds are the intersection of the
input bounds and the computed bounds, padded outward by
1e-6 * max(1, abs(bound)). This does not certify rounding errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linexpr
|
LinearExpression
|
The linear expression whose bounds are to be tightened. |
required |
lb
|
ndarray
|
Current lower bounds for each element of the expression. |
required |
ub
|
ndarray
|
Current upper bounds for each element of the expression. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray] | None
|
A tuple |
Source code in fomtools/canonicalizers/obbt_handler.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
update_bounds
¶
update_bounds(expression: LinearExpression, lb: float | ndarray, ub: float | ndarray) -> None
Update the lower and upper bounds of the solver variables corresponding
to the given LinearExpression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
LinearExpression
|
A |
required |
lb
|
float or ndarray
|
New lower bound(s). |
required |
ub
|
float or ndarray
|
New upper bound(s). |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/obbt_handler.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
Simulator¶
Simulator
¶
Bases: Canonicalizer
An interface for simulating a Verification Problem using CuPy.
Steps are recorded during canonicalization and compiled into efficient batched functions at solve time. This deferred-compilation approach allows an arbitrary sequence of steps to be registered incrementally (matching the MIP/SDP user experience) and then evaluated in a single forward pass over all parameter samples.
Attributes:
| Name | Type | Description |
|---|---|---|
param_to_samples |
dict[LinearExpression, ndarray]
|
A dictionary mapping each parameter variable (LinearExpression) to its sample values. Each array should have shape (num_samples, dim), where dim is the dimensionality of the parameter. |
iterate_to_samples |
dict[LinearExpression, ndarray]
|
A dictionary mapping each iterate variable (a LinearExpression) to its initial values. Each array should have shape (dim,), representing the initial state for that iterate. |
step_descriptors |
list[tuple[Step, Callable]]
|
A list of (step, activation) tuples recorded during canonicalization. Each activation is a callable that applies the step-specific nonlinearity to the assembled arg result. |
residual_specs |
dict[int, tuple[list[LinearExpression], int | float | str]]
|
A dictionary mapping step indices to (expr_list, norm_ord) tuples that define how residuals are computed at each step. |
device |
int
|
GPU device ID for CuPy execution. |
Source code in fomtools/canonicalizers/simulator.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 | |
add_var
¶
add_var(var: LinearExpression, **kwargs) -> None
Add a variable to the Simulator instance. This method converts the provided LinearExpression object to a CuPy array and registers it with the Simulator instance so that it can be referenced later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
LinearExpression
|
Linear expression object to add to the Simulator instance. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in fomtools/canonicalizers/simulator.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
canonicalize_affine
¶
canonicalize_affine(step: Step) -> None
Record the provided affine step for deferred evaluation at solve time.
The LU factorization of step.output_mat is computed eagerly since
it depends only on a constant matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Step
|
A step object that represents the affine transformation. |
required |
Source code in fomtools/canonicalizers/simulator.py
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | |
canonicalize_relu
¶
canonicalize_relu(step: Step) -> None
Record the provided ReLU step for deferred evaluation at solve time.
The activation evaluates ReLU on the projected arg coords selected by
step.proj_indices and writes them into step.output_leaves[0].
For full ReLU, proj_indices covers every arg row and the fancy
index is the identity slice. For partial-projection ReLU, non-proj
rows of step.output share decomposition with step.arg and are
read off the existing arg leaves at evaluation time — no separate
storage needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Step
|
A step object containing the ReLU operation. |
required |
Source code in fomtools/canonicalizers/simulator.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 | |
canonicalize_saturatedlinear
¶
canonicalize_saturatedlinear(step: Step) -> None
Record the provided saturated linear step for deferred evaluation at solve time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Step
|
A step object that represents a saturated linear operation. |
required |
Source code in fomtools/canonicalizers/simulator.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | |
canonicalize_softthreshold
¶
canonicalize_softthreshold(step: Step) -> None
Record the provided soft-threshold step for deferred evaluation at solve time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Step
|
A step object containing the soft-threshold operation. |
required |
Source code in fomtools/canonicalizers/simulator.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
compute_risk_bound
staticmethod
¶
compute_risk_bound(residuals: ndarray, delta: float = 0.05, epsilon: float = 0.0)
Compute a high-probability bound on the risk using the KL inverse bound.
Given a tolerance \(\epsilon\), a number of iterations \(k\) (implicitly given by the last
column of residuals), and \(N\) sampled problem instances,
we define the \(0\)–\(1\) error for sample \(x\) as
which in this implementation corresponds to checking whether the final residual exceeds \(\epsilon\).
Let \(N\) be the number of samples and let the empirical risk be
where \(r_i^{(k)}\) is the final residual of trajectory \(i\).
Then, with probability at least \(1 - \delta\), the true risk \(r\) satisfies
where \(\mathrm{kl}^{-1}(q \mid c)\) denotes the largest \(p \in [q,1]\) such that
and
is the binary Kullback–Leibler divergence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residuals
|
ndarray
|
Residuals of the problem instances. |
required |
delta
|
float
|
Confidence parameter \(\delta \in (0,1)\). The bound holds with probability at least \(1 - \delta\). |
0.05
|
epsilon
|
float
|
Tolerance level \(\epsilon\) defining the \(0\)–\(1\) error. |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Upper bound on true risk via KL inverse. |
Source code in fomtools/canonicalizers/simulator.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
record_iterate
¶
record_iterate(expression)
Record a public operation's output after all its internal steps.
Source code in fomtools/canonicalizers/simulator.py
1238 1239 1240 | |
register_subproblem_step
¶
register_subproblem_step(arg: LinearExpression, output_leaf: LinearExpression, activation) -> None
Record a subproblem step for deferred evaluation at solve time.
Used by the step decomposer for proxes/steps that have no Step class
on the simulator (projections onto the simplex / ℓ1-ball, the ℓ∞-norm and
total-variation proxes, polyhedral projections, and inequality QP/LP). The
activation is a callable mapping the assembled input batch
(N, arg.ndim) to the output batch (N, output_leaf.ndim); the result
is written into output_leaf's slot. See the subproblem activation
factories defined in this module (e.g. simplex_activation,
qp_activation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
LinearExpression
|
The assembled per-sample input to the subproblem. |
required |
output_leaf
|
LinearExpression
|
The fresh leaf the activation result is written into. |
required |
activation
|
Callable
|
Maps the input batch to the output batch. |
required |
Source code in fomtools/canonicalizers/simulator.py
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
set_infinity_norm_objective
¶
set_infinity_norm_objective(expr_list, lb_list=None, ub_list=None)
Record an infinity-norm residual expression at the most recently registered step.
Source code in fomtools/canonicalizers/simulator.py
1127 1128 1129 | |
set_one_norm_objective
¶
set_one_norm_objective(expr_list)
Record a one-norm residual expression at the most recently registered step.
Source code in fomtools/canonicalizers/simulator.py
1135 1136 1137 | |
set_two_norm_objective
¶
set_two_norm_objective(expr_list, lb_list=None, ub_list=None)
Record a squared two-norm residual expression at the most recently registered step.
Source code in fomtools/canonicalizers/simulator.py
1131 1132 1133 | |
set_zero_objective
¶
set_zero_objective()
Record a zero residual at the most recently registered step.
Source code in fomtools/canonicalizers/simulator.py
1123 1124 1125 | |
solve_model
¶
solve_model(delta: float = 0.05, epsilon: float = 0.0, device: str = None) -> ndarray
Run a batched simulation of all registered steps.
Each call re-simulates from scratch: the value table is rebuilt, all steps are compiled and executed in sequence, and residuals are computed. This method can be called repeatedly (e.g. inside the user's iteration loop) as new steps are registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
float
|
Confidence parameter for the risk bound. |
0.05
|
epsilon
|
float
|
Tolerance level defining the 0–1 error. |
0.0
|
device
|
str
|
Device to run the simulation on ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
residuals |
ndarray
|
A 2D array of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no steps have been registered. |
Source code in fomtools/canonicalizers/simulator.py
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 | |
condat_tv_1d
¶
condat_tv_1d(y: ndarray, lam: float) -> ndarray
1-D total-variation prox via Condat's O(n) direct algorithm.
Computes argmin_x 1/2 ||x - y||^2 + lam * sum_i |x_{i+1} - x_i| exactly in a
single forward pass (Condat, "A Direct Algorithm for 1-D Total Variation
Denoising", 2013). lam <= 0 or length < 2 returns a copy of y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
(n,) np.ndarray
|
Input signal. |
required |
lam
|
float
|
Total-variation weight. |
required |
Returns:
| Type | Description |
|---|---|
(n,) np.ndarray
|
The proximal point. |
Source code in fomtools/canonicalizers/simulator.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
l1_ball_activation
¶
l1_ball_activation(r: float)
Activation projecting each sample onto the ℓ1-ball of radius r.
Source code in fomtools/canonicalizers/simulator.py
187 188 189 | |
norm_inf_activation
¶
norm_inf_activation(radius: float)
Activation for the ℓ∞-norm prox via Moreau: v - proj_{||.||_1 <= radius}(v).
Source code in fomtools/canonicalizers/simulator.py
192 193 194 | |
polyhedral_activation
¶
polyhedral_activation(A: ndarray, b, n: int, m: int, b_is_param: bool)
Activation projecting each sample onto {u : A u <= b} with cvxpy.
Builds a single parameterized (DPP) projection problem and solves it per sample.
The input batch has the point in its first n columns; when b is a
parameter (b_is_param), the next m columns carry the per-sample b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
(m, n) np.ndarray
|
Inequality matrix. |
required |
b
|
(m,) np.ndarray or None
|
Fixed right-hand side when |
required |
n
|
int
|
Point and constraint dimensions. |
required |
m
|
int
|
Point and constraint dimensions. |
required |
b_is_param
|
bool
|
Whether |
required |
Notes
The per-sample loop runs on host (cvxpy/CLARABEL has no GPU backend); on a GPU run
each call moves the batch device→host and the result back (see _to_numpy).
Source code in fomtools/canonicalizers/simulator.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
project_l1_ball_batch
¶
project_l1_ball_batch(V, r: float)
Euclidean projection of each row of V onto {u : ||u||_1 <= r}.
Rows already inside the ball are returned unchanged; rows outside are
projected via sign(V) * project_simplex_batch(|V|, r). No Python loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
V
|
(N, n) array (numpy or cupy)
|
Points to project. |
required |
r
|
float
|
Ball radius ( |
required |
Returns:
| Type | Description |
|---|---|
(N, n) array
|
The row-wise projections. |
Source code in fomtools/canonicalizers/simulator.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
project_simplex_batch
¶
project_simplex_batch(V, a: float)
Euclidean projection of each row of V onto {u >= 0, 1^T u = a}.
Vectorized Held–Wolfe / Duchi (2008) sort algorithm: for a > 0 the
threshold theta is found per row from the descending sort and cumulative
sums, and the projection is max(V - theta, 0). No Python loop over the
batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
V
|
(N, n) array (numpy or cupy)
|
Points to project (one per row). |
required |
a
|
float
|
Positive simplex sum. |
required |
Returns:
| Type | Description |
|---|---|
(N, n) array
|
The row-wise projections. |
Source code in fomtools/canonicalizers/simulator.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
qp_activation
¶
qp_activation(P, A, C, n: int, p: int, m: int, is_lp: bool)
Activation solving a QP/LP per sample with cvxpy.
Builds a single parameterized (DPP) problem minimize 0.5 x^T P x + q^T x s.t.
A x = b, C x <= d (the quadratic term is dropped when is_lp) and solves it
per sample. The input batch stacks the present parametric blocks in the order
[q (n) | b (p) | d (m)].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
(n, n) array or None
|
Quadratic term (ignored when |
required |
A
|
(p, n) array or None
|
Equality matrix ( |
required |
C
|
(m, n) array or None
|
Inequality matrix ( |
required |
n
|
int
|
Primal / equality / inequality dimensions. |
required |
p
|
int
|
Primal / equality / inequality dimensions. |
required |
m
|
int
|
Primal / equality / inequality dimensions. |
required |
is_lp
|
bool
|
Drop the quadratic term (linear program). |
required |
Notes
The per-sample loop runs on host (cvxpy/CLARABEL has no GPU backend); on a GPU run
each call moves the batch device→host and the result back (see _to_numpy).
Source code in fomtools/canonicalizers/simulator.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
simplex_activation
¶
simplex_activation(a: float)
Activation projecting each sample onto the scaled simplex.
Source code in fomtools/canonicalizers/simulator.py
182 183 184 | |
tv_activation
¶
tv_activation(lam: float)
Activation applying Condat's TV prox to each sample (looped on host).
Host-side loop: on a GPU run the batch is moved device→host and the result back
(see _to_numpy).
Source code in fomtools/canonicalizers/simulator.py
299 300 301 302 303 304 305 306 307 308 309 310 311 | |
SDP canonicalizer¶
SDP
¶
Bases: Canonicalizer
Semidefinite programming canonicalizer for verification problems.
This class converts verification problems involving ReLU and other piecewise linear operations into semidefinite programming (SDP) formulations. It builds the SDP problem incrementally by adding variables and constraints, then solves using Clarabel or CVXPY.
The SDP uses a lifted matrix variable X where X[0,0] = 1 (homogenization). Variables are embedded in the diagonal blocks, and constraints are encoded as linear matrix inequalities.
Attributes:
| Name | Type | Description |
|---|---|---|
solver_name |
str
|
Name of the SDP solver backend ('clarabel', 'cvxpy', 'cuclarabel'). |
range_marker |
int
|
Current dimension of the SDP matrix variable. |
var_idx_map |
dict
|
Mapping from LinearExpression to (start_idx, end_idx) in SDP matrix. |
Aeq_matrices |
list[csc_matrix]
|
Equality constraint matrices. |
beq_consts |
list[float]
|
Equality constraint right-hand sides. |
Aineq_matrices |
list[csc_matrix]
|
Inequality constraint matrices. |
bineq_upperbounds |
list[float]
|
Inequality constraint upper bounds. |
psd_cone_indices |
list[set]
|
Indices defining PSD cone constraints. |
bound_constraint_indices |
dict
|
Mapping from variable to its bound constraint indices. |
rlt_cuts |
bool
|
If True, add RLT (Reformulation-Linearization Technique) cuts
between off-diagonal pairs of SDP indices that co-exist in some
|
triangle_cuts |
bool
|
If True, add lifted triangle cuts for every ReLU step's mixed-bound output rows. Each cut multiplies the per-output triangle inequality by a nonneg bound multiplier, yielding a quadratic-in-X inequality. See paper §4.5 eq 25/26. |
C_obj |
csc_matrix
|
Objective matrix for maximization. |
Source code in fomtools/canonicalizers/sdp.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 | |
__init__
¶
__init__(solver_params=None, solver='clarabel', rlt_cuts=False, triangle_cuts=False, ineq_product_cuts=True, ineq_box_cuts=True, ineq_square_cuts=True, relu_envelope_cuts=False, rlt_all_pairs=False, full_psd_cone=False, cross_cut=False, subgrad_mono_cut=False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver_params
|
dict
|
Dictionary of solver-specific parameters to pass to the backend. |
None
|
solver
|
str
|
Name of the SDP solver to use. Options: 'clarabel', 'cvxpy', 'cuclarabel'. |
'clarabel'
|
rlt_cuts
|
bool
|
If True, add RLT (Reformulation-Linearization Technique) cuts between cone-mate SDP indices to tighten the relaxation. |
False
|
triangle_cuts
|
bool
|
If True, add lifted triangle cuts for ReLU steps with mixed-bound output dimensions to tighten the relaxation. |
False
|
ineq_product_cuts
|
bool
|
For each inequality constraint |
True
|
ineq_box_cuts
|
bool
|
For each inequality constraint, add the RLT products of the constraint
with the variable box bounds ( |
True
|
ineq_square_cuts
|
bool
|
For each inequality constraint, add the self-square upper bound
|
True
|
relu_envelope_cuts
|
bool
|
If True, add the linear ReLU convex-hull inequalities on the
first-moment (vector) variables: the lower envelope |
False
|
rlt_all_pairs
|
bool
|
If True, RLT every pair of variables (not just cone-mates) by
registering a cheap |
False
|
full_psd_cone
|
bool
|
If True, union all PSD cones into a single full moment-matrix block
at solve time. Combined with |
False
|
cross_cut
|
bool
|
If True, add the PEP "cross" interpolation cuts |
False
|
subgrad_mono_cut
|
bool
|
If True, add the PEP subgradient-monotonicity cuts
|
False
|
Source code in fomtools/canonicalizers/sdp.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
add_constraint
¶
add_constraint(constraint: Constraint) -> None
Add a constraint to the SDP instance.
Dispatches to the appropriate implementation based on the constraint operator type (equality or inequality).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
Constraint
|
Constraint object to add to the SDP instance. |
required |
Source code in fomtools/canonicalizers/sdp.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
add_param_stack_var
¶
add_param_stack_var(param_stack_var, param_list)
Stack parameter variables (not implemented for SDP).
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not supported in the SDP canonicalizer. |
Source code in fomtools/canonicalizers/sdp.py
348 349 350 351 352 353 354 355 356 357 | |
add_psd_cone_indices
¶
add_psd_cone_indices(new_indices)
Register a new PSD cone constraint on a submatrix.
Adds the constraint that the submatrix of X indexed by new_indices
(including the homogenization index 0) is positive semidefinite.
This method maintains an antichain: no stored set is a subset of another. If a matrix X is PSD, any principal submatrix is also PSD, so subset constraints are redundant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_indices
|
list[tuple[int, int]]
|
List of (start, end) index ranges defining the submatrix. Index 0 is automatically included for homogenization. |
required |
Source code in fomtools/canonicalizers/sdp.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
add_theory_cut
¶
add_theory_cut(margin: float, target_expr: LinearExpression, lb: float | ndarray, ub: float | ndarray)
Add theory cut constraints (not yet implemented for SDP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
margin
|
float
|
Relaxation margin for the bounds. |
required |
target_expr
|
LinearExpression
|
The expression whose bounds are to be relaxed. |
required |
lb
|
float | ndarray
|
Lower bound(s) for target_expr. |
required |
ub
|
float | ndarray
|
Upper bound(s) for target_expr. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented for the SDP canonicalizer. |
Source code in fomtools/canonicalizers/sdp.py
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
add_var
¶
add_var(var: LinearExpression, **kwargs) -> None
Add a variable to the SDP with bound constraints.
Embeds the variable in the SDP matrix diagonal and adds quadratic bound constraints of the form (x - l)(x - u) <= 0 for each component, which encode the box constraints l <= x <= u.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
LinearExpression
|
The variable to add. Must have finite bounds in |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If any bound is infinite. |
Source code in fomtools/canonicalizers/sdp.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
canonicalize_affine
¶
canonicalize_affine(step: Affine) -> None
Encode an Affine step as a linear equality constraint.
The Affine step asserts step.output_mat @ step.output == step.arg;
this is the same equality MIP encodes (mip.py:404). On SDP it
flows through add_constraint → _add_equality_constraint_impl,
which emits the linear matrix, the quadratic strengthening, and
the PSD cone membership for the involved leaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Affine
|
The affine step to canonicalize. |
required |
Source code in fomtools/canonicalizers/sdp.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | |
canonicalize_relu
¶
canonicalize_relu(step: Relu) -> None
Encode a ReLU step as SDP constraints.
Converts the relationship y = ReLU(Ax + b) into equality constraints on the SDP matrix variable and registers the appropriate PSD cone constraint for the lifted formulation.
Operates uniformly over step.proj_indices and binds equalities to
step.output_leaves[0]. For full ReLU, proj_indices covers every
arg row and output_leaves[0] is the full output leaf — equivalent to a
standard full-output encoding. For partial-projection ReLU, only the
projected rows get lifted equalities and output_leaves[0] is the
smaller fresh proj-leaf; the non-projected rows are structurally
fused into shared arg leaves at composition time, so no equalities
and no SDP rows are emitted for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
Relu
|
The ReLU step containing input expression (arg) and output variable (output). |
required |
Source code in fomtools/canonicalizers/sdp.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
copy
¶
copy() -> SDP
Create an independent copy of this SDP canonicalizer.
Returns a new SDP canonicalizer with deep copies of all mutable state (constraint matrices, cone indices, etc.). The copy can be modified without affecting the original.
Returns:
| Type | Description |
|---|---|
SDP
|
A new canonicalizer instance with copied state. |
Source code in fomtools/canonicalizers/sdp.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
get_sdp_var_dim
¶
get_sdp_var_dim() -> int
Get the current dimension of the SDP matrix variable.
Returns:
| Type | Description |
|---|---|
int
|
The current size of the symmetric matrix variable X. |
Source code in fomtools/canonicalizers/sdp.py
279 280 281 282 283 284 285 286 287 288 | |
get_solution_value
¶
get_solution_value(expression: LinearExpression) -> ndarray
Get the solution value for an expression (not yet implemented for SDP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
LinearExpression
|
The expression to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The solution values. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented for the SDP canonicalizer. |
Source code in fomtools/canonicalizers/sdp.py
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 | |
linexpr_to_Amat_and_bounds
¶
linexpr_to_Amat_and_bounds(expr: LinearExpression)
Extract the coefficient matrix and SDP indices from a LinearExpression.
Converts a LinearExpression of the form Ax + b into the coefficient matrix A and the index ranges where the corresponding variables are located in the SDP matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
LinearExpression
|
The expression to decompose. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, list[tuple[int, int]]]
|
A tuple containing: - The horizontally stacked coefficient matrix. - List of (start, end) index bounds for each variable block. |
Source code in fomtools/canonicalizers/sdp.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | |
register_box_prox_step
¶
register_box_prox_step(z: LinearExpression, v: LinearExpression, l, u) -> None
Register a saturated-linear (box projection) step for the PEP box cuts.
Records (z, v, l, u) where z = clip(v, l, u) is the composite
projection output (relu(v - l) - relu(v - u) + l in the SDP lift), v
is the input expression (step.arg; residual r = v - z), and l /
u are the box bounds (constant arrays or LinearExpression if
parametric). Consumed by _build_box_normalcone_cuts (under
cross_cut) and _build_box_mono_cuts (under subgrad_mono_cut).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
LinearExpression
|
Box-projection output (composite); leaves already in |
required |
v
|
LinearExpression
|
Box-projection input ( |
required |
l
|
ndarray | LinearExpression
|
Lower/upper box bounds (per the operator's |
required |
u
|
ndarray | LinearExpression
|
Lower/upper box bounds (per the operator's |
required |
Source code in fomtools/canonicalizers/sdp.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
register_prox_step
¶
register_prox_step(z: LinearExpression, v: LinearExpression, tau: float, *, func: str) -> None
Register a prox step for the subgradient-monotonicity cut.
Records (z, v, tau, func) where z is the prox output expression,
v is the prox input expression (so the subgradient is s = v - z),
tau is the prox threshold (tau = 1 for orthant projection / ReLU,
tau = lambda for soft-thresholding), and func names the sublinear
function the step is the prox of. The subgradient cut builder
(_build_subgrad_mono_cuts) consumes this registry and pairs only
steps with the same func (the cut is invalid across functions).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
LinearExpression
|
Prox output. May be composite (e.g. |
required |
v
|
LinearExpression
|
Prox input ( |
required |
tau
|
float
|
Prox threshold used to normalize the subgradient. |
required |
func
|
str
|
Identifier of the sublinear function ( |
required |
Source code in fomtools/canonicalizers/sdp.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | |
set_infinity_norm_objective
¶
set_infinity_norm_objective(expr_list, lb=None, ub=None) -> None
Store infinity-norm objective specification for deferred application.
Uses the identities: - abs(x) = relu(x) + relu(-x) - max(a, b) = a + relu(b - a)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr_list
|
list[LinearExpression]
|
List of expressions whose infinity-norm maximum is the objective. |
required |
lb
|
optional
|
Unused (kept for interface compatibility with MIP). |
None
|
ub
|
optional
|
Unused (kept for interface compatibility with MIP). |
None
|
Source code in fomtools/canonicalizers/sdp.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
set_one_norm_objective
¶
set_one_norm_objective(expr_list) -> None
Store one-norm objective specification for deferred application.
The objective will be applied to a copy of the canonicalizer at solve time using the identity: ||x||_1 = 1^T @ (relu(x) + relu(-x)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr_list
|
list[LinearExpression]
|
List of expressions whose one-norms are summed in the objective. |
required |
Source code in fomtools/canonicalizers/sdp.py
946 947 948 949 950 951 952 953 954 955 956 957 958 | |
set_two_norm_objective
¶
set_two_norm_objective(expr_list, lb_list=None, ub_list=None) -> None
Store two-norm objective specification for deferred application.
The objective will be applied to a copy of the canonicalizer at solve time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr_list
|
list[LinearExpression]
|
List of expressions whose squared norms are summed in the objective. |
required |
lb_list
|
list[ndarray]
|
Lower bounds for each expression (unused in SDP, for interface consistency). |
None
|
ub_list
|
list[ndarray]
|
Upper bounds for each expression (unused in SDP, for interface consistency). |
None
|
Source code in fomtools/canonicalizers/sdp.py
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
set_zero_objective
¶
set_zero_objective()
Set objective to zero (not yet implemented for SDP).
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method is not yet implemented for the SDP canonicalizer. |
Source code in fomtools/canonicalizers/sdp.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | |
solve_model
¶
solve_model(steps=None, convex_hull_cuts=False, **solver_kwargs)
Solve the SDP problem using the configured solver.
Creates a copy of the canonicalizer, applies the objective to the copy, solves it, and keeps a reference for future use. This prevents objective constraints from accumulating across multiple solve calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
list
|
Unused by SDP, accepted for API compatibility. |
None
|
convex_hull_cuts
|
bool
|
Unused by SDP, accepted for API compatibility. |
False
|
**solver_kwargs
|
Native solver options forwarded verbatim to the backend
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
The objective value. |
Source code in fomtools/canonicalizers/sdp.py
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 | |
solve_via_clarabel
¶
solve_via_clarabel(**solver_kwargs)
Solve the SDP using the native Clarabel interface.
Directly invokes the Clarabel solver without going through CVXPY, which can be more efficient for large problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**solver_kwargs
|
Native Clarabel settings forwarded verbatim to the solver. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
The optimal objective value. |
Source code in fomtools/canonicalizers/sdp.py
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 | |
solve_via_cuclarabel
¶
solve_via_cuclarabel(**solver_kwargs)
Solve the SDP using GPU-accelerated Clarabel.
Uses the CUDA-enabled Clarabel solver for GPU acceleration. Requires CuPy and Julia with CUDA.jl and Clarabel.jl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**solver_kwargs
|
Native Clarabel settings forwarded verbatim to the solver. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
The optimal objective value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If CUDA dependencies (cupy) are not available. |
Source code in fomtools/canonicalizers/sdp.py
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 | |
solve_via_cvxpy
¶
solve_via_cvxpy(**solver_kwargs)
Solve the SDP using the CVXPY modeling interface.
Constructs a CVXPY problem from the stored constraint matrices and solves it using the Clarabel backend via CVXPY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**solver_kwargs
|
Native solver options forwarded verbatim to |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
The optimal objective value. |
Source code in fomtools/canonicalizers/sdp.py
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 | |
update_bounds
¶
update_bounds(expression: LinearExpression, lb: float | ndarray, ub: float | ndarray) -> None
Update bounds for a variable by regenerating its constraint matrices.
Modifies the existing inequality constraint matrices for the given variable to reflect new lower and upper bounds. This is used during bound tightening procedures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
LinearExpression
|
The variable whose bounds are being updated. Must already be
registered via |
required |
lb
|
ndarray
|
New lower bounds. Must have length equal to |
required |
ub
|
ndarray
|
New upper bounds. Must have length equal to |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the expression is not found in the canonicalizer, or if the bounds do not have the expected length. |
NotImplementedError
|
If any new bound is infinite. |
Source code in fomtools/canonicalizers/sdp.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
range_to_indices
¶
range_to_indices(idx_ranges)
Convert a list of (start, end) range tuples to a set of indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx_ranges
|
list[tuple[int, int]]
|
List of (start, end) pairs defining half-open ranges. |
required |
Returns:
| Type | Description |
|---|---|
set[int]
|
The union of all indices in the specified ranges. |
Source code in fomtools/canonicalizers/sdp.py
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 | |
symmetrize
¶
symmetrize(mat)
Symmetrize a sparse matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
scipy.sparse matrix
|
The matrix to symmetrize. |
required |
Returns:
| Type | Description |
|---|---|
scipy.sparse matrix
|
The symmetric matrix (mat + mat.T) / 2. |
Source code in fomtools/canonicalizers/sdp.py
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 | |