microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/pip/qsharp/noisy_simulator/_noisy_simulator.pyi
241lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # Licensed under the MIT License. |
| 3 | |
| 4 | from typing import Optional, List, Any |
| 5 | |
| 6 | class NoisySimulatorError(BaseException): |
| 7 | """ |
| 8 | EXPERIMENTAL: |
| 9 | |
| 10 | An error returned from the Q# noisy simulator. |
| 11 | """ |
| 12 | |
| 13 | ... |
| 14 | |
| 15 | class Operation: |
| 16 | """ |
| 17 | EXPERIMENTAL: |
| 18 | |
| 19 | This struct represents a quantum operation. A quantum operation is a linear |
| 20 | transformation that maps a valid density matrix to another valid density matrices. |
| 21 | """ |
| 22 | |
| 23 | def __init__(self, kraus_operators: Any) -> None: |
| 24 | """ |
| 25 | Construct an operation from a list of Kraus operators. |
| 26 | Matrices must be of dimension 2^k x 2^k, where k is an integer. |
| 27 | Raises a `NoisySimulatorError` if the Kraus matrices are ill formed. |
| 28 | |
| 29 | Input: |
| 30 | kraus_operators: List[List[List[complex]]], can be a Python list or a numpy array. |
| 31 | """ |
| 32 | ... |
| 33 | |
| 34 | def get_effect_matrix(self) -> List[List[complex]]: |
| 35 | """ |
| 36 | Returns effect matrix: |
| 37 | $$ (\sum_i K_i^{\dagger} K_i) $$ |
| 38 | where $K_i$ are Kraus operators. |
| 39 | """ |
| 40 | ... |
| 41 | |
| 42 | def get_operation_matrix(self) -> List[List[complex]]: |
| 43 | """ |
| 44 | Return matrix representation: |
| 45 | $$ \sum_i K_i \otimes K_{i}* $$ |
| 46 | where $K_i$ are Kraus operators. |
| 47 | """ |
| 48 | ... |
| 49 | |
| 50 | def get_kraus_operators(self) -> List[List[List[complex]]]: |
| 51 | """ |
| 52 | Return list of Kraus operators. |
| 53 | """ |
| 54 | ... |
| 55 | |
| 56 | def get_number_of_qubits(self) -> int: |
| 57 | """ |
| 58 | Return the number of qubits that the operation acts on. |
| 59 | """ |
| 60 | |
| 61 | class Instrument: |
| 62 | """ |
| 63 | EXPERIMENTAL: |
| 64 | |
| 65 | An instrument is the means by which we make measurements on a quantum system. |
| 66 | """ |
| 67 | |
| 68 | def __init__(self, operations: List[Operation]) -> None: |
| 69 | """ |
| 70 | Constructs an instrument from a list of operations. |
| 71 | """ |
| 72 | ... |
| 73 | |
| 74 | class DensityMatrix: |
| 75 | """ |
| 76 | EXPERIMENTAL: |
| 77 | |
| 78 | A square complex matrix of size 2^k x 2^k representing the state |
| 79 | of a quantum system. The data is stored in a linear vector for |
| 80 | performance reasons. |
| 81 | """ |
| 82 | |
| 83 | def data(self) -> List[List[complex]]: |
| 84 | """ |
| 85 | Returns a copy of the matrix data. |
| 86 | """ |
| 87 | ... |
| 88 | |
| 89 | def dimension(self) -> int: |
| 90 | """ |
| 91 | Returns the dimension of the matrix. E.g.: if the matrix is |
| 92 | 5 x 5, it returns 5. |
| 93 | """ |
| 94 | ... |
| 95 | |
| 96 | def number_of_qubits(self) -> int: |
| 97 | """ |
| 98 | Returns the number of qubits in the system. |
| 99 | """ |
| 100 | ... |
| 101 | |
| 102 | class DensityMatrixSimulator: |
| 103 | """ |
| 104 | EXPERIMENTAL: |
| 105 | |
| 106 | A quantum circuit simulator using a density matrix. |
| 107 | |
| 108 | If the simulator reaches an invalid state due to a numerical |
| 109 | error, it will raise a `SimulatorException`. |
| 110 | """ |
| 111 | |
| 112 | def __init__(self, number_of_qubits: int, seed: Optional[int]) -> None: |
| 113 | """ |
| 114 | Creates a new `DensityMatrixSimulator`. |
| 115 | """ |
| 116 | ... |
| 117 | |
| 118 | def apply_operation(self, operation: Operation, qubits: List[int]) -> None: |
| 119 | """ |
| 120 | Apply an operation to the given qubit ids. |
| 121 | """ |
| 122 | ... |
| 123 | |
| 124 | def apply_instrument(self, instrument: Instrument, qubits: List[int]) -> None: |
| 125 | """ |
| 126 | Apply non selective evolution to the given qubit ids. |
| 127 | """ |
| 128 | ... |
| 129 | |
| 130 | def sample_instrument(self, instrument: Instrument, qubits: List[int]) -> int: |
| 131 | """ |
| 132 | Performs selective evolution under the given instrument. |
| 133 | Returns the index of the observed outcome. |
| 134 | |
| 135 | Use this method to perform measurements on the quantum system. |
| 136 | """ |
| 137 | |
| 138 | def get_state(self) -> Optional[DensityMatrix]: |
| 139 | """ |
| 140 | Returns the `DensityMatrix` if the simulator is in a valid state, |
| 141 | otherwise returns None. |
| 142 | """ |
| 143 | ... |
| 144 | |
| 145 | def set_state(self, state: DensityMatrix) -> None: |
| 146 | """ |
| 147 | Set state of the quantum system to another `DensityMatrix` of the |
| 148 | same dimensions. |
| 149 | """ |
| 150 | ... |
| 151 | |
| 152 | def set_trace(self, trace: float) -> None: |
| 153 | """ |
| 154 | Set trace of the quantum system. That is, the probability of |
| 155 | finding the quantum system in the current state. The new trace |
| 156 | must be a number between 0 and 1. |
| 157 | """ |
| 158 | ... |
| 159 | |
| 160 | class StateVector: |
| 161 | """ |
| 162 | EXPERIMENTAL: |
| 163 | |
| 164 | A vector representing a pure state of a quantum system. |
| 165 | """ |
| 166 | |
| 167 | def data(self) -> List[complex]: |
| 168 | """ |
| 169 | Returns a copy of the vector data. |
| 170 | """ |
| 171 | ... |
| 172 | |
| 173 | def dimension(self) -> int: |
| 174 | """ |
| 175 | Returns the dimension of the vector. |
| 176 | """ |
| 177 | ... |
| 178 | |
| 179 | def number_of_qubits(self) -> int: |
| 180 | """ |
| 181 | Returns the number of qubits in the system. |
| 182 | """ |
| 183 | ... |
| 184 | |
| 185 | class StateVectorSimulator: |
| 186 | """ |
| 187 | EXPERIMENTAL: |
| 188 | |
| 189 | A quantum circuit simulator using a density matrix. |
| 190 | |
| 191 | If the simulator reaches an invalid state due to a numerical |
| 192 | error, it will raise a `SimulatorException`. |
| 193 | """ |
| 194 | |
| 195 | def __init__(self, number_of_qubits: int, seed: Optional[int]) -> None: |
| 196 | """ |
| 197 | Creates a new `DensityMatrixSimulator`. |
| 198 | """ |
| 199 | ... |
| 200 | |
| 201 | def apply_operation(self, operation: Operation, qubits: List[int]) -> None: |
| 202 | """ |
| 203 | Apply an operation to the given qubit ids. |
| 204 | """ |
| 205 | ... |
| 206 | |
| 207 | def apply_instrument(self, instrument: Instrument, qubits: List[int]) -> None: |
| 208 | """ |
| 209 | Apply non selective evolution to the given qubit ids. |
| 210 | """ |
| 211 | ... |
| 212 | |
| 213 | def sample_instrument(self, instrument: Instrument, qubits: List[int]) -> int: |
| 214 | """ |
| 215 | Performs selective evolution under the given instrument. |
| 216 | Returns the index of the observed outcome. |
| 217 | |
| 218 | Use this method to perform measurements on the quantum system. |
| 219 | """ |
| 220 | |
| 221 | def get_state(self) -> Optional[StateVector]: |
| 222 | """ |
| 223 | Returns the `StateVector` if the simulator is in a valid state, |
| 224 | otherwise returns None. |
| 225 | """ |
| 226 | ... |
| 227 | |
| 228 | def set_state(self, state: StateVector) -> None: |
| 229 | """ |
| 230 | Set state of the quantum system to another `StateVector` of the |
| 231 | same dimensions. |
| 232 | """ |
| 233 | ... |
| 234 | |
| 235 | def set_trace(self, trace: float) -> None: |
| 236 | """ |
| 237 | Set trace of the quantum system. That is, the probability of |
| 238 | finding the quantum system in the current state. The new trace |
| 239 | must be a number between 0 and 1. |
| 240 | """ |
| 241 | ... |