Skip to content

Commit

Permalink
Replace existing calls of SupportsChannel to SupportsKraus (#4438)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtomole authored Aug 18, 2021
1 parent 5ee2288 commit aa8184c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cirq-core/cirq/qis/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cirq-core/cirq/qis/channels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/qis/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion cirq-core/cirq/sim/act_on_density_matrix_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/sim/density_matrix_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/sim/sparse_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit aa8184c

Please sign in to comment.