braket.default_simulator.linalg_utils module

braket.default_simulator.linalg_utils.multiply_matrix(state: ndarray, matrix: ndarray, targets: tuple[int, ...], controls: tuple[int, ...] | None = (), control_state: tuple[int, ...] | None = ()) ndarray[source]

Multiplies the given matrix by the given state, applying the matrix on the target qubits, controlling the operation as specified.

Parameters:
  • state (np.ndarray) – The state to multiply the matrix by.

  • matrix (np.ndarray) – The matrix to apply to the state.

  • targets (tuple[int]) – The qubits to apply the state on.

  • controls (Optional[tuple[int]]) – The qubits to control the operation on. Default ().

  • control_state (Optional[tuple[int]]) – A tuple of same length as controls with either a 0 or 1 in each index, corresponding to whether to control on the |0⟩ or |1⟩ state. Default (1,) * len(controls).

Returns:

np.ndarray – The state after the matrix has been applied.

braket.default_simulator.linalg_utils.marginal_probability(probabilities: ndarray, targets: Sequence[int] | None = None) ndarray[source]

Return the marginal probability of the computational basis states.

The marginal probability is obtained by summing the probabilities on the unused qubits. If no targets are specified, then the probability of all basis states is returned.

Parameters:
  • probabilities (np.ndarray) – The probability distribution to marginalize.

  • targets (list[int]) – The qubits of the marginal distribution; if no targets are specified, then the probability of all basis states is returned.

Returns:

np.ndarray – The marginal probability distribution.

braket.default_simulator.linalg_utils.partial_trace(density_matrix: ndarray, targets: list[int] | None = None) ndarray[source]

Returns the reduced density matrix for the target qubits.

If no target qubits are supplied, this method returns the trace of the density matrix.

Parameters:
  • density_matrix (np.ndarray) – The density matrix to reduce, as a tensor product of qubit states.

  • targets (list[int]) – The qubits of the output reduced density matrix; if no target qubits are supplied, this method returns the trace of the density matrix.

Returns:

np.ndarray – The partial trace of the density matrix.