# use pip (or, conda) to make sure numpy is installed:
!pip -q install numpy
from mpyc.runtime import mpc
import secretsanta, id3gini, lpsolver, np_cnnmnist
mpc.run(secretsanta.main())
Setting input to default = 8 2022-09-17 10:37:18,694 Start MPyC runtime v0.8.8 Using secure integers: SecInt32 2 [1, 0] 3 [2, 0, 1] 4 [3, 2, 1, 0] 5 [1, 4, 0, 2, 3] 6 [3, 4, 5, 0, 2, 1] 7 [2, 3, 6, 0, 5, 1, 4] 8 [2, 0, 6, 5, 7, 4, 1, 3] Using secure fixed-point numbers: SecFxp32:16 2 [1.0, 0.0] 3 [2.0, 0.0, 1.0] 4 [3.0, 2.0, 0.0, 1.0] 5 [3.0, 4.0, 1.0, 2.0, 0.0] 6 [5.0, 0.0, 4.0, 1.0, 2.0, 3.0] 7 [6.0, 4.0, 1.0, 2.0, 3.0, 0.0, 5.0] 8 [7.0, 0.0, 4.0, 1.0, 6.0, 3.0, 2.0, 5.0] Using secure prime fields: SecFld4(GF(11)) 2 [1, 0] 3 [1, 2, 0] 4 [2, 3, 1, 0] 5 [1, 3, 4, 0, 2] 6 [4, 2, 5, 0, 3, 1] 7 [4, 5, 1, 0, 6, 2, 3] 8 [5, 4, 3, 1, 2, 0, 7, 6] Using secure binary fields: SecFld3(GF(2^3)) 2 [1, 0] 3 [x, 0, 1] 4 [x, 0, x+1, 1] 5 [x^2, 0, 1, x, x+1] 6 [x^2, x, 1, x^2+1, x+1, 0] 7 [x^2+1, 0, x+1, x^2+x, 1, x^2, x] 8 [x^2+x+1, x^2+1, 1, x^2+x, x, 0, x+1, x^2] Using secure quinary fields: SecFld5(GF(5^2)) 2 [1, 0] 3 [2, 0, 1] 4 [3, 2, 1, 0] 5 [2, 4, 0, 1, 3] 6 [1, 4, 0, 2, x, 3] 7 [x, 4, x+1, 2, 0, 1, 3] 8 [x, 0, x+2, 4, 3, 2, 1, x+1] Using secure extension fields (medium prime): SecFld25(GF(11^7)) 2 [1, 0] 3 [1, 2, 0] 4 [3, 2, 1, 0] 5 [3, 4, 1, 2, 0] 6 [3, 0, 1, 5, 2, 4] 7 [2, 5, 0, 4, 3, 6, 1] 8 [4, 6, 1, 5, 0, 3, 7, 2] Using secure extension fields (larger prime): SecFld31(GF(1031^3)) 2 [1, 0] 3 [2, 0, 1] 4 [3, 2, 1, 0] 5 [2, 3, 4, 0, 1] 6 [3, 5, 0, 2, 1, 4] 7 [1, 3, 6, 0, 5, 2, 4] 8 [5, 7, 0, 4, 6, 1, 3, 2] 2022-09-17 10:37:19,273 Stop MPyC runtime -- elapsed time: 0:00:00.575169
mpc.run(id3gini.main())
Using secure integers: SecInt32 dataset: tennis with 14 samples and 4 attributes 2022-09-17 10:37:19,293 Start MPyC runtime v0.8.8 2022-09-17 10:37:19,300 Attribute node 0 2022-09-17 10:37:19,303 Leaf node label 1 2022-09-17 10:37:19,309 Attribute node 3 2022-09-17 10:37:19,312 Leaf node label 0 2022-09-17 10:37:19,315 Leaf node label 1 2022-09-17 10:37:19,320 Attribute node 2 2022-09-17 10:37:19,323 Leaf node label 0 2022-09-17 10:37:19,325 Leaf node label 1 2022-09-17 10:37:19,326 Stop MPyC runtime -- elapsed time: 0:00:00.032990 Decision tree of depth 2 and size 8: if Outlook == Overcast: Yes if Outlook == Rain: | if Wind == Strong: No | if Wind == Weak: Yes if Outlook == Sunny: | if Humidity == High: No | if Humidity == Normal: Yes
mpc.run(lpsolver.main())
Using secure 8-bit integers: SecInt8 dataset: uvlp with 2 constraints and 3 variables (scale factor 1) 2022-09-17 10:37:19,340 Start MPyC runtime v0.8.8 2022-09-17 10:37:19,344 Iteration 1/2: 0.0 pivot=1.0 2022-09-17 10:37:19,349 Iteration 2/2: 10.0 pivot=3.0 max = 37 / 3 / 1 = 12.333333333333334 in 2 iterations 2022-09-17 10:37:19,352 Solution x 2022-09-17 10:37:19,355 Dual solution y verification c.x == y.b, A.x <= b, x >= 0, y.A >= c, y >= 0: True solution = [1.3333333333333333, 0.3333333333333333, 0.0] 2022-09-17 10:37:19,360 Stop MPyC runtime -- elapsed time: 0:00:00.019084
mpc.run(np_cnnmnist.main())
2022-09-17 10:37:19,370 Start MPyC runtime v0.8.8 2022-09-17 10:37:19,371 --------------- INPUT ------------- Type = SecInt37, range = (1488, 1489) Labels: [4] [[0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000110000000000000111000] [0000001111000000000011111000] [0000011111000000000111111000] [0000011111000000000111111000] [0000011111000000000111110000] [0000011110000000001111100000] [0000011110000000001111100000] [0000011110000000011111000000] [0000011110000000111111000000] [0000011110000001111110000000] [0000011111000111111110000000] [0000011111111111111100000000] [0000001111111111111100000000] [0000000111111100111110000000] [0000000000000000011110000000] [0000000000000000011111000000] [0000000000000000011110000000] [0000000000000000001110000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000]] 2022-09-17 10:37:19,414 --------------- LAYER 1 ------------- 2022-09-17 10:37:19,414 - - - - - - - - conv2d - - - - - - - 2022-09-17 10:37:19,461 - - - - - - - - maxpool - - - - - - - 2022-09-17 10:37:20,767 - - - - - - - - ReLU - - - - - - - 2022-09-17 10:37:21,197 Barrier-after-layer-1 0 0 2022-09-17 10:37:21,197 --------------- LAYER 2 ------------- 2022-09-17 10:37:21,223 - - - - - - - - conv2d - - - - - - - 2022-09-17 10:37:22,222 - - - - - - - - maxpool - - - - - - - 2022-09-17 10:37:23,136 - - - - - - - - ReLU - - - - - - - 2022-09-17 10:37:23,429 Barrier-after-layer-2 0 0 2022-09-17 10:37:23,429 --------------- LAYER 3 ------------- 2022-09-17 10:37:24,266 - - - - - - - - fc 3136 x 1024 - - - 2022-09-17 10:37:24,422 - - - - - - - - ReLU - - - - - - - 2022-09-17 10:37:24,562 Barrier-after-layer-3 0 0 2022-09-17 10:37:24,562 --------------- LAYER 4 ------------- 2022-09-17 10:37:24,607 - - - - - - - - fc 1024 x 10 - - - - 2022-09-17 10:37:24,608 --------------- OUTPUT ------------- Image #1488 with label 4: 4 predicted. [-3754640229 -3026277190 -6936057232 -10456779375 20035698270 -8239621192 -3735898106 -6070673158 -6724021956 -370619516] 2022-09-17 10:37:24,616 Stop MPyC runtime -- elapsed time: 0:00:05.244793
import sys
mpc.logging(False)
sys.argv[1:] = ['6']
mpc.run(secretsanta.main())
print()
sys.argv[1:] = ['-i', '2']
mpc.run(id3gini.main())
print()
sys.argv[1:] = ['-i', '1']
mpc.run(lpsolver.main())
print()
sys.argv[1:] = ['1.5'] # forces use of secure fixed-point arithmetic
mpc.run(np_cnnmnist.main()) # faster than secure integers
sys.argv[1:] = []
Using secure integers: SecInt32 2 [1, 0] 3 [1, 2, 0] 4 [1, 3, 0, 2] 5 [1, 2, 3, 4, 0] 6 [2, 0, 4, 5, 1, 3] Using secure fixed-point numbers: SecFxp32:16 2 [1.0, 0.0] 3 [2.0, 0.0, 1.0] 4 [2.0, 0.0, 3.0, 1.0] 5 [1.0, 4.0, 3.0, 2.0, 0.0] 6 [3.0, 4.0, 0.0, 5.0, 2.0, 1.0] Using secure prime fields: SecFld3(GF(7)) 2 [1, 0] 3 [2, 0, 1] 4 [1, 0, 3, 2] 5 [1, 0, 3, 4, 2] 6 [1, 2, 5, 0, 3, 4] Using secure binary fields: SecFld3(GF(2^3)) 2 [1, 0] 3 [x, 0, 1] 4 [x, x+1, 1, 0] 5 [1, x^2, 0, x, x+1] 6 [x+1, x^2, x^2+1, 1, x, 0] Using secure quinary fields: SecFld5(GF(5^2)) 2 [1, 0] 3 [1, 2, 0] 4 [3, 2, 0, 1] 5 [2, 4, 0, 1, 3] 6 [2, 4, 3, x, 0, 1] Using secure extension fields (medium prime): SecFld25(GF(11^7)) 2 [1, 0] 3 [2, 0, 1] 4 [1, 0, 3, 2] 5 [4, 2, 3, 0, 1] 6 [1, 2, 3, 0, 5, 4] Using secure extension fields (larger prime): SecFld31(GF(1031^3)) 2 [1, 0] 3 [1, 2, 0] 4 [1, 0, 3, 2] 5 [2, 0, 3, 4, 1] 6 [4, 5, 3, 2, 0, 1] Using secure integers: SecInt95 dataset: car with 1728 samples and 6 attributes Decision tree of depth 3 and size 25: if safety == high: | if persons == 2: unacc | if persons == 4: | | if buying == high: acc | | if buying == low: acc | | if buying == med: acc | | if buying == vhigh: acc | if persons == more: | | if buying == high: acc | | if buying == low: vgood | | if buying == med: acc | | if buying == vhigh: unacc if safety == low: unacc if safety == med: | if persons == 2: unacc | if persons == 4: | | if buying == high: unacc | | if buying == low: acc | | if buying == med: acc | | if buying == vhigh: unacc | if persons == more: | | if lug_boot == big: acc | | if lug_boot == med: acc | | if lug_boot == small: unacc Using secure 6-bit integers: SecInt6 dataset: wiki with 2 constraints and 3 variables (scale factor 1) max = 60 / 3 / 1 = 20.0 in 1 iterations verification c.x == y.b, A.x <= b, x >= 0, y.A >= c, y >= 0: True solution = [0.0, 0.0, 5.0] Type = SecFxp10:4, range = (4269, 4270) Labels: [4] [[0000000000000000000000000000] [0000000000000000000000000000] [0000001110000000000000000000] [0000001100000000000000000000] [0000001100000000000000000000] [0000001110000000000000000000] [0000001110000000000000000000] [0000001110000000000110000000] [0000001110000000000110000000] [0000001110000000000110000000] [0000001110000000000110000000] [0000001110000000000110000000] [0000001111000000000111000000] [0000001111000000000111000000] [0000000111000000000111000000] [0000000111000000011111000000] [0000000111101111111111100000] [0000000111111111111111100000] [0000000011111111111111100000] [0000000001111111000011110000] [0000000000000000000011110000] [0000000000000000000001110000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000] [0000000000000000000000000000]] Image #4269 with label 4: 4 predicted. [-5.25 -4.8125 -3.6875 -9.0625 17.375 -5.6875 0. -5.5 -8. -1.3125]