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
Compute a Kraus representation from the Choi matrix #4549
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after responding to questions
if choi.shape != (d * d, d * d): | ||
raise ValueError(f"Invalid Choi matrix shape, expected {(d * d, d * d)}, got {choi.shape}") | ||
if not np.allclose(choi, choi.T.conj()): | ||
raise ValueError("Choi matrix must be Hermitian") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cirq-core/cirq/qis/channels.py
Outdated
if not np.allclose(choi, choi.T.conj()): | ||
raise ValueError("Choi matrix must be Hermitian") | ||
|
||
w, v = np.linalg.eig(choi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use eigh here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Done.
The new
cirq.choi_to_kraus
function is like the existingcirq.kraus_to_choi
but in the opposite direction.Note that the former chooses one of many admissible Kraus representations while the latter maps all valid Kraus representations to the Choi. Therefore,
cirq.kraus_to_choi(cirq.choi_to_kraus(c)) == c
, but it is not necessarily the case thatcirq.choi_to_kraus(cirq.kraus_to_choi(ks)) == ks
. Check out section and retraction if you like this sort of thing.Example future use-cases: channel comparisons, obtaining Kraus representation of a noisy circuit.
Some context: #3248.