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: enhanced error message for inapplicable Project! of GeneralizedStabilizer #416

Merged
merged 12 commits into from
Nov 8, 2024
34 changes: 30 additions & 4 deletions src/nonclifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,41 @@ function _allthreesumtozero(a,b,c)
true
end

function project!(sm::GeneralizedStabilizer, p::PauliOperator)

project!(::GeneralizedStabilizer, ::PauliOperator) =
Copy link
Member

Choose a reason for hiding this comment

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

this can be done a bit more neatly using MethodError and a registered error hint.

E.g. throw throw(MethodError(f, (sm,p))) where sm and p are the arguments to this function.

Then use register_error_hint to register the additional explanation message: https://docs.julialang.org/en/v1.12-dev/base/base/#Base.Experimental.register_error_hint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks so much for the suggestion!

error("The method `project!` is not applicable for `GeneralizedStabilizer` with \n" *
"measurements involving the hermitian Pauli operator ℳ. The `GeneralizedStabilizer` 𝜏 \n" *
"is updated by measuring ℳ = 𝒶⋅𝒹ₘ⋅𝓈ₙ, resulting in the new state 𝜏′ defined as: \n" *
"𝜏′ = ¼(ℐ + ℳ)𝜏(ℐ + ℳ) = (𝜙′, ℬ(𝒮′, 𝒟′)), where (𝒮′, 𝒟′) is derived from (𝒮, 𝒟) \n" *
"through the traditional stabilizer update, and 𝜙' represents the updated density \n" *
"matrix. Note that ¼(ℐ − ℳ)𝜏(ℐ − ℳ) can be obtained by changing the sign of 𝒶.\n\n" *
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" *
"The projection requires a probabilistic approach, as measurement outcomes depend on \n" *
"the expectation value of the `PauliOperator`. Specifically, the expectation value is \n" *
"derived from the trace Tr[𝜏′] = Tr[𝜙ᵢⱼ′] in the expression: 𝜏′ = 𝛴 𝜙ᵢⱼ' 𝒫ᵢ 𝜌 𝒫ⱼ†, where 𝜙ᵢⱼ′\n" *
"is the updated 𝜙-matrix. The trace Tr[𝜏′] = Tr[𝜙ᵢⱼ′] represents the probability of \n" *
"measuring either 0 or a non-zero outcome and serves as the normalization required for 𝜏′.\n\n" *
"To correctly perform the 'nondeterministic' projection, please use `projectrand!`.\n\n" *
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" *
"Moreover, `project!` in this library operates as a 'deterministic' method to verify \n" *
"whether a measurement operator commutes with stabilizers. Based on this commutation, it \n" *
"executes additional steps to determine the resultant state after projection. Thus, there \n" *
"are semantic nuances in defining `project!` consistently for`GeneralizedStabilizer`, \n" *
"particularly regarding the interpretations of `anticom` and `res` in this context.\n\n" *
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" *
"𝒩𝒪𝒯ℰ𝒮:\n" *
"- `rowdecompose(ℳ, 𝜏.stab)`: Provides the decomposition of ℳ in terms of stabilizer \n" *
"and destabilizer rows of the given tableau of 𝜏.\n\n" *
"- `expect(ℳ, 𝜏)`: Returns the updated 𝜙-matrix 𝜙ᵢⱼ′, where the trace Tr[𝜙ᵢⱼ′] provides \n" *
"the expectation value of measuring ℳ.\n\n")

function projectrand!(sm::GeneralizedStabilizer, p::PauliOperator)
eval = expect(p, sm)
prob₁ = (real(eval)+1)/2
error("This functionality is not implemented yet")
end

function _proj₋(sm::GeneralizedStabilizer, p::PauliOperator)
end
function _proj₊(sm::GeneralizedStabilizer, p::PauliOperator)
function _proj(sm::GeneralizedStabilizer, p::PauliOperator)
end

nqubits(sm::GeneralizedStabilizer) = nqubits(sm.stab)
Expand Down
Loading