IoContract
IoContracts definitions.
IoContracts contains Pacti's basic definitions: Var, Term, TemList, and IoContract. Var creates variables; Term is an abstract class representing constraints; a TermList (also an abstract class) is a collection of terms semantically equivalent to the term which is the conjunction of all terms contained in the TermList; IoContract is an assume-guarantee specification consisting of assumptions, guarantees, and input and output variables. The assumptions and guarantees are given by TermLists. Assumptions make predicates only on inputs, and guarantees on both input and outputs (and no other variable).
This module implements all supported contract operations and relations. In order to instantiate contracts and perform this operations, it is necessary to extend Term and TermList with specific constraint formalisms.
IoContract
¶
Bases: Generic[TermList_t]
Basic type for an IO contract.
Attributes:
Name | Type | Description |
---|---|---|
inputvars |
Variables which are inputs of the implementations of the contract. |
|
outputvars |
Variables which are outputs of the implementations of the contract. |
|
a(TermList) |
Contract assumptions. |
|
g(TermList) |
Contract guarantees. |
Source code in pacti\src\pacti\iocontract\iocontract.py
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 |
|
vars: List[Var]
property
¶
The list of variables in the interface of the contract.
Returns:
Type | Description |
---|---|
List[Var]
|
Input and output variables of the contract. |
__init__(assumptions, guarantees, input_vars, output_vars, simplify=True)
¶
Class constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assumptions |
TermList_t
|
The assumptions of the contract. |
required |
guarantees |
TermList_t
|
The guarantees of the contract. |
required |
input_vars |
List[Var]
|
The input variables of the contract. |
required |
output_vars |
List[Var]
|
The output variables of the contract. |
required |
simplify |
bool
|
Whether to simplify the guarantees with respect to the assumptions. |
True
|
Raises:
Type | Description |
---|---|
IncompatibleArgsError
|
Arguments provided does not produce a valid IO contract. |
Source code in pacti\src\pacti\iocontract\iocontract.py
can_compose_with(other)
¶
Tell whether the contract can be composed with another contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
Contract whose possibility to compose with self we are verifying. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the contracts can be composed. False otherwise. |
Source code in pacti\src\pacti\iocontract\iocontract.py
can_quotient_by(other)
¶
Tell whether the contract can quotiented by another contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
potential quotient by which self would be quotiented. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the IO profiles of the contracts allow the quotient to exist. False otherwise. |
Source code in pacti\src\pacti\iocontract\iocontract.py
compose(other, vars_to_keep=None, simplify=True)
¶
Compose IO contracts.
Compute the composition of the two given contracts and abstract the result in such a way that the result is a well-defined IO contract, i.e., that assumptions refer only to inputs, and guarantees to both inputs and outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
The second contract being composed. |
required |
vars_to_keep |
Any
|
A list of variables that should be kept as top-level outputs. |
None
|
simplify |
bool
|
Whether to simplify the result of variable elimination by refining or relaxing. |
True
|
Returns:
Type | Description |
---|---|
IoContract_t
|
The abstracted composition of the two contracts. |
Source code in pacti\src\pacti\iocontract\iocontract.py
compose_tactics(other, vars_to_keep=None, simplify=True, tactics_order=None)
¶
Compose IO contracts with support for specifying the order of tactics and measuring their use.
Compute the composition of the two given contracts and abstract the result in such a way that the result is a well-defined IO contract, i.e., that assumptions refer only to inputs, and guarantees to both inputs and outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
The second contract being composed. |
required |
vars_to_keep |
Any
|
A list of variables that should be kept as top-level outputs. |
None
|
simplify |
bool
|
Whether to simplify the result of variable elimination by refining or relaxing. |
True
|
tactics_order |
Optional[List[int]]
|
The order of tactics to try for variable term elimination. |
None
|
Returns:
Type | Description |
---|---|
Tuple[IoContract_t, List[TacticStatistics]]
|
A tuple of the abstracted composition of the two contracts and of the list of tactics used. |
Raises:
Type | Description |
---|---|
IncompatibleArgsError
|
An error occurred during composition. |
Source code in pacti\src\pacti\iocontract\iocontract.py
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 |
|
contains_environment(component)
¶
Tell whether a component is a valid environment for the contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component |
TermList
|
The component in question. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the component is a valid environment; false otherwise. |
Source code in pacti\src\pacti\iocontract\iocontract.py
contains_implementation(component)
¶
Tell whether a component is a valid implementation for the contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component |
TermList
|
The component in question. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the component is a valid implementation; false otherwise. |
Source code in pacti\src\pacti\iocontract\iocontract.py
copy()
¶
Makes copy of contract.
Returns:
Type | Description |
---|---|
IoContract_t
|
Copy of contract. |
Source code in pacti\src\pacti\iocontract\iocontract.py
merge(other)
¶
Compute the merging operation for two contracts.
Compute the merging operation of the two given contracts. No abstraction/refinement is applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
The contract with which we are merging self. |
required |
Returns:
Type | Description |
---|---|
IoContract_t
|
The result of merging. |
Raises:
Type | Description |
---|---|
IncompatibleArgsError
|
trying to merge different contract types. |
Source code in pacti\src\pacti\iocontract\iocontract.py
quotient(other, additional_inputs=None, simplify=True)
¶
Compute the contract quotient.
Compute the quotient self/other of the two given contracts and refine the result in such a way that the result is a well-defined IO contract, i.e., that assumptions refer only to inputs, and guarantees to both inputs and outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
The contract by which we take the quotient. |
required |
additional_inputs |
Optional[List[Var]]
|
Additional variables that the quotient is allowed to consider as inputs. These variables can be either top level-inputs or outputs of the other argument. |
None
|
simplify |
bool
|
Whether to simplify the result of variable elimination by refining or relaxing. |
True
|
Returns:
Type | Description |
---|---|
IoContract_t
|
The refined quotient self/other. |
Source code in pacti\src\pacti\iocontract\iocontract.py
quotient_tactics(other, additional_inputs=None, simplify=True, tactics_order=None)
¶
Compute the contract quotient with support for specifying the order of tactics and measuring their use.
Compute the quotient self/other of the two given contracts and refine the result in such a way that the result is a well-defined IO contract, i.e., that assumptions refer only to inputs, and guarantees to both inputs and outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
The contract by which we take the quotient. |
required |
additional_inputs |
Optional[List[Var]]
|
Additional variables that the quotient is allowed to consider as inputs. These variables can be either top level-inputs or outputs of the other argument. |
None
|
simplify |
bool
|
Whether to simplify the result of variable elimination by refining or relaxing. |
True
|
tactics_order |
Optional[List[int]]
|
The order of tactics to try for variable term elimination. |
None
|
Returns:
Type | Description |
---|---|
Tuple[IoContract_t, List[TacticStatistics]]
|
A tuple of the refined quotient self/other and the list of tactics used. |
Raises:
Type | Description |
---|---|
IncompatibleArgsError
|
Arguments provided are incompatible with computation of the quotient. |
Source code in pacti\src\pacti\iocontract\iocontract.py
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 |
|
refines(other)
¶
Tell whether the given contract is a refinement of another.
Return self <= other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
contract being compared with self. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the calling contract refines the argument. |
Raises:
Type | Description |
---|---|
IncompatibleArgsError
|
Refinement cannot be computed. |
Source code in pacti\src\pacti\iocontract\iocontract.py
rename_variable(source_var, target_var)
¶
Rename a variable in a contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_var |
Var
|
The variable to be replaced. |
required |
target_var |
Var
|
The new variable. |
required |
Returns:
Type | Description |
---|---|
IoContract_t
|
A contract with |
Raises:
Type | Description |
---|---|
IncompatibleArgsError
|
The new variable is both an input and output of the resulting contract. |
Source code in pacti\src\pacti\iocontract\iocontract.py
shares_io_with(other)
¶
Tell whether two contracts have the same IO signature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IoContract_t
|
contract whose IO signature is compared with self. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the contracts have the same IO profile. |
Source code in pacti\src\pacti\iocontract\iocontract.py
Term
¶
Bases: ABC
Terms, or constraints, to be imposed on the system or components.
Term is an abstract class that must be extended in order to support specific constraint languages.
Source code in pacti\src\pacti\iocontract\iocontract.py
vars: List[Var]
abstractmethod
property
¶
Variables contained in the syntax of the term.
__eq__(other)
abstractmethod
¶
Equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
the object against which we are comparing self. |
required |
__hash__()
abstractmethod
¶
__repr__()
abstractmethod
¶
__str__()
abstractmethod
¶
contains_var(var_to_seek)
abstractmethod
¶
Tell whether term contains a given variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_to_seek |
Var
|
The variable that we are seeking in the current term. |
required |
copy()
abstractmethod
¶
rename_variable(source_var, target_var)
abstractmethod
¶
Rename a variable in a term.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_var |
Var
|
The variable to be replaced. |
required |
target_var |
Var
|
The new variable. |
required |
Returns:
Type | Description |
---|---|
Term_t
|
A term with |
Source code in pacti\src\pacti\iocontract\iocontract.py
TermList
¶
Bases: ABC
A collection of terms, or constraints.
A TermList is semantically equivalent to a single term which is the conjunction of all terms contained in the TermList. TermList is an abstract class that must be extended to support a specific constraint formalism.
Source code in pacti\src\pacti\iocontract\iocontract.py
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 |
|
vars: List[Var]
property
¶
The list of variables contained in this list of terms.
Returns:
Type | Description |
---|---|
List[Var]
|
List of variables referenced in the term. |
__init__(term_list=None)
¶
Class constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
term_list |
Optional[List]
|
A list of terms contained by TermList. |
None
|
Source code in pacti\src\pacti\iocontract\iocontract.py
contains_behavior(behavior)
abstractmethod
¶
Tell whether TermList contains the given behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
behavior |
Any
|
The behavior in question. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the behavior satisfies the constraints; false otherwise. |
Raises:
Type | Description |
---|---|
ValueError
|
Not all variables in the constraints were assigned values. |
Source code in pacti\src\pacti\iocontract\iocontract.py
copy()
¶
Makes copy of termlist.
Returns:
Type | Description |
---|---|
TermList_t
|
Copy of termlist. |
elim_vars_by_refining(context, vars_to_elim, simplify, tactics_order)
abstractmethod
¶
Eliminate variables from termlist by refining it in a context.
Given a context \(\Gamma\), and the list of terms contained in self, \(s\), this routine identifies a TermList \(x\) lacking variables vars_to_elim such that \(\frac{\Gamma\colon \; x}{\Gamma: \; s}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
TermList_t
|
List of context terms that will be used to refine the TermList. |
required |
vars_to_elim |
List[Var]
|
Variables to be eliminated. |
required |
simplify |
bool
|
Whether to simplify self in the given context before variable elimination |
required |
tactics_order |
List[int]
|
The order of the tactics to use when transforming each term in the list. |
required |
Returns:
Type | Description |
---|---|
Tuple[TermList_t, TacticStatistics]
|
A tuple consisting of (a) a list of terms not containing any variables in |
Source code in pacti\src\pacti\iocontract\iocontract.py
elim_vars_by_relaxing(context, vars_to_elim, simplify, tactics_order)
abstractmethod
¶
Eliminate variables from termlist by relaxing it in a context
Given a context \(\Gamma\), and the list of terms contained in self, \(s\), this routine identifies a formula \(x\) lacking variables vars_to_elim such that \(\frac{\Gamma\colon \; s}{\Gamma: \; x}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
TermList_t
|
List of context terms that will be used to abstract the TermList. |
required |
vars_to_elim |
List[Var]
|
Variables that cannot be present in TermList after relaxation. |
required |
simplify |
bool
|
Whether to simplify self in the given context before variable elimination |
required |
tactics_order |
List[int]
|
The order of the tactics to use when transforming each term in the list. |
required |
Returns:
Type | Description |
---|---|
Tuple[TermList_t, TacticStatistics]
|
A tuple consisting of (a) a list of terms not containing any variables in |
Source code in pacti\src\pacti\iocontract\iocontract.py
get_terms_with_vars(variable_list)
¶
Returns the list of terms which contain any of the variables indicated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_list |
List[Var]
|
a list of variables being sought in current TermList. |
required |
Returns:
Type | Description |
---|---|
TermList_t
|
The list of terms which contain any of the variables indicated. |
Source code in pacti\src\pacti\iocontract\iocontract.py
is_empty()
abstractmethod
¶
Tell whether the termlist has no satisfying assignments.
Returns:
Type | Description |
---|---|
bool
|
True if termlist constraints cannot be satisfied. |
refines(other)
abstractmethod
¶
Tell whether the argument is a larger specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
TermList_t
|
TermList against which we are comparing self. |
required |
Returns:
Type | Description |
---|---|
bool
|
self <= other. |
Source code in pacti\src\pacti\iocontract\iocontract.py
rename_variable(source_var, target_var)
¶
Rename a variable in a termlist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_var |
Var
|
The variable to be replaced. |
required |
target_var |
Var
|
The new variable. |
required |
Returns:
Type | Description |
---|---|
TermList_t
|
A termlist with |
Source code in pacti\src\pacti\iocontract\iocontract.py
simplify(context=None)
abstractmethod
¶
Remove redundant terms in TermList.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
Optional[TermList_t]
|
List of context terms that will be used to remove redundancies in the TermList. |
None
|
Returns:
Type | Description |
---|---|
TermList_t
|
Let \(S\) be this TermList. Simplify will return \(S_T = S \setminus T\), where \(T \subseteq S\) is a maximal subset such that \(\frac{\Gamma, S_T\colon \; \top}{\Gamma, S_T\colon \; \wedge_{t \in T} t}\). |
Source code in pacti\src\pacti\iocontract\iocontract.py
Var
¶
Variables used in system modeling.
Variables allow us to name an entity for which we want to write constraints.