OpenMined / openmined

OpenMined courses application
https://courses.openmined.org
Apache License 2.0
25 stars 16 forks source link

Errors in notebook Additive Secret Sharing #185

Closed nigoshh closed 3 years ago

nigoshh commented 3 years ago

Description

Running notebook Additive Secret Sharing.ipynb from course Foundations of Private Computation, Lesson 9, Concept 4, gives the following errors.

First error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-72e576e1fdc8> in <module>
      1 # Run this cell to import the quizzes
----> 2 from quiz import q0, q1, q2

~\courses\secure-mpc\quiz.py in <module>
    263 x = 4
    264 for i in range(20):
--> 265     a, b = secret_share(x)
    266     assert a >= -(2 ** (bits - 1)) and a < 2 ** (bits - 1)
    267     assert b >= -(2 ** (bits - 1)) and b < 2 ** (bits - 1)

~\courses\secure-mpc\quiz.py in secret_share(x)
    228 
    229 def secret_share(x: int) -> List[int]:
--> 230     share_1 = np.random.randint(0, 2 ** bits)
    231     share_2 = (x - share_1) % 2 ** bits
    232 

mtrand.pyx in numpy.random.mtrand.RandomState.randint()

_bounded_integers.pyx in numpy.random._bounded_integers._rand_int32()

ValueError: high is out of bounds for int32

Second error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-359523f627e4> in <module>
      1 import torch
      2 import syft as sy
----> 3 hook = sy.TorchHook(torch)

AttributeError: module 'syft' has no attribute 'TorchHook'

The first error can be fixed by changing this line

 230     share_1 = np.random.randint(0, 2 ** bits)

to

 230     share_1 = np.random.randint(0, 2 ** bits, dtype=np.int64)

I do not know how to solve the second error.

tcp commented 3 years ago

Thank you @nigoshh.

jmaunon commented 3 years ago

@nigoshh , the second error comes from PySyft version, if you want to run this example you need pysyft==0.2.9