Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Subtraction operation of FV Scheme #3775

Merged
merged 4 commits into from
Jun 28, 2020

Conversation

rav1kantsingh
Copy link
Member

Description

closes #3702
Implemented Subtraction operation of the FV scheme.

Can Subtract two ciphertexts or a plaintext from a ciphertext.

Affected Dependencies

None

How has this been tested?

  • Added tests which check the subtracted values from the operation.

Checklist

@rav1kantsingh rav1kantsingh added Type: New Feature ➕ Introduction of a completely new addition to the codebase Crypto Team labels Jun 23, 2020
@rav1kantsingh rav1kantsingh added this to the BFV Tensor in Python milestone Jun 23, 2020
@rav1kantsingh rav1kantsingh requested review from youben11 and a team June 23, 2020 14:23
@rav1kantsingh rav1kantsingh changed the title Add Subtraction operation of FV Scheme Implemented Subtraction operation of FV Scheme Jun 23, 2020
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #3775 into master will decrease coverage by 0.07%.
The diff coverage is 93.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3775      +/-   ##
==========================================
- Coverage   94.76%   94.68%   -0.08%     
==========================================
  Files         186      186              
  Lines       18477    18571      +94     
==========================================
+ Hits        17509    17584      +75     
- Misses        968      987      +19     
Impacted Files Coverage Δ
syft/frameworks/torch/he/fv/util/operations.py 93.54% <90.32%> (-1.78%) ⬇️
syft/frameworks/torch/he/fv/evaluator.py 94.04% <92.00%> (-3.52%) ⬇️
test/torch/tensors/test_fv.py 100.00% <100.00%> (ø)
syft/workers/node_client.py 27.88% <0.00%> (-2.12%) ⬇️

return self._add_plain_cipher(op2, op1)
return self._sub_cipher_plain(op1, op2)

elif isinstance(op1, PlainText) and isinstance(op2, CipherText):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a method for the ifs? to check if both are ciphertexts, different or throw exception.
to reduce the duplicated code.

Comment on lines 13 to 34
class ParamTypes(Enum):
"""Enumeration for type checking of parameters.
"""

CTCT = 1
PTPT = 2
CTPT = 3
PTCT = 4


def _typecheck(op1, op2):
"""Check the type of parameters used and return correct enum type."""
if isinstance(op1, CipherText) and isinstance(op2, CipherText):
return ParamTypes.CTCT
elif isinstance(op1, PlainText) and isinstance(op2, PlainText):
return ParamTypes.PTPT
elif isinstance(op1, CipherText) and isinstance(op2, PlainText):
return ParamTypes.CTPT
elif isinstance(op1, PlainText) and isinstance(op2, CipherText):
return ParamTypes.PTCT
else:
return None
Copy link
Member Author

@rav1kantsingh rav1kantsingh Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcebere I have tried to update it as per your review, please check and suggest if anything better can be done 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe throw directly, instead of renurning None?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then I would have to remove the name of operation. Can you suggest another error message without operation name.

Copy link
Member

@bcebere bcebere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small comment, otherwise LGTM! Great work!

Comment on lines 13 to 34
class ParamTypes(Enum):
"""Enumeration for type checking of parameters.
"""

CTCT = 1
PTPT = 2
CTPT = 3
PTCT = 4


def _typecheck(op1, op2):
"""Check the type of parameters used and return correct enum type."""
if isinstance(op1, CipherText) and isinstance(op2, CipherText):
return ParamTypes.CTCT
elif isinstance(op1, PlainText) and isinstance(op2, PlainText):
return ParamTypes.PTPT
elif isinstance(op1, CipherText) and isinstance(op2, PlainText):
return ParamTypes.CTPT
elif isinstance(op1, PlainText) and isinstance(op2, CipherText):
return ParamTypes.PTCT
else:
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe throw directly, instead of renurning None?

Copy link
Member

@youben11 youben11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I just put some remarks about docs

Comment on lines 142 to 143
ct (Ciphertext): First argument.
pt (Plaintext): Second argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what the argument is for the operation here?

Comment on lines 169 to 170
ct (Ciphertext): First argument.
pt (Plaintext): Second argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what the argument is for the operation here?

Comment on lines 182 to 183
ct1 (Ciphertext): First argument.
ct2 (Ciphertext): Second argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what the argument is for the operation here?

Comment on lines 76 to 77
"""return subtraction of two polynomials with all coefficients of
polynomial %q(coefficient modulus)"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what the arguments are for the operation here?

@youben11 youben11 merged commit fe8311a into OpenMined:master Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature ➕ Introduction of a completely new addition to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Subtraction operation for FV HE Scheme
3 participants