-
Notifications
You must be signed in to change notification settings - Fork 62
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
Refactor: Partial trace and partial transpose #145
Comments
Hi there! I am interested in this issue, it would be great if you can assign this issue to me!😄 |
Thank you for your interest @ErikQQY ! You have been assigned! |
@vprusso I just refactored |
For example: toqito/toqito/state_opt/optimal_clone.py Line 176 in 835fcd3
|
Hi @ErikQQY . Thanks for the work thus far and for the question. Two options come to mind:
# If the input matrix is a CVX variable for an SDP, we convert it to a numpy array,
# perform the partial trace, and convert it back to a CVX variable.
if isinstance(input_mat, Variable):
rho_np = expr_as_np_array(input_mat)
traced_rho = partial_trace(rho_np, sys, dim)
traced_rho = np_array_as_expr(traced_rho)
return traced_rho Note that the above snippet of code is used in both the I believe the same general approach could also be applied to the portions of the code that you pointed to. Does that make sense? |
Yeah, I think the prudent approach is appliable in this case, I think we have two choices:
def partial_trace(mat, sys, dim):
if isinstance(input_mat, Variable):
rho_np = expr_as_np_array(input_mat)
traced_rho = partial_trace(rho_np, sys, dim)
traced_rho = np_array_as_expr(traced_rho)
return traced_rho
picos.partial_trace(mat, sys, dim) |
Yep, I think the approach you outlined in (2) sounds like the way to go! |
@vprusso I complete the rho = np.kron(np.eye(2, 3), np.ones((2, 3)))
rho = np.kron(rho, np.eye(2, 3))
dim = np.array([[2, 2, 2], [3, 3, 3]])
res = partial_transpose(rho, sys=2, dim=dim) It confuses me a lot🤔 |
Hmm, you know, I'm trying to imagine a scenario for when the partial transpose function would ever need to be applied to a non-square matrix. My initial thought is to make the assumption that the input matrix must be square. As a question, modulo the |
Yeah, I think the partial_transpose should be applied to a square matrix, but as a matter of fact, there is indeed a test for non-square matrices in toqito: toqito/tests/test_channels/test_partial_transpose.py Lines 711 to 722 in 1da8ad2
|
Yes, I did indeed see the test for the non-square matrices, however, assuming that the partial transpose is only applicable to square matrices (modulo these tests) I think we can remove these test cases. I did not happen to see any other places where applying a partial transpose to a non-square matrix is needed so I think we can:
The above is probably not an exhaustive list, but I think it covers the bulk of it. Does that make sense? |
Yeah, this make sense to me! I got another question here: toqito/toqito/channels/realignment.py Lines 80 to 84 in 150aa3a
An MWE can be reproduce using: a=np.arange(1, 17).reshape(4,4)
partial_transpose(a, 1, [[2, 2], [2, 2]]) As far as I know, picos doesn't have this feature(passing dim as |
Hmm. That is a bit of a hurdle. Okay, reassess. What if we kept the There may indeed be some extra functionality here in this that actually makes sense to keep, and the ability to perform this operation on non-square matrices might be useful. Thoughts? |
I think that would be the right choice! PR updated! |
The problem:
The present implementation of
partial_trace
andpartial_transpose
is not particularly favorable for a few different reasons:Counterintuitively, the first index is "1" and opposed to "0". The violates the conventions used elsewhere and is a result of these functions originally being converted over from MATLAB
The functions themselves are quite convoluted, and hence, more likely to induce error. While the test suite for these functions is fairly thorough, it is still not ideal.
The solution:
The solution is fairly straightforward:
Replace the
partial_transpose
andpartial_trace
functions with the corresponding equivalent functions provided from the picos module (that is,picos.partial_transpose
andpicos.partial_trace
, respectively.The other places in the code that make use of either
partial_trace
orpartial_tranpose
will necessarily need to be updated along with any mention of usage in the docs/tutorials.The text was updated successfully, but these errors were encountered: