#66 [unitaryHACK] is_permutation #70
Conversation
Codecov Report
@@ Coverage Diff @@
## master #70 +/- ##
======================================
Coverage 98.7% 98.7%
======================================
Files 121 123 +2
Lines 2366 2399 +33
Branches 566 574 +8
======================================
+ Hits 2337 2370 +33
Misses 12 12
Partials 17 17
Continue to review full report at Codecov.
|
Will need to find a way to get this working on my local version,
|
I found some errors in my code and have corrected the one's I found. Also working on getting the test.py method to work locally so I can verify the tests do actually work. |
|
I was able to get the tests running locally in a debug mode with nose. Working on resolving the errors found by the automated checks. |
Unsure why it is failing on the automated 2nd check. Will find the cause soon.
I have seen some interpreters choke on different line return sequences so maybe this one does as well. Changing the line return syntax to match the other test cases.
|
@vanzilar I'd suggest changing the title to [unitaryHACK] (case-sensitive) so that the bot can detect this PR. :-) |
| if not is_square(mat): | ||
| return False | ||
|
|
||
| for i in mat: |
There was a problem hiding this comment.
I think this whole approach for checking whether something is a permutation matrix is overcomplicating the task at hand. I would do something like:
if all(sum(row) == 1 for row in mat):
return all(sum(col) == 1 for col in zip(*mat))
return False
There was a problem hiding this comment.
I agree after reviewing this in detail.
This syntax is great I think as it reduces 7 lines down to 3 and is entirely equivalent to the 7 lines in terms of output with no issues I can find. Plus it might work better when going through the style checkers as a added bonus. I am going to try it this way, recheck and then submit and then I think this is done.
I played around with more changes to this idea make it more concise or readable however each way I tried actually made it more complex with no readability nor computational benefit.
There was a problem hiding this comment.
Okay. Thanks for the heads up. Let me know when you've completed the feature.
Likewise. And hopefully some day even I'll be contributing to this project too. :-) |
and not duplicate function names so all tests are run
Every time is complies and passes tests on my local machine. Maybe the difference is in the spaces. Reformatted to a standard of 4 spaces for each level to see if that is the difference between my local tests and the remote tests.
This file appears needed and was missing. Was not required for local tests.
|
I have an update. The issue appears to be a difference between what is up in github and what is down on my local machine. I am going to change the title to [WIP]. |
|
@vanzilar I'm not sure how that's going to solve your problems, but you're welcome to do that in addition to fixing the issues. |
Ran local tests and confirmed the .is_permutation is needed in this case
Cool, let me know if you have something specific, and I'll try to provide guidance. |
|
Thanks all. I have learned quite a bit. I know what the code-cov plugin does now.... it is awesome the way to zeroes in to make sure you test every check at least once. I need to spend a drop more time now on seeing if I can understand the proposed change that was sent by using zip and * or perhaps to find a more concise way to check for permutation matrices, using functions I have not tried in the pymath package or elsewhere in toqito itself. Will send any questions up as soon as I have one. |
Cool, keep me posted! |
Change the 7 lines of code to 3.
|
OK all done from my side now. :) Ready for any comments or changes however..... Side note: From a personal standpoint, I am still thinking about a more concise way to do: However I have not found a better way with python or pymath syntax yet. I am open to better suggestions. My Computer Science friends often prefer this type of broken up form however so they can see the check on every element. There should be a simpler way to iterate with one interable through every element in a matrix in python and run a check on each. Wait a second... there is an easier way.... ok tested... one more commit coming in. |
Removed the 2 comments and the parenthesis as per pylint's preferences. all good.
|
OK now I am done. (There is always more to change) however. Let me explain my logic here. Based on the wikipedia def of a permutation matrix only 0s and 1s are allowed. To be explicit I put in an is_square even though it might be superfluous as all valid permutation matrices will be square given the other checks. I found just adding up rows and columns there are many matrices that can add up to 1 in every row and column and not consist of 0s and 1s, so I had to check each element to make sure it is in the set of 0,1., (see tests for a few examples) So I am going to leave my submission as is and ask for any more comments or requested changes and advice. |
| >>> is_permutation(A) | ||
| True | ||
|
|
||
| Alternatively, the following example matrix :math:`B` defined as |
There was a problem hiding this comment.
This sentence isn't complete, you don't mention whether or not the following matrix B is a permutation matrix or not.
|
Thanks @vanzilar. Added some comments. |
Changes the matrix notation from indicating index numbers to containing the actual element values as requested. Removed is_square check as requested. (If it is needed it can be restored later)
|
Running into a end-case issue. When I remove is_square check... and try to check the single value matrix [[1]] I am getting errors. For this trivial matrix should it be considered a permutation matrix of the identity variety or a non-permutation matrix? Unsure how to proceed or how it should be defined in this context. Here is the test that is failing def test_is_one_dimensional_permutation(): Or should it be true? |
also debating whether to add a 1-D permutation matrix check and if it is valid or not.
As mentioned in the previous comment, you don't need the |
Was causing compile error.
|
OK all done... let me know of the 2 remaining topics:
|
Removing is the best way to demonstrate why this additional code for checking each element is necessary, Without checking if each element is in the set, 0,1 the checks for various non-permutation matrices that mimic permutation matrices but are not permutation matrices per the wikipedia definition, will fail in the testing suite.
Added spaces Also modified import statement to match the new line of code in the init py file in the toqito directory
|
OK all the changes are in now. The build fails as designed. Next step is: Let me know which way is correct. |
Ah gotcha. No, I think you were correct and I mistakenly told you to remove the |
|
All in now. Let me know if this is good or if there are more changes to make. Thanks so much for all the checks. |
While reviewing the recommended fixes found this was spelled wrong
|
Cool, accepted. |
Description
Adds in the feature as requested. 😓 with not much time to go! 😭
Todos
Questions
Status
So excited. I was thinking I could get more in however still getting the handle of the whole quantum dev environment that has evolved over the years in concert with git.
Hoping I can contribute more here and there as time goes on, as I want to play with quantum theories and experiments to understand the universe a little better.
Hope you are getting many cool additions from many Unitary Hackers and Programmers!