-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add is_cptp predicate #4365
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
Add is_cptp predicate #4365
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.
Looks good. The only thing I would change is in the test if we could try and cut out the dependency on other library pieces if we can. Also might be useful:
A random set of kraus operators can be made by doing (Totally untested :P):
one_qubit_u = cirq.testing.random_unitary(8)
one_qubit_kraus = np.reshape(one_qubit_u[:, :2], (-1, 2, 2)) # make 4 2x2 kraus ops.
or
two_qubit_u = cirq.testing.random_unitary(64)
two_qubit_kraaus = np.reshape(two_qubit_u[:, :4], (-1, 4, 4)) # make 16 4x4 kraus ops.
cirq-core/cirq/linalg/predicates.py
Outdated
@@ -149,6 +149,21 @@ def is_normal(matrix: np.ndarray, *, rtol: float = 1e-5, atol: float = 1e-8) -> | |||
return matrix_commutes(matrix, matrix.T.conj(), rtol=rtol, atol=atol) | |||
|
|||
|
|||
def is_cptp(kraus_ops: Sequence[np.ndarray], *, rtol: float = 1e-5, atol: float = 1e-8): |
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.
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.
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.
A reasonable way to ensure this is forward compatible with changing that choice is to force keyword args for kraus_ops
. We can weaken it later that way if we decide to stick with it, or add other args if we want to extend.
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 point - moved kraus_ops
into kwargs.
Added the recommended random tests. |
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
As requested in quantumlib#4194. Can be used for quantumlib#2271. This predicate is meant to be invoked when constructing a channel to verify that the provided Kraus operators actually describe a valid quantum channel. Recommendations for cleaner `is_cptp` behavior or additional test cases are welcome.
As requested in quantumlib#4194. Can be used for quantumlib#2271. This predicate is meant to be invoked when constructing a channel to verify that the provided Kraus operators actually describe a valid quantum channel. Recommendations for cleaner `is_cptp` behavior or additional test cases are welcome.
As requested in #4194. Can be used for #2271.
This predicate is meant to be invoked when constructing a channel to verify that the provided Kraus operators actually describe a valid quantum channel. Recommendations for cleaner
is_cptp
behavior or additional test cases are welcome.