Skip to content

Add testing helper for consistent channel/mixture #5247

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

Merged
merged 6 commits into from
May 19, 2022

Conversation

dabacon
Copy link
Collaborator

@dabacon dabacon commented Apr 12, 2022

Adds a helper that tests that channel kraus operator is cptp (\sum_i A_i^\dagger A_i = I) and that has_kraus is true. Uses this on channels.

Adds a helper for testing that mixture's probabilities sum to 1. Uses this on mixtures.

Fixes #2271

@dabacon dabacon requested review from a team, vtomole and cduck as code owners April 12, 2022 03:58
@dabacon dabacon requested a review from dstrain115 April 12, 2022 03:58
@CirqBot CirqBot added the size: M 50< lines changed <250 label Apr 12, 2022
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

Could we also add similar for mixture ?

@MichaelBroughton MichaelBroughton self-assigned this Apr 15, 2022
@95-martin-orion
Copy link
Collaborator

Related: #4365

Comment on lines 20 to 26
def assert_consistent_channel(gate: Any, rtol: float = 1e-5, atol: float = 1e-8):
assert cirq.has_kraus(gate), f"Given gate {gate!r} does not return True cirq.has_kraus."
kraus_ops = cirq.kraus(gate)
assert cirq.is_cptp(kraus_ops=kraus_ops, rtol=rtol, atol=atol), (
f"Kraus operators for {gate!r} did not sum to identity up to expected tolerances. "
f"Summed to {sum(m.T.conj() @ m for m in kraus_ops)}"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also add tests for has_mixture and mixture.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is now done

@dabacon dabacon changed the title Add testing helper for consistent channel Add testing helper for consistent channel/mixture May 14, 2022
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

LGTM

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 19, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label May 19, 2022
@CirqBot CirqBot merged commit 734ddc2 into quantumlib:master May 19, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels May 19, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Adds a helper that tests that channel kraus operator is cptp (\sum_i A_i^\dagger A_i = I) and that has_kraus is true.  Uses this on channels.

Adds a helper for testing that mixture's probabilities sum to 1.  Uses this on mixtures.

Fixes quantumlib#2271
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Adds a helper that tests that channel kraus operator is cptp (\sum_i A_i^\dagger A_i = I) and that has_kraus is true.  Uses this on channels.

Adds a helper for testing that mixture's probabilities sum to 1.  Uses this on mixtures.

Fixes quantumlib#2271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add validation for Kraus operators
5 participants