References
Ansaetze#
from qml_essentials.ansaetze import Ansaetze
Source code in qml_essentials/ansaetze.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
Circuit_1
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
build(w, n_qubits)
staticmethod
#
Creates a Circuit1 ansatz.
Length of flattened vector must be n_qubits*2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits2) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
Circuit_15
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
build(w, n_qubits)
staticmethod
#
Creates a Circuit15 ansatz.
Length of flattened vector must be n_qubits*3-1 because for >1 qubits there are three gates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3-1) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
Circuit_18
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
build(w, n_qubits)
staticmethod
#
Creates a Circuit18 ansatz.
Length of flattened vector must be n_qubits*3-1 because for >1 qubits there are three gates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3-1) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
Circuit_19
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
build(w, n_qubits)
staticmethod
#
Creates a Circuit19 ansatz.
Length of flattened vector must be n_qubits*3-1 because for >1 qubits there are three gates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3-1) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
Circuit_9
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
build(w, n_qubits)
staticmethod
#
Creates a Circuit19 ansatz.
Length of flattened vector must be n_qubits*3-1 because for >1 qubits there are three gates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3-1) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
Hardware_Efficient
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
build(w, n_qubits)
staticmethod
#
Creates a Circuit19 ansatz.
Length of flattened vector must be n_qubits*3-1 because for >1 qubits there are three gates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3-1) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
No_Entangling
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
build(w, n_qubits)
staticmethod
#
Creates a circuit without entangling, but with U3 gates on all qubits
Length of flattened vector must be n_qubits*3
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
Strongly_Entangling
#
Bases: Circuit
Source code in qml_essentials/ansaetze.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
build(w, n_qubits)
staticmethod
#
Creates a StronglyEntanglingLayers ansatz.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
w |
ndarray
|
weight vector of size n_layers(n_qubits3) |
required |
n_qubits |
int
|
number of qubits |
required |
Source code in qml_essentials/ansaetze.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
Model#
from qml_essentials.model import Model
A quantum circuit model.
Source code in qml_essentials/model.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
execution_type: str
property
writable
#
Gets the execution type of the model.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The execution type, one of 'density', 'expval', or 'probs'. |
noise_params: Optional[Dict[str, float]]
property
writable
#
Gets the noise parameters of the model.
Returns:
Type | Description |
---|---|
Optional[Dict[str, float]]
|
Optional[Dict[str, float]]: A dictionary of noise parameters or None if not set. |
shots: Optional[int]
property
writable
#
Gets the number of shots to use for the quantum device.
Returns:
Type | Description |
---|---|
Optional[int]
|
Optional[int]: The number of shots. |
__call__(params, inputs, noise_params=None, cache=False, execution_type=None)
#
Perform a forward pass of the quantum circuit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
Weight vector of shape [n_layers, n_qubits*n_params_per_layer]. |
required |
inputs |
ndarray
|
Input vector of shape [1]. |
required |
noise_params |
Optional[Dict[str, float]]
|
The noise parameters. Defaults to None which results in the last set noise parameters being used. |
None
|
cache |
Optional[bool]
|
Whether to cache the results. Defaults to False. |
False
|
execution_type |
str
|
The type of execution. Must be one of 'expval', 'density', or 'probs'. Defaults to None which results in the last set execution type being used. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The output of the quantum circuit. The shape depends on the execution_type. - If execution_type is 'expval', returns an ndarray of shape (1,) if output_qubit is -1, else (len(output_qubit),). - If execution_type is 'density', returns an ndarray of shape (2n_qubits, 2n_qubits). - If execution_type is 'probs', returns an ndarray of shape (2n_qubits,) if output_qubit is -1, else (2len(output_qubit),). |
Source code in qml_essentials/model.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
__init__(n_qubits, n_layers, circuit_type, data_reupload=True, initialization='random', output_qubit=0, shots=None, random_seed=1000)
#
Initialize the quantum circuit model. Parameters will have the shape [impl_n_layers, parameters_per_layer] where impl_n_layers is the number of layers provided and added by one depending if data_reupload is True and parameters_per_layer is given by the chosen ansatz.
The model is initialized with the following parameters as defaults: - noise_params: None - execution_type: "expval" - shots: None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_qubits |
int
|
The number of qubits in the circuit. |
required |
n_layers |
int
|
The number of layers in the circuit. |
required |
circuit_type |
str
|
The type of quantum circuit to use. If None, defaults to "no_ansatz". |
required |
data_reupload |
bool
|
Whether to reupload data to the quantum device on each measurement. Defaults to True. |
True
|
initialization |
str
|
The strategy to initialize the parameters. Can be "random", "zeros", "zero-controlled", "pi", or "pi-controlled". Defaults to "random". |
'random'
|
output_qubit |
(List[int], int)
|
The index of the output qubit (or qubits). When set to -1 all qubits are measured, or a global measurement is conducted, depending on the execution type. |
0
|
shots |
Optional[int]
|
The number of shots to use for the quantum device. Defaults to None. |
None
|
random_seed |
int
|
seed for the random number generator in initialization is "random", Defaults to 1000. |
1000
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in qml_essentials/model.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
Entanglement#
from qml_essentials.entanglement import Entanglement
Source code in qml_essentials/entanglement.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
meyer_wallach(model, n_samples, seed, **kwargs)
staticmethod
#
Calculates the entangling capacity of a given quantum circuit using Meyer-Wallach measure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Callable
|
Function that models the quantum circuit. It must
have a |
required |
n_samples |
int
|
Number of samples per qubit. |
required |
seed |
Optional[int]
|
Seed for the random number generator. |
required |
kwargs |
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Entangling capacity of the given circuit. It is guaranteed to be between 0.0 and 1.0. |
Source code in qml_essentials/entanglement.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
Expressibility#
from qml_essentials.expressibility import Expressibility
Source code in qml_essentials/expressibility.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
haar_integral(n_qubits, n_bins, cache=True)
staticmethod
#
Calculates theoretical probability density function for random Haar states as proposed by Sim et al. (https://arxiv.org/abs/1905.10876) and bins it into a 3D-histogram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_qubits |
int
|
number of qubits in the quantum system |
required |
n_bins |
int
|
number of histogram bins |
required |
cache |
bool
|
whether to cache the haar integral |
True
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: - x component (bins): the input domain - y component (probabilities): the haar probability density funtion for random Haar states |
Source code in qml_essentials/expressibility.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
kullback_leibler_divergence(vqc_prob_dist, haar_dist)
staticmethod
#
Calculates the KL divergence between two probability distributions (Haar probability distribution and the fidelity distribution sampled from a VQC).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vqc_prob_dist |
ndarray
|
VQC fidelity probability distribution. Should have shape (n_inputs_samples, n_bins) |
required |
haar_dist |
ndarray
|
Haar probability distribution with shape. Should have shape (n_bins, ) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of KL-Divergence values for all values in axis 1 |
Source code in qml_essentials/expressibility.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
state_fidelities(n_bins, n_samples, n_input_samples, seed, model, **kwargs)
staticmethod
#
Sample the state fidelities and histogram them into a 2D array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_bins |
int
|
Number of histogram bins. |
required |
n_samples |
int
|
Number of parameter sets to generate. |
required |
n_input_samples |
int
|
Number of samples for the input domain in [-pi, pi] |
required |
seed |
int
|
Random number generator seed. |
required |
model |
Callable
|
|
required |
kwargs |
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: Tuple containing the input samples, bin edges, and histogram values. |
Source code in qml_essentials/expressibility.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
Coefficients#
from qml_essentials.coefficients import Coefficients
Source code in qml_essentials/coefficients.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
sample_coefficients(model)
#
Sample the Fourier coefficients of a given model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Model
|
The model to sample. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The sampled Fourier coefficients. |
Source code in qml_essentials/coefficients.py
9 10 11 12 13 14 15 16 17 18 19 20 |
|