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

Create ChoiState type and conversions to/from SuperOperator #115

Merged
merged 4 commits into from
Nov 17, 2024

Conversation

akirakyle
Copy link
Member

@akirakyle akirakyle commented Jun 29, 2023

Unlike qutip, which uses type = super, superrep = choi to mark a qobj as a superoperator in the choi representation, I personally think it makes more sense to just reuse the normal Operator type to represent a choi matrix since it must be a valid density operator after all. Also it often makes sense to compute things like the Von Neumann entropy of the choi state. To convert back to the superoperator representation, one needs to assume some convention for which of the two Hilbert spaces is the auxiliary/reference/environment system and which represents the channel's output system. I've chosen the convention which seems standard to have the first system be the reference and the second be the output system.

I still need to add docs and tests but I thought I'd open this now as a draft so that there can be some discussion of these choices. Also this might be a good time to follow through on the TODO to upstream _permutedims and maybe figure out how to make it operate on ReshapedSparseArray?

Rough TODO list:

  • converters back and forth between the 3 types
  • docstrings with doctest-based examples
  • test for correctness
  • application methods (e.g. at the very least having multiplication operator between superoperators and density matrices)

@codecov
Copy link

codecov bot commented Jun 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.06%. Comparing base (bb71f52) to head (ca52e97).
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #115      +/-   ##
==========================================
+ Coverage   93.00%   93.06%   +0.05%     
==========================================
  Files          25       26       +1     
  Lines        3104     3257     +153     
==========================================
+ Hits         2887     3031     +144     
- Misses        217      226       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Krastanov
Copy link
Collaborator

@akirakyle , I think here it would be a great place to use the multimethod style of julia.

With the current setup you are proposing, the following will be a bit difficult: applying the choi superoperator to some operator.

My initial suggestion would be to create

struct ChoiSuperOperator{T} <: AbstractSuperOperator
    choistate::{T}
end

ChoiSuperOperator(sop::SuperOperator) = ChoiSuperOperator(_super_to_choi(sop))
SuperOperator(csop::ChoiSuperOperator) = ...

Then you can easily have the same function (e.g. multiplication or apply!) have different methods for Operator and ChoiSuperOperator. I imagine this would avoid confusion down the line where you would want the same function to act on an Operator that just represents some state or some unitary and an Operator that would have meant to represent a Choi state in a superoperator.

Do not hesitate to voice dissent if this seems misguided. Let me know what you think.

@akirakyle
Copy link
Member Author

@Krastanov I think it might make sense to keep this in draft status for awhile while I get some experience using the choi representation in my own code to see what feels most natural. I think you might be right in that the safest method would to introduce a ChoiSuperOperator subtype of AbstractSuperOperator and explicitly method dispatch the functions you want to think of it as a state appropriately (such as entanglement_entropy).

@akirakyle
Copy link
Member Author

@Krastanov I am finally getting back to working on this and I noticed that the PauliTransferMatrix and ChiMatrix types don't subtype AbstractSuperOperator. Should they? After all they just different representations of superoperators and I think I will be modeling the ChoiState type on them.

I will be needing the Kraus representation of superoperators as well so I think I will go ahead and implement a KrausOperators type that will behave similarly to all the other explicit superoperator representations. Also as I'm working on this would it make sense to put some documentation of more of the high level concepts into the superoperators page here? I'm thinking something along the lines of this doc page from forest benchmarking, which I've found to be a very useful reference whenever I've been working with superoperators.

@akirakyle
Copy link
Member Author

I'm also noticing that the constructors for SuperOperator, DensePauliTransferMatrix, and DenseChiMatrix are all essentially the same so perhaps we should just rely on the constructor for SuperOperator and maybe introduce a DataSuperOperator type to parallel the way construction of dense and sparse Operator is handled?

@akirakyle akirakyle force-pushed the choi branch 2 times, most recently from 7e848f4 to 81a9159 Compare March 11, 2024 23:32
@akirakyle akirakyle marked this pull request as ready for review March 11, 2024 23:33
@Krastanov
Copy link
Collaborator

Hi, Akira! Pardon the slow response, I did not notice that was converted away from draft status. I will try to review this in the next few days.

@Krastanov
Copy link
Collaborator

Hi, Akira! I guess a week turned into a month, sorry about that.

I did some very minor touchup, but feel free to disregard the last commit (by doing a force push here). Otherwise, do not forget to do a pull first to incorporate it.

Given other things you have mentioned in this thread, does the following todo list sound reasonable as prerequisite for merging (of course, there is no expectation that you have to do this -- it is already appreciated that you have donated some of your time to start this):

  • another type for the Kraus representation
  • converters back and forth between the 3 types
  • docstrings with doctest-based examples
  • test for correctness
  • application methods (e.g. at the very least having multiplication operator between superoperators and density matrices)

I will add this to the PR description and convert it to a draft for now (that helps me with organizing my own PR-review work). Do not hesitate to convert this back to non-draft and request a review.

@Krastanov Krastanov marked this pull request as draft June 10, 2024 14:47
@akirakyle
Copy link
Member Author

That looks like a solid todo list to me and represents what I would like to see with regards to getting all the common superoperator representations implemented with a reasonable interface.

I've been consumed by another research project which is why I haven't been spending time on this lately but I do intended to come back to this at some point, hopefully soon.

@akirakyle akirakyle force-pushed the choi branch 2 times, most recently from 45e5850 to c12a150 Compare July 24, 2024 22:14
@akirakyle
Copy link
Member Author

@Krastanov I've finally been coming back to this PR as I've picked up the research project that relies on it again!

I've implemented the KrausOperators representation and converters to/from SuperOperator and ChoiState. I still need to think about how to incorporate PauliTransferMatrix and DenseChiMatrix as they are also types of super operators but only valid for tensors of qubit or qudit basis afaiu. In fact, I think the way QO has chosen to represent density operators as a specific type of quantum operator with equal basis_l and basis_r means that the SuperOperator type can represent types of quantum maps that don't admit a Kraus decomposition. There's currently a comment about this in the docstring for theKrausOperators struct the latest update to this PR.

The conversion from ChoiState to KrausOperators requires finding eigenvalues and vectors. Currently I'm just using LinearAlgebra's eigen, but it would be useful if sparse matrices were handled without the conversion to dense, which I think would require pulling in something like Arpack.jl or ArnoldiMethod.j. Furthermore, there's the associated numerical tolerances and the interface for setting those which I have a rough implementation of currently.

PS: I am currently in Boston until this Sunday, then stonehill until next friday, so if you are around and would like to meet up in person to discuss this or anything else julia/quantum related, let me know when works!

@akirakyle akirakyle force-pushed the choi branch 6 times, most recently from 2ab7770 to 1154c2a Compare October 7, 2024 21:29
@akirakyle akirakyle changed the title Add super_to_choi and choi_to_super Create ChoiState type and conversions to/from SuperOperator Oct 7, 2024
@akirakyle akirakyle marked this pull request as ready for review October 7, 2024 22:14
@akirakyle
Copy link
Member Author

@Krastanov I think this should finally be ready for review!

I've split off implementing Kraus operators into a separate PR #177 to make it easier for both myself and for review.

@Krastanov Krastanov self-requested a review October 8, 2024 14:04
@Krastanov
Copy link
Collaborator

Thanks! I will try to look into it later this week. Please ping me if I have not done so by next week

Copy link
Collaborator

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

This looks great, thank you so much for the contribution! Apologies for the slow review. I have a few very minor suggestions, please check them out.

If we keep this non-public for a while, I am happy to merge this ASAP.

new(basis_l, basis_r, data)
end
end
ChoiState{BL,BR}(b1::BL, b2::BR, data::T) where {BL,BR,T} = ChoiState{BL,BR,T}(b1, b2, data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to make sure everything is really fine, could you add a test for this constructor as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah this is left over from my copy-paste of the SuperOperator constructors. I don't actually use this so I just went ahead and deleted it. It can easily be added back if it's needed at any point in the future.

@@ -228,4 +247,20 @@ N = exp(log(2) * sparse(L)) # 50% loss channel
@test (0.5 - real(tr(ρ^2))) < 1e-10 # one photon state becomes maximally mixed
@test tracedistance(ρ, normalize(dm(fockstate(b, 0)) + dm(fockstate(b, 1)))) < 1e-10

# Testing 0-2-4 binomial code encoder
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a really neat test!

@@ -36,8 +36,8 @@ export Basis, GenericBasis, CompositeBasis, basis,
current_time, time_shift, time_stretch, time_restrict, static_operator,
#superoperators
SuperOperator, DenseSuperOperator, DenseSuperOpType,
SparseSuperOperator, SparseSuperOpType, spre, spost, sprepost, liouvillian,
identitysuperoperator,
SparseSuperOperator, SparseSuperOpType, ChoiState,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep it unexported until more of the related functionality is completed and it has been tested a bit more. I want to avoid a breaking release.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good to me, especially since #177 may rework things a bit!

end

ChoiState(op::SuperOperator) = ChoiState(_super_choi(op.basis_l, op.basis_r, op.data)...)
SuperOperator(op::ChoiState) = SuperOperator(_super_choi(op.basis_l, op.basis_r, op.data)...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it make sense to also add a Ket(::ChoiState) constructor, so that we can actually extract it as a state?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it makes sense since in general the ChoiState is mixed iff the corresponding channel is non-unitary, so it is akin to asking for a Ket(::Operator) method which has multiple ways in which it could make sense, e.g. closest pure state under a given operator norms.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, noted. Then maybe a dm(::ChoiState) would make sense, but no need to block the PR on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have something like that added as part of #177. The tricky part is ensuring the input and ancilla bases make sense and can be appropriately manipulated!

@akirakyle
Copy link
Member Author

akirakyle commented Nov 15, 2024

@Krastanov I just addressed your comments!

P.S. If you get the chance to give some feedback on my proposal in qojulia/QuantumInterface.jl#26 that would help me to organize my work on this going forward!

@Krastanov
Copy link
Collaborator

This is ready to merge, but it seems the release of 1.11 in the meantime has broken a bunch of allocation tests.

@amilsted , is this on your radar, it seems to be related to the time-dependent operators.

I will make a separate issue for that. This PR is not at fault. @akirakyle , could you please mark the those tests as broken? Afterwards we can go ahead and merge this. If you do not have the bandwidth, that is fine, one of us should get around to it in the next week anyway.

@akirakyle
Copy link
Member Author

@Krastanov I marked the failing test as broken and so now all tests are passing on 1.11

@Krastanov Krastanov merged commit 2b6763b into qojulia:master Nov 17, 2024
11 of 12 checks passed
@akirakyle akirakyle deleted the choi branch November 19, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants