-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
158 develop introductory jupyter notebook that shows pactis use cases (…
…#174) * minor * minor * rename * minor * rename * rename * hide edit button from webpage * Many edits * minor * minor * base64 * saving outputs * now saving ALL outputs * typo * header change * minor
- Loading branch information
Showing
13 changed files
with
3,571 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Examples | ||
|
||
|
||
### Composition | ||
|
||
|
||
Suppose we have the following system: | ||
|
||
<img src="source/_static/exports/circuit_series_composition_black.svg" width="350" alt="Buffers connected in series"> | ||
|
||
|
||
Components $M$ and $M'$ obey, respectively, contracts $C = (|i| \le 2, o \le i \le 2o + 2)$ and $C' = (-1 \le o \le 1/5, o' \le o)$. We can use Pacti to obtain the specification of the system by executing the command | ||
|
||
`pacti examples/example.json result.json` | ||
|
||
Pacti places the result of composition in the file result.json. The output is | ||
|
||
``` | ||
Composed contract: | ||
InVars: [<Var i>] | ||
OutVars:[<Var o_p>] | ||
A: 5*i <= 1, -1/2*i <= 0 | ||
G: -1*i + 1*o_p <= 0 | ||
``` | ||
|
||
### Quotient | ||
|
||
|
||
Now we consider an example of quotient. Consider the following circuits: | ||
|
||
<img src="source/_static/exports/circuit_series_quotient_black.svg" width="350" alt="Buffers connected in series"> | ||
|
||
We wish to implement a system $M$ with specification $C = (|i| \le 1, o' = 2i + 1)$, and to do this we have available a component $M'$ with specification $C' = (|i| \le 2, o = 2i)$. We use the quotient operation in Pacti to obtain the specification of the component that we are missing so that the resulting object meets the specification $C$. We run the command | ||
|
||
`pacti examples/example_quotient.json result.json` | ||
|
||
And Pacti outputs | ||
|
||
``` | ||
Contract quotient: | ||
InVars: [<Var o>] | ||
OutVars:[<Var o_p>] | ||
A: 1*o <= 2, -1*o <= 2 | ||
G: -1*o + 1*o_p <= 1, 1*o + -1*o_p <= -1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ | |
.md-main__inner { | ||
margin-bottom: 1.5rem; | ||
} | ||
|
||
|
||
.md-content__button { | ||
display: none; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1,586 changes: 1,586 additions & 0 deletions
1,586
docs/source/_static/circuit_series_composition_background.ai
Large diffs are not rendered by default.
Oops, something went wrong.
1,649 changes: 1,649 additions & 0 deletions
1,649
docs/source/_static/circuit_series_quotient_background.ai
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+9.02 KB
docs/source/_static/exports/circuit_series_composition_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
docs/source/_static/exports/circuit_series_composition_background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
docs/source/_static/exports/circuit_series_quotient_background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
from pacti.terms.polyhedra import PolyhedralContract, PolyhedralTermList, PolyhedralTerm | ||
from pacti.iocontract import Var | ||
|
||
|
||
contract = PolyhedralContract.from_string( | ||
InputVars=["x"], | ||
OutputVars=["y"], | ||
assumptions=["x <= 2"], | ||
guarantees=["2x + 3y <= 7", "2y - 3x <= 8"]) | ||
print(contract) | ||
|
||
x = Var("x") | ||
y = Var("y") | ||
print(contract.a.contains_behavior({x:5})) | ||
print(contract.a.contains_behavior({x:0})) | ||
print(contract.g.contains_behavior({x:0, y:2})) | ||
print(contract.g.contains_behavior({x:0, y:5})) | ||
|
||
|
||
# now verify component | ||
t1 = PolyhedralTerm(variables={x:1},constant=3) | ||
t2 = PolyhedralTerm(variables={x:-1},constant=-3) | ||
t3 = PolyhedralTerm(variables={y:1},constant=2) | ||
t4 = PolyhedralTerm(variables={y:-1},constant=-2) | ||
component = PolyhedralTermList([t1,t2,t3,t4]) | ||
|
||
print(contract.contains_environment(component)) | ||
print(contract.contains_implementation(component)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters