Skip to content

Commit

Permalink
add wonderful code review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Nov 6, 2024
1 parent 0fbea7d commit a8a8589
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ function __init__()
BIG_INT_MINUS_ONE[] = BigInt(-1)
BIG_INT_TWO[] = BigInt(2)
BIG_INT_FOUR[] = BigInt(4)

# Register error hint for the `project!` method for GeneralizedStabilizer
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
if exc.f == project!
print(io, "\n\n")
print(io, "The method `project!` is not applicable for `GeneralizedStabilizer` with measurements\n")
print(io, "involving the Hermitian Pauli operator M. \n")
print(io, "The `GeneralizedStabilizer` 𝜏 is updated by measuring M = 𝒶⋅𝒹ₘ⋅𝓈ₙ, resulting in the new\n")
print(io, "state 𝜏′ defined as: 𝜏′ = ¼(I + M)𝜏(I + M) = (ϕ′, B(𝒮′, 𝒟′)) where (𝒮′, 𝒟′) is derived\n")
print(io, "from (𝒮, 𝒟) through the traditional stabilizer update, and 𝜙' represents the updated\n")
print(io, "density matrix. Note that ¼(I − M)𝜏(I − M) can be obtained by changing the sign of 𝒶.\n\n")
print(io, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n")
print(io, "The projection requires a probabilistic approach, as measurement outcomes depend on \n")
print(io, "the expectation value of the `PauliOperator`. Specifically, the expectation value is \n")
print(io, "derived from the trace Tr[𝜏′] = Tr[ϕᵢⱼ′] in the expression: 𝜏′ = ∑ ϕᵢⱼ Pᵢ ρ Pⱼ† , where 𝜙ᵢⱼ′\n")
print(io, "is the updated 𝜙-matrix. The trace Tr[𝜏′] = Tr[ϕᵢⱼ′] represents the probability of \n")
print(io, "measuring either 0 or a non-zero outcome and serves as the normalization required for 𝜏′.\n\n")

print(io, "To correctly perform the 'nondeterministic' projection, please use ")
printstyled(io, "`projectrand!`", color=:cyan)
print(io, ".\n\n")

print(io, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n")
print(io, "Moreover, `project!` in this library operates as a 'deterministic' method to verify \n")
print(io, "whether a measurement operator commutes with stabilizers. Based on this commutation, it \n")
print(io, "executes additional steps to determine the resultant state after projection. Thus, there \n")
print(io, "are semantic nuances in defining `project!` consistently for `GeneralizedStabilizer`, \n")
print(io, "particularly regarding the interpretations of `anticom` and `res` in this context.\n\n")
print(io, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n")
print(io, "𝒩𝒪𝒯ℰ𝒮:\n")
print(io, "- `rowdecompose(M, 𝜏.stab)`: Provides the decomposition of M in terms of stabilizer \n")
print(io, "and destabilizer rows of the given tableau of 𝜏.\n\n")
print(io, "- `expect(M, 𝜏)`: Returns the updated ϕ-matrix ϕᵢⱼ′, where the trace Tr[ϕᵢⱼ′] provides \n")
print(io,"the expectation value of measuring ℳ.\n\n")
end
end
end

const NoZeroQubit = ArgumentError("Qubit indices have to be larger than zero, but you are attempting to create a gate acting on a qubit with a non-positive index. Ensure indexing always starts from 1.")
Expand Down

0 comments on commit a8a8589

Please sign in to comment.