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

Enforce the positivity of prob inside ProbMP.process_density_matrix #6727

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pennylane/measurements/probs.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def process_density_matrix(self, density_matrix: TensorLike, wire_order: Wires):
)

# Since we only care about the probabilities, we can simplify the task here by creating a 'pseudo-state' to carry the diagonal elements and reuse the process_state method
# Introduce a small epsilon to avoid sqrt(0) to ensure absolute positivity.
prob = qml.math.real(prob)
prob = qml.math.where(prob < 0, -prob, prob)
prob = qml.math.where(prob == 0, prob + np.finfo(float).eps, prob)
p_state = qml.math.sqrt(prob)
JerryChen97 marked this conversation as resolved.
Show resolved Hide resolved
return self.process_state(p_state, wire_order)

Expand Down
Loading