added Z2 integer support#42
Conversation
d6b0a34 to
684f2df
Compare
|
Please provide a brief description of changes |
| # Draft version class | ||
|
|
||
|
|
||
| class Z2: |
There was a problem hiding this comment.
Please add docstrings and type annotations
There was a problem hiding this comment.
done!
|
|
||
| Examples | ||
| -------- | ||
| >>> a = Z2(1) |
There was a problem hiding this comment.
Please add imports from physika
There was a problem hiding this comment.
done!
|
|
||
| Returns | ||
| ------- | ||
| None |
There was a problem hiding this comment.
According to type annotations this returns "Z2", please fix
There was a problem hiding this comment.
done!
| """ | ||
| return bool(self.val) | ||
|
|
||
| def __int__(self) -> int: |
There was a problem hiding this comment.
I think there are two init methods.
There was a problem hiding this comment.
it is __int__ method, but now I have removed because we want both types to be Z2 only for doing operations.
| @@ -0,0 +1,121 @@ | |||
| from typing import Union | |||
There was a problem hiding this comment.
Please add unit ttests
There was a problem hiding this comment.
done!
rbharath
left a comment
There was a problem hiding this comment.
@a-b-h-a-y-s-h-i-n-d-e Make sure to add rst docs of the new features explaining and providing examples
174db47 to
3d66805
Compare
61bc381 to
5af89bc
Compare
| # ---------------- | ||
| # XOR operation | ||
| # ---------------- | ||
| xor_opposite = a + b |
There was a problem hiding this comment.
please add the types of these decl expressions: xor_opposite, xor_same, and_mixed, etc
There was a problem hiding this comment.
done!
| import torch.optim as optim | ||
|
|
||
| from physika.runtime import physika_print | ||
| from physika.z2 import Z2 |
There was a problem hiding this comment.
I'm not sure if we want physika.z2 as an import in runtime, instead as a physika type to perform modulo operations with.
There was a problem hiding this comment.
yes this make sense, should I create a new type for Z2 just like we are doing in utils/types.py
e.g:
# Ground scalar types
T_REAL = TScalar("ℝ")
T_NAT = TScalar("ℕ")
T_COMPLEX = TScalar("ℂ")
T_STRING = TScalar("string")and then handle explicitly in utils/type_checker_utils.py
There was a problem hiding this comment.
@JoseAntonioSiguenza can you check the last commit which I made, I have added Z2 as a standalone type, but since we have z2.py I have to add that in runtime, but in generated code it is not getting included now
There was a problem hiding this comment.
I think is better now Z2 as it type, please lets integrate this new type with exisiting ones and test it for type checker.
There was a problem hiding this comment.
Maybe a new PR for type system integration is better to keep this PR with less changes
There was a problem hiding this comment.
okay great
5af89bc to
24bdfd1
Compare
| return T_COMPLEX | ||
| if ts == "string": | ||
| return T_STRING | ||
| if ts in ("ℤ2", "Z2"): |
There was a problem hiding this comment.
Please include this at test_type_checker_utils.py
There was a problem hiding this comment.
done!
| T_NAT = TScalar("ℕ") | ||
| T_COMPLEX = TScalar("ℂ") | ||
| T_STRING = TScalar("string") | ||
| T_Z2 = TScalar("ℤ2") |
There was a problem hiding this comment.
Please add this new type to existing tests
There was a problem hiding this comment.
done!
|
@JoseAntonioSiguenza , I have also added Z2 in
|
84a0fa7 to
581104f
Compare
| import torch.optim as optim | ||
|
|
||
| from physika.utils.print_utils import _from_torch, _infer_type | ||
| from physika.z2 import Z2 # noqa |
There was a problem hiding this comment.
So, I think having just this is not adding much. Lets remove Z2 from runtime completly (we can call later if needed)
|
Great work!! This PR got pretty large, so lets split in 2 to facilitate final review:
|



This PR adds support for Z2 modulo 2 integer, along with support for XOR, AND operations and boolean flags
example code: