hongyehu / PyClifford

An intuitive programming package for simulating and analyzing Clifford circuits, quantum measurement, and stabilizer states with applications to many-body localization, classical shadows, quantum chemistry and error correction code.
https://hongyehu.github.io/PyCliffordPages/intro.html
BSD 3-Clause "New" or "Revised" License
69 stars 13 forks source link

[Unitary Hack]Mix state evolution, and expectation value calculation #22

Open hongyehu opened 1 month ago

hongyehu commented 1 month ago

Implement mixed state quantum evolution, measurement, and expectation values. In the current implementation, the stabilizer state class has an attribute stabilizer_state.r which labels how many stabilizer generators are used to describe the state. For example, for a N qubit stabilizer state, in the gs matrix, the first N rows denote the stabilizer generators in binary vectors, and the second N rows denote the destabilizer generators in binary vectors. And the stabilizer generators used are from stabilizer_state.r to N, while destabilizer generators used are from stabilizer_state.r+N to 2N.

Therefore, if stabilizer_state.r=0, the state is fully stabilized by the first N generators, and the state is pure. And one need to change the evolution, measurement, calculation of expectation functions accordingly to general 0<stabilizer_state.r<=N for the mixed states.

vietnguyen012 commented 1 month ago

Hi, I would like to take up the issue. Can you assign it to me? thank you.

vietnguyen012 commented 1 month ago

Hi, I would like to take up the issue. Can you assign it to me? thank you.

P.S: I've just read the underlying code of pyclifford for the pure state operations, I understand nothing tbh 🙁. Do you have documents or papers explaining the algorithms for doing the projection's evolution, measurement and expectation for pure state or even better mixed states? I really appreciate your help! I am still new to the stabilizer code but I really want to learn more about it by solving this challenge.

hongyehu commented 1 month ago

@vietnguyen012 according to the unitary fund, the bounty is not assigned to a person until one finishes it. I am happy to help you understand better. I will attach some references on the stabilizer state and its simulation here. If you need extra help, please let me know. :-)

vietnguyen012 commented 1 month ago

yes, I will try to solve it. I am still waiting for your references though.

vietnguyen012 commented 4 weeks ago

Hi, I noticed that it looks like the measurement function has already implemented measurements with r > 0. Is that right? I need to confirm this.

dobbse42 commented 3 weeks ago

Hello! I'll be giving this one a shot. In your problem statement you mention that the stabilizer generators go from StabilizerState.r to N, and the destabilizer generators from StabilizerState.r+N to 2N. This differs from the original Aaronson and Gottesman paper in two significant ways: 1) Aaronson and Gottesman place the destabilizers first, and the stabilizers second (I don't think this causes any issues, it's just important to remember when trying to compare the code to the algorithm outlined in the paper). 2) In the mixed case, the stabilizer mixed state is generated by r stabilizers and additionally has r destabilizers, not n-r as you have in the code. There are instead n-r logical X and logical Z operators (see section VIIA on page 11). I believe this to be a bug in your code which has simply not presented itself up to now since r has always been 0. I'm going to start working on implementing the modified operations with the assumption that gs will contain r stabilizers, followed by n-r X operators, followed by r destabilizers, followed by n-r Z operators, but actually making that change might affect other parts of the code. Have I misunderstood anything here, or do you plan for this to be implemented in a different way than I outlined? Additionally, do you expect a partial trace to be implemented for the mixed case (since this is not yet implemented for even the pure case)?Thanks in advance.

dobbse42 commented 2 weeks ago

After spending a while looking at the code, I am now under the impression that all of the requested functionality has actually already been implemented since the first commit. stabilizer_project, stabilizer_measure, and stabilizer_expect all allow for non-zero r and (I believe) function correctly. The only functionality which I believe may remain to be implemented is actually finding the logical Z and X operators (the "standby operators") when creating a stabilizer mixed state, as I cannot tell if the stabilizer_project function would halt at non-zero r with correct operator values if given stabilizers defining a stabilizer mixed state (and I don't think any of the existing unit tests look for this).

@hongyehu Is there still some desired functionality missing from the stabilizer functions in utils.py? Am I correct in understanding that the existing unit tests do not test for correct values of standby operators for arbitrary stabilizer mixed states, and so this is all that needs to be implemented?

Additionally, in the interest of helping others who might want to contribute to this project: stabilizer_state.r refers to the value "n-r" in the Aaronson and Gottesman paper (the number of logical operators, not the number of stabilizer generators), and stabilizer_state.gs holds the Z operators, followed by the stabilizer generators, followed by the X operators, followed by the destabilizer generators.

vietnguyen012 commented 2 weeks ago

Hi @dobbse42, do you think the r needs to be 0 after the algorithm is finished bc we basically purify the mixed states by representing it as a tableau of a pure state? on the side note, I find it hard to reconcile the algorithm from the paper and pyclifford. Pyclifford uses an observable to interact with the stabilizer states whereas Aaronson and Gottesman's algorithm just manipulates on the state itself. Probably I dont really understand the purpose of those row operations haha.