TensorNetwork
TensorNetwork copied to clipboard
Add power to each backend and as a Tensor method in linalg
We should support the numpy function np.power.
Edit: it would also be good to support elementwise exponentiation of Tensor using the ** operator
@wkostuch how's this sound? I could help you through it if you want a good way to get started!
@alewis, this looks good, thanks! I'd love to have a go at it.
I'm excited to (hopefully) start contributing, and if something comes up I'll be sure to contact you.
Great! The first step would be to add the function to the abstract backend.
To do this, first fork TensorNetwork, track the google repo as a remote, and start a new branch for your modification (lemme know if you need help with that part).
Within this new branch, go to tensornetwork/backends/abstract_backend.py, where various "empty" backend functions are implemented. These implementations just raise NotImplementedError when called. So the first step would be to add an equivalent for power.
Next you check backend_tests.py, which contains a bunch of tests that make sure NotImplementedError is indeed called, and add your own for the relevant function. Make sure your tests work: cd tensornetwork, pytest ./backends/backend_tests.py.
That would be enough for your first PR! Commit, push, and navigate back to this repo, where there should be an option to merge your recent push.
So a pull request with just the "empty" function (and corresponding test) that raises an error and then go from there after that?
I wrote the code for that, but then when trying to run the tests found out that one of the dependencies doesn't play nice with Windows, so I'm in the midst of setting up a Linux environment to get around that. Once that's done I'll run the tests and keep on working. Thanks again for all the guidance, I really appreciate it!
Yes that's right, just the empty function at first. In general we try to keep pull requests to 200 lines or shorter, excluding test code, although sometimes this is not possible. That's because all the pull requests are to be peer reviewed, and it's hard for the reviewer to catch things when they are longer than this.
Regarding Windows, if you are using Windows 10 there is a so called "Windows Subsystem for Linux" that essentially allows you to run Ubuntu inside Windows as an app. I used to develop this way - it works pretty well and while some setup is required, it's a lot easier than setting up a partition and so on, especially on a laptop with a GPU. There's instructions to get it working here: https://docs.microsoft.com/en-us/windows/wsl/install-win10
Makes sense! I got WSL running, so the empty function and test are now waiting for a review.
The next step would be to add the same function, and test(s) of it, to the numpy backend, using the existing functions in numpy_backend.py and the test file as an example. This next needs to be repeated for TensorFlow, PyTorch, and eventually Symmetric, though Symmetric might require some specialized physics knowledge and perhaps would be best left for later.
Add the same empty function and tests as before or go ahead and put each backend's version of power in?
Yeah, so this time you'd want to actually add the function. I'd recommend you make each backend a separate PR.
Hello there @alewis! I would like to help with this, this is my first time contributing.
Alright, maybe you could do the Jax version?
@wkostuch
Sure thing! @alewis I'm sorry but this is the first time of me working on this project just to confirm I will work on the files in the Jax folder found inside the back end folder right?
TensorNetwork/tensornetwork/backends/jax
That's correct
Perfect, I'll get on it right away thank you! btw is there a place where we can communicate? Like matrix, slack, discord, or something? @mganahl @alewis
Thanks. I think github should be sufficient.
Perfect, I just want to confirm what I'm going to do, which is basically to implement the power function that wkostuch added to the abstract files, but implement them in the Jax files right? each file would be its own PR? @mganahl @alewis
that's right. There is only jax_backend.py that needs to be updated.
Perfect! Thanks so much for the help!
@mganahl @alewis I also need to update the jax_backend_test.py right?
EDIT: I am having some issues with the jax_backend_test.py file it keeps reporting for the missing jax module but I have already installed it with pip3 but the issue persist.
Hi there! I believe that the power function has been implemented, is there anywhere else where this function needs to be implemented? @mganahl @alewis
Hello @alewis @mganahl After viewing all files in the backend, I notice the power method is missing in both the Pytorch and Symmetric backends, should I implement them there as well?
Sure, give it a shot!
Hello @mganahl @alewis I was running pytest for pytorch_backend_test.py and I am receiving this error message at line 16, this is the output I get:
============================================================= test session starts ============================================================== platform darwin -- Python 3.8.5, pytest-6.1.2, py-1.9.0, pluggy-0.13.1 rootdir: /Users/nsl-glopez/Documents/GithubOpenSource/TensorNetwork collected 173 items
pytorch_backend_test.py Fatal Python error: Aborted
Current thread 0x000000010c1455c0 (most recent call first): File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/torch/functional.py", line 936 in tensordot File "/Users/nsl-glopez/Documents/GithubOpenSource/TensorNetwork/tensornetwork/backends/pytorch/pytorch_backend.py", line 46 in tensordot File "/Users/nsl-glopez/Documents/GithubOpenSource/TensorNetwork/tensornetwork/backends/pytorch/pytorch_backend_test.py", line 16 in test_tensordot File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/python.py", line 184 in pytest_pyfunc_call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 84 in
File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/python.py", line 1627 in runtest File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 163 in pytest_runtest_call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 84 in File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 256 in File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 310 in from_call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 255 in call_runtest_hook File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 216 in call_and_report File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 127 in runtestprotocol File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/runner.py", line 110 in pytest_runtest_protocol File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 84 in File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/main.py", line 338 in pytest_runtestloop File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 84 in File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/main.py", line 313 in _main File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/main.py", line 257 in wrap_session File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/main.py", line 306 in pytest_cmdline_main File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 84 in File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in call File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/config/init.py", line 164 in main File "/Users/nsl-glopez/miniconda3/lib/python3.8/site-packages/_pytest/config/init.py", line 187 in console_main File "/Users/nsl-glopez/miniconda3/bin/pytest", line 8 in [1] 9285 abort pytest pytorch_backend_test.py
Hard to say from this error message except that the call to torch.tensordot is for some reason failing. Did you change anything about either pytorch_backend.tensordot, the tensordot test, or the test file?
Hi there @alewis. The only changes I had made to the PyTorch backend was the power function and the test for it, I just reverted those changes, and the error persists, something else is the culprit since I also compared the master file from GitHub to my own from my branch and they are the same.
can you open a pull request with the changes? I'll can have look tommorw
Sure thing, thanks!
Nice one !