SyMPC icon indicating copy to clipboard operation
SyMPC copied to clipboard

Type annotations for Approximations

Open kamathhrishi opened this issue 3 years ago • 4 comments

Where?

Currently, the approximations module of SyMPC does not have type annotations. The following are the files with missing type annotations:

  • [ ] exponential.py
  • [ ] log.py
  • [ ] reciprocal.py
  • [ ] sigmoid.py
  • [ ] softmax.py
  • [ ] tanh.py
  • [ ] utils.py

kamathhrishi avatar Jun 27 '21 03:06 kamathhrishi

Hi I would like to contribute to this. Note that this is my first time contributing to a open source project.

rhit-namburs avatar Jun 27 '21 05:06 rhit-namburs

Sure @rhit-namburs , go for it :+1:

rasswanth-s avatar Jun 27 '21 07:06 rasswanth-s

@rhit-namburs are you still working on it?

rasswanth-s avatar Jul 26 '21 02:07 rasswanth-s

Hi! I am not sure if @rhit-namburs is still working on this issue so I decided to take a look.

I noticed that softmax.py and tanh.py are already annotated, so I decided to follow their approach. However, this leads to a circular import issue:

  1. sympc.tensor.mpc_tensor.py imports APPROXIMATIONS from sympc.approximations, which includes func = (sigmoid.py, log.py, exponential.py, reciprocal.py, utils.py).
  2. softmax.py and tanh.py import MPCTensor from sympc.tensor to be used for the type annotations. If we do the same for func we go into a loop of imports.

Without restructuring both sympc.approximations folder and MPCTensor class, I think the easiest way to go around this issue is to use TypeVar from typing to define an MPCTensor annotation. I tested and this solution passes the pre-commit tests.

Another possible solution could be to include the approximation functions defined in sympc.approximations folder inside MPCTensor class.

manel1874 avatar Feb 02 '22 11:02 manel1874