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

noncliff: define _proj subroutine for projectrand! and test multi-qubit projection for stabilizer and non-stabilizer states #355

Closed
wants to merge 22 commits into from

Conversation

Fe-r-oz
Copy link
Contributor

@Fe-r-oz Fe-r-oz commented Sep 8, 2024

PR implements project! for noncliff. Basic tests are added as well.

  • The code is properly formatted and commented.
  • Substantial new functionality is documented within the docs.
  • All new functionality is tested.
  • All of the automated tests on github pass.

@Fe-r-oz Fe-r-oz marked this pull request as ready for review September 27, 2024 14:56
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Sep 27, 2024

I think the PR is ready for review. I hope it's not awkward. Thank you!

Copy link
Member

@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.

Thanks for starting this, it is incredibly helpful to have someone tackle it.

I left a few comments in, but I think there is a bigger thing that is currently unclear to me: in _proj₊ you access only the base tableau out of which all terms in the weighted sum are generated, but you do not access any of those terms themselves, nor are their relative weights taken into account. And it seems that you are returning a pure state, not a GeneralizedStabilizer. But one single measurement is not enough to turn a mixed state into a pure state, so there must be an issue with the current code.

src/nonclifford.jl Outdated Show resolved Hide resolved
src/nonclifford.jl Outdated Show resolved Hide resolved
test/test_nonclifford_quantumoptics.jl Outdated Show resolved Hide resolved
test/test_nonclifford_quantumoptics.jl Outdated Show resolved Hide resolved
@Krastanov Krastanov marked this pull request as draft September 27, 2024 17:39
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Oct 1, 2024

Thanks for your pertinent observation. Indeed, something was wrong as I was only considering the tableau, not the catering X. What I overlooked was that in the base paper, Ted tells us to update the GeneralizedStabilizer state τ with the reduced χ-matrix namely χ' after performing the measurement (expect). That I did not...

This is why Ted says that 'trace Tr [τ′] = Tr [χ′] is the probability of measuring 0' when talking about the case of measuring 0. My bad...

Now, we have deterministic project! and random projectrand!.

@Fe-r-oz Fe-r-oz force-pushed the project branch 3 times, most recently from 18a3b7b to b367530 Compare October 1, 2024 16:21
@Fe-r-oz Fe-r-oz marked this pull request as ready for review October 1, 2024 17:30
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Oct 1, 2024

The PR is ready for review, Thank you!

Copy link
Member

@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.

Thanks for continuing with this. It seems there are a few mistakes in the tests. Could you look into them?

src/nonclifford.jl Outdated Show resolved Hide resolved
src/nonclifford.jl Outdated Show resolved Hide resolved
src/nonclifford.jl Outdated Show resolved Hide resolved
test/test_nonclifford_quantumoptics.jl Outdated Show resolved Hide resolved
test/test_nonclifford_quantumoptics.jl Outdated Show resolved Hide resolved
test/test_nonclifford_quantumoptics.jl Outdated Show resolved Hide resolved
@Krastanov Krastanov marked this pull request as draft October 25, 2024 02:17
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Oct 25, 2024

Thank you for your feedback.

I've removed projectrand! from this PR, as I don’t have clarity on whether χ' is needed in projectrand!, based on your comment here: discussion link.

This PR focuses solely on implementing project!, which corresponds to Algorithm 2 in Ted's paper. Regarding project!, Ted states that we should update the GeneralizedStabilizer state τ with the reduced χ-matrix, specifically χ', after performing the measurement (expectation). That is why we take the trace (i.e., $\text{Tr} [\tau'] = \text{Tr} [χ']$) to calculate the probability of obtaining 0 or non-zero. I hope this sounds reasonable.

I’ll address projectrand! in a separate PR after giving it more thought in light of your feedback.

I attempted to use the suggested test (shown below) from this comment: discussion link, but I encountered an error when testing with Stabilizer/MixedDestabilizer. Consequently, I added a similar test in the test section that passes for both GeneralizedStabilizer and Stabilizer/MixedDestabilizer.

While the test may be basic, I would appreciate your feedback on its conceptual correctness. I hope it doesn't fall into the trap of being tautologically true. The tests pass for gs when changed to checks = [(random_stabilizer(1), random_pauli(1))] as well. It appears that using a repetition loop outside or employing more than one qubit results in errors, even when utilizing the Stabilizer instead of GeneralizedStabilizer

Thank you again for your guidance, and I look forward to your thoughts.

# gives error for Stabilizer/MixedDestabilizer
julia> @testset "project! for Stabilizer/MixedStabilizer" begin
           for n in 1:4
               for repetition in 1:5
                   s = random_stabilizer(n) # or md = MixedDestabilizer(random_stabilizer(n))
                   p = random_pauli(n)
                   apply!(s, p)
                   qo_state = Operator(s)
                   project!(s, p)[1]
                   qo_state_after_proj = Operator(s)
                   qo_pauli = Operator(p)
                   qo_proj1 = (identityoperator(qo_pauli) - qo_pauli)/2
                   qo_proj2 = (identityoperator(qo_pauli) + qo_pauli)/2
                   result1  = qo_proj1*qo_state*qo_proj1'
                   result2  = qo_proj2*qo_state*qo_proj2'
                   @test qo_state_after_proj ≈ result2 || qo_state_after_proj ≈ result1
               end
           end
       end

@Fe-r-oz Fe-r-oz marked this pull request as ready for review November 8, 2024 22:28
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Nov 8, 2024

Thank you for your valuable feedback!

This PR builds upon the scaffolding introduced in #420, addresses #418, and includes a test for GeneralizedStabilizer from #424. It demonstrates multi-qubit projection using random_stabilizer states and the random_pauli operator for GeneralizedStabilizer, which also holds for Stabilizer and MixedDestabilizer. T̶h̶e̶ r̶e̶m̶a̶i̶n̶i̶n̶g̶ t̶a̶s̶k̶ i̶s̶ t̶o̶ a̶d̶d̶ t̶e̶s̶t̶s̶ f̶o̶r̶ n̶o̶n̶-̶s̶t̶a̶b̶i̶l̶i̶z̶e̶r̶ c̶a̶s̶e̶, w̶h̶i̶c̶h̶ p̶a̶s̶s̶ p̶r̶o̶b̶a̶b̶i̶l̶i̶s̶t̶i̶c̶a̶l̶l̶y̶ b̶u̶t̶ r̶e̶q̶u̶i̶r̶e̶ a̶d̶d̶i̶t̶i̶o̶n̶a̶l̶ w̶o̶r̶k̶.

Overall, this PR demonstrates that GeneralizedStabilizer encompasses all the capabilities outlined in the Gottesman-Knill theorem. It also extends the aforementioned theorem by showing that multi-qubit stabilizer states, when subjected to multi-qubit randomized non-Clifford gates, can be probabilistically projected through repeated trials. These findings reinforce Ted's conclusion that "no magic state will be simulatable through every stabilizer circuit."

Edit:

The MixedDestabilizer case from #424 has been added as a reference to demonstrate consistent multi-qubit projection results for stabilizer simulation when compared with GeneralizedStabilizer.

graph TD

subgraph NittyGritty [ ]
        direction TB
        D--> D1[define_proj]
    end

subgraph Tests [ ]
    direction TB
     E[Consistency Tests] --> E1[random_stabilizer, *done* <br>random_pauli, *done* <br> random_clifford, *done* <br> non-stabilizer *done*]
 end

    subgraph ScaffoldingBranch [ ]
        direction TB
        B[Scaffolding] --> B1[completed]
    end
    subgraph ErrorBranch [Unrelated Errors, <br> Issue #418]
        direction TB
        C[Unrelated Errors, <br> Issue #418] --> C1[Resolve projection inconsistencies for multi-qubit Stabilizer/MixedDestabilizer]
    end
    A[projectrand!] --> C
    A[projectrand!] --> B
  A[projectrand!] --> E
    A --> D[Nitty Gritty]
Loading

Additional work:

Update: added with the recent commit: ca9bcee

I have also started working on the remaining task shown in the mermaid diagram. Increasing the number of repetitions has been shown to improve the success probability, exceeding $50$% for the non-stabilizer simulation with random multi-qubit non-Clifford gates. For example, using random $8$-qubit non-Clifford gates with $1,000$ repetitions results in a success probability greater than $50$%, which also holds for $n$-qubit random non-Clifford gates after the same number of repetitions. With this setup, we can now probabilistically simulate non-stabilizer circuits containing random n-qubit non-Clifford gates.

Test/Reproducible:

@testset "probabilistic non-stabilizer circuit simulation" begin
    num_trials = 10
    count = 0
    for n in 1:10 # num_qubits: 1 to 10
        for _ in 1:num_trials
            s = random_stabilizer(n)
            p = random_pauli(n)
            τ = GeneralizedStabilizer(s)
            i = rand(1:n)
            nc = embed(n, i, pcT)
            apply!(τ, nc) # multi-qubit random non-Clifford gate
            qo_state = Operator(τ)
            projectrand!(τ, p)[1]
            qo_state_after_proj = Operator(τ)
            qo_pauli = Operator(p)
            qo_proj1 = (identityoperator(qo_pauli) - qo_pauli)/2
            qo_proj2 = (identityoperator(qo_pauli) + qo_pauli)/2
            result1 = qo_proj1 * qo_state * qo_proj1'
            result2 = qo_proj2 * qo_state * qo_proj2'
            norm_qo_state_after_proj = qo_state_after_proj/tr(qo_state_after_proj)
            norm_result1 = result1/tr(result1)
            norm_result2 = result2/tr(result2)
            if norm_qo_state_after_proj ≈ norm_result2 || norm_qo_state_after_proj ≈ norm_result1
                count += 1
            end
        end
    end
    prob = count/(num_trials*10)
    @test prob > 0.5 # increase trials to increase probability
end

I think this aligns with the probabilistic nature of non-Clifford simulations, as discussed by Bravyi and Gosset in their paper Improved classical simulation of quantum circuits dominated by Clifford gates. They introduced an algorithm for approximating the output probability $P_\text{out(x, y)}$ in circuits composed of Clifford and T gates, highlighting that success probability in weak simulations is probabilistic and can be improved through repeated sampling, albeit with an associated computational cost. In addition, this talk provides survey of non-Clifford simulators, highlighting the probabilistic simulation approaches mentioned in aforementioned paper.

Ted also provide comparable insights in the conclusion section: The set of states that are stabilizer circuit efficient is related to the set of magic states, those states that, when combined with stabilizer circuits, allow universal quantum computation. The problems are essentially complementary; no magic state will be simulatable through every stabilizer circuit (assuming BQP is larger than BPP, that is). With qudits of odd prime dimension, it was recently found in https://arxiv.org/pdf/1201.1256 that a sufficient condition for a state to be efficiently (weakly) simulated through stabilizer circuits is that a certain quasi-probability representation of the state be positive.

Reproducible 2 for Issue 309 results:

The results demonstrate that the post-measurement complex density matrices match the expected outcomes (printed as TRUE), supporting Ted's comment that we can simulate some 'magic' states using the stabilizer-defined basis. However, not all 'magic' states are simulatable in this way (printed as FALSE), as noted by Ted. PFA: 3_qubit_ncgate_results.txt

julia> @testset "non-Clifford simulation" begin
           n=3; # easier to see the 8 x 8 density matrices on console/txt file
           for repetition in 1:20
               s = random_stabilizer(n)
               p = random_pauli(n)
               τ = GeneralizedStabilizer(s)
               i = rand(1:n)
               apply!(τ, embed(n, i, pcT))
               qo_state = Operator(τ)
               projectrand!(τ, p)[1]
               qo_state_after_proj = Operator(τ)
               qo_pauli = Operator(p)
               qo_proj1 = (identityoperator(qo_pauli) - qo_pauli)/2
               qo_proj2 = (identityoperator(qo_pauli) + qo_pauli)/2
               result1 = qo_proj1*qo_state*qo_proj1'
               result2 = qo_proj2*qo_state*qo_proj2'
               norm_qo_state_after_proj = qo_state_after_proj/tr(qo_state_after_proj)
               norm_result1 = result1/tr(result1)
               norm_result2 = result2/tr(result2)
               println("========================================================================================")
               println("NORM_QO_STATE_AFTER_PROJ ", norm_qo_state_after_proj)
               println("NORM_RESULT ", norm_result1)
               println("NORM_RESULT2 ", norm_result2)
               if norm_qo_state_after_proj ≈ norm_result2 || norm_qo_state_after_proj ≈ norm_result1
                   println("TRUE, multi-qubit projection holds")
               else
                   println("FALSE")
               end
              println("========================================================================================")
           end
       end

@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Nov 9, 2024

This PR is ready for review, Thank you!

Edit:

Pardon - I've now added the remaining probabilistic non-stabilizer simulator tests, testing up to 10 qubits with random non-Clifford gates at randomized positions. I also did some further reading on probabilistic non-stabilizer simulators, incorporating insights from Ted's paper and other key studies in the additional work section: #355 (comment).

…n as mentiond in earlier conversation comment
src/nonclifford.jl Outdated Show resolved Hide resolved
@Fe-r-oz Fe-r-oz changed the title noncliff: define _proj subroutine for projectrand! noncliff: define _proj subroutine for projectrand! and test multi-qubit projection for stabilizer and non-stabilizer states Nov 13, 2024
Copy link
Member

@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.

I am not sure whether this is actually finished, but there was a review request. There seems to be some pretty severe issues with this implementation. See the comments.

Could you run me through why this was done in this way? I am a bit confused what the goal or reasoning was.

src/nonclifford.jl Outdated Show resolved Hide resolved
@Krastanov Krastanov marked this pull request as draft November 15, 2024 21:23
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Nov 17, 2024

There seems to be some pretty severe issues with this implementation

I must acknowledge that I overlooked pages 6 to 8 and equations 14 to 26, which provide the constructive proof of the equations. Although I was aware of this section, I neglected to incorporate it properly. Furthermore, the proper implementation of Algorithm 2, which embodies the constructive proof, was absent from my initial submission. This was a significant oversight on my part, and I apologize for the mistake.

It is also evident that my earlier attempt did not effectively translate the paper into code but rather resulted in a somewhat confused interpretation. For example, the author dedicated two pages to explaining Pauli measurements before presenting Algorithm 2 using the specialized stabilizer basis, emphasizing that a proper implementation requires a more thorough approach than the simplistic one I initially attempted. This misstep is, admittedly, quite embarrassing.

I greatly appreciate your feedback and patience throughout this process. Based on your comments, I have revisited the paper's methodology and reworked the implementation to align with the original approach outlined in Algorithm 2. As a result, I am closing this PR in favor of the new work, which is currently in progress: #427.

@Fe-r-oz Fe-r-oz closed this Nov 17, 2024
@Fe-r-oz Fe-r-oz deleted the project branch November 17, 2024 18:28
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