From aa8184c703b3d9a089c93acee69b2bc78cd612d4 Mon Sep 17 00:00:00 2001 From: Victory Omole Date: Wed, 18 Aug 2021 13:39:22 -0500 Subject: [PATCH] Replace existing calls of `SupportsChannel` to `SupportsKraus` (#4438) --- cirq-core/cirq/qis/channels.py | 6 +++--- cirq-core/cirq/qis/channels_test.py | 6 +++--- cirq-core/cirq/qis/measures.py | 2 +- cirq-core/cirq/sim/act_on_density_matrix_args.py | 4 +++- cirq-core/cirq/sim/density_matrix_simulator.py | 2 +- cirq-core/cirq/sim/sparse_simulator.py | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cirq-core/cirq/qis/channels.py b/cirq-core/cirq/qis/channels.py index 4d335b9bd47..96f516b089e 100644 --- a/cirq-core/cirq/qis/channels.py +++ b/cirq-core/cirq/qis/channels.py @@ -45,7 +45,7 @@ def kraus_to_superoperator(kraus_operators: Sequence[np.ndarray]) -> np.ndarray: return m -def operation_to_choi(operation: 'protocols.SupportsChannel') -> np.ndarray: +def operation_to_choi(operation: 'protocols.SupportsKraus') -> np.ndarray: r"""Returns the unique Choi matrix associated with an operation . Choi matrix J(E) of a linear map E: L(H1) -> L(H2) which takes linear operators @@ -68,7 +68,7 @@ def operation_to_choi(operation: 'protocols.SupportsChannel') -> np.ndarray: @deprecated(deadline='v0.14', fix='use cirq.operation_to_superoperator instead') -def operation_to_channel_matrix(operation: 'protocols.SupportsChannel') -> np.ndarray: +def operation_to_channel_matrix(operation: 'protocols.SupportsKraus') -> np.ndarray: """Returns the matrix representation of an operation in standard basis. Let E: L(H1) -> L(H2) denote a linear map which takes linear operators on Hilbert space H1 @@ -85,7 +85,7 @@ def operation_to_channel_matrix(operation: 'protocols.SupportsChannel') -> np.nd return operation_to_superoperator(operation) -def operation_to_superoperator(operation: 'protocols.SupportsChannel') -> np.ndarray: +def operation_to_superoperator(operation: 'protocols.SupportsKraus') -> np.ndarray: """Returns the matrix representation of an operation in standard basis. Let E: L(H1) -> L(H2) denote a linear map which takes linear operators on Hilbert space H1 diff --git a/cirq-core/cirq/qis/channels_test.py b/cirq-core/cirq/qis/channels_test.py index 221b5e5880b..5121b8e428d 100644 --- a/cirq-core/cirq/qis/channels_test.py +++ b/cirq-core/cirq/qis/channels_test.py @@ -20,7 +20,7 @@ import cirq -def apply_channel(channel: cirq.SupportsChannel, rho: np.ndarray) -> np.ndarray: +def apply_channel(channel: cirq.SupportsKraus, rho: np.ndarray) -> np.ndarray: ks = cirq.kraus(channel) d_out, d_in = ks[0].shape assert rho.shape == (d_in, d_in) @@ -38,7 +38,7 @@ def generate_standard_operator_basis(d_out: int, d_in: int) -> Iterable[np.ndarr yield e_ij -def compute_choi(channel: cirq.SupportsChannel) -> np.ndarray: +def compute_choi(channel: cirq.SupportsKraus) -> np.ndarray: ks = cirq.kraus(channel) d_out, d_in = ks[0].shape d = d_in * d_out @@ -48,7 +48,7 @@ def compute_choi(channel: cirq.SupportsChannel) -> np.ndarray: return c -def compute_superoperator(channel: cirq.SupportsChannel) -> np.ndarray: +def compute_superoperator(channel: cirq.SupportsKraus) -> np.ndarray: ks = cirq.kraus(channel) d_out, d_in = ks[0].shape m = np.zeros((d_out * d_out, d_in * d_in), dtype=np.complex128) diff --git a/cirq-core/cirq/qis/measures.py b/cirq-core/cirq/qis/measures.py index aaf59b5acba..518b8ec2de5 100644 --- a/cirq-core/cirq/qis/measures.py +++ b/cirq-core/cirq/qis/measures.py @@ -287,7 +287,7 @@ def von_neumann_entropy( return 0.0 -def entanglement_fidelity(operation: 'cirq.SupportsChannel') -> float: +def entanglement_fidelity(operation: 'cirq.SupportsKraus') -> float: r"""Returns entanglement fidelity of a given quantum channel. Entanglement fidelity $F_e$ of a quantum channel $E: L(H) \to L(H)$ is the overlap between diff --git a/cirq-core/cirq/sim/act_on_density_matrix_args.py b/cirq-core/cirq/sim/act_on_density_matrix_args.py index defcb2dd4b4..e26e6682fe6 100644 --- a/cirq-core/cirq/sim/act_on_density_matrix_args.py +++ b/cirq-core/cirq/sim/act_on_density_matrix_args.py @@ -115,7 +115,9 @@ def _act_on_fallback_( raise TypeError( "Can't simulate operations that don't implement " "SupportsUnitary, SupportsConsistentApplyUnitary, " - "SupportsMixture, SupportsChannel or is a measurement: {!r}".format(action) + "SupportsMixture, SupportsChannel or SupportsKraus or is a measurement: {!r}".format( + action + ) ) def _perform_measurement(self, qubits: Sequence['cirq.Qid']) -> List[int]: diff --git a/cirq-core/cirq/sim/density_matrix_simulator.py b/cirq-core/cirq/sim/density_matrix_simulator.py index 4c5a1f9d614..d4dc5ee733c 100644 --- a/cirq-core/cirq/sim/density_matrix_simulator.py +++ b/cirq-core/cirq/sim/density_matrix_simulator.py @@ -48,7 +48,7 @@ class DensityMatrixSimulator( * measurements * a `_decompose_` that eventually yields one of the above That is, the circuit must have elements that follow on of the protocols: - * `cirq.SupportsChannel` + * `cirq.SupportsKraus` * `cirq.SupportsMixture` * `cirq.SupportsConsistentApplyUnitary` * `cirq.SupportsUnitary` diff --git a/cirq-core/cirq/sim/sparse_simulator.py b/cirq-core/cirq/sim/sparse_simulator.py index 5e01f5b6a13..2c4eb99daca 100644 --- a/cirq-core/cirq/sim/sparse_simulator.py +++ b/cirq-core/cirq/sim/sparse_simulator.py @@ -56,7 +56,7 @@ class Simulator( protocol, the `cirq.SupportsMixture` protocol, or the `cirq.CompositeOperation` protocol. It is also permitted for the circuit to contain measurements which are operations that support - `cirq.SupportsChannel` and `cirq.SupportsMeasurementKey` + `cirq.SupportsKraus` and `cirq.SupportsMeasurementKey` This simulator supports four types of simulation.