Simulator¶
tn
¶
Simulator
dataclass
¶
Simulator for quantum circuits, providing callable methods for computing forward, backward, and Fisher Information matrix calculations on the quantum amplitudes and classical probabilities, given a set of parameters PyTrees
Attributes:
| Name | Type | Description |
|---|---|---|
amplitudes |
SimulatorQuantumAmplitudes
|
Object for quantum amplitudes computations. |
probabilities |
SimulatorClassicalProbabilities
|
Object for classical probabilities computations. |
path |
Any
|
Path to the simulator, can be used for saving/loading. |
info |
str
|
Additional information about the simulator. |
Source code in src/squint/simulator/tn.py
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 | |
compile(static: PyTree, *params, **kwargs)
classmethod
¶
Compiles the circuit into a tensor contraction function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
static
|
PyTree
|
The static PyTree, following the |
required |
#
|
dim (int
|
The dimension of the local Hilbert space (the same dimension across all wires). |
required |
params
|
Sequence[PyTree]
|
The parameterized PyTree, following the |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
sim |
Simulator
|
A class which contains methods for computing the parameterized forward, grad, and Fisher information functions. |
Source code in src/squint/simulator/tn.py
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 | |
jit(device: jax.Device = None)
¶
JIT (just-in-time) compile the simulator methods. Args: device (jax.Device, optional): Device to compile the methods on. Defaults to None, which uses the first available device.
Source code in src/squint/simulator/tn.py
sample(key: jr.PRNGKey, params: PyTree, shape: tuple[int, ...])
¶
Sample from the quantum circuit using the provided parameters and a random key.
Args:
key (jr.PRNGKey): Random key for sampling.
params (PyTree): Parameters for the quantum circuit, partitioned via eqx.partition.
shape (tuple[int, ...]): Shape of the output samples.
Returns:
samples (jnp.ndarray): Samples drawn from the quantum circuit.
Source code in src/squint/simulator/tn.py
PureBackend
¶
Bases: AbstractBackend
Source code in src/squint/simulator/tn.py
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 | |
subscripts(obj: Union[Circuit, Block]) -> str
staticmethod
¶
Generate einsum subscript string for pure state tensor network contraction.
Iterates through all operations in the circuit/block and assigns unique character indices to each tensor leg. Input and output indices are tracked per wire to construct the full einsum expression for contracting the tensor network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Union[Circuit, Block]
|
A Circuit or Block containing quantum operations. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
An einsum subscript string in the format "input1,input2,...->output" suitable for use with jnp.einsum. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a gate is applied to a wire before a state is initialized. |
TypeError
|
If an unknown operation type is encountered. |
Source code in src/squint/simulator/tn.py
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 | |
MixedBackend
¶
Bases: AbstractBackend
Source code in src/squint/simulator/tn.py
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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
subscripts(obj: Union[Circuit, Block]) -> str
staticmethod
¶
Assigns the indices for all tensor legs when the circuit is includes mixed states, channels, and non-unitary evolution.
The canonical ordering of indices is (input_indices, output_indices)
Source code in src/squint/simulator/tn.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
SimulatorQuantumAmplitudes
dataclass
¶
Simulator object which computes quantities related to the quantum probability amplitudes, including forward pass, gradient computation, and quantum Fisher information matrix calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
forward |
Callable
|
Function to compute quantum amplitudes. |
grad |
Callable
|
Function to compute gradients of quantum amplitudes. |
qfim |
Callable
|
Function to compute the quantum Fisher information matrix. |
Source code in src/squint/simulator/tn.py
jit(device: jax.Device = None)
¶
JIT (just-in-time) compile the simulator methods. Args: device (jax.Device, optional): Device to compile the methods on. Defaults to None, which uses the first available device.
Source code in src/squint/simulator/tn.py
SimulatorClassicalProbabilities
dataclass
¶
Simulator object which computes quantities related to the classical probabilities, including forward pass, gradient computation, and classical Fisher information matrix calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
forward |
Callable
|
Function to compute classical probabilities. |
grad |
Callable
|
Function to compute gradients of classical probabilities. |
cfim |
Callable
|
Function to compute the classical Fisher information matrix. |
Source code in src/squint/simulator/tn.py
jit(device: jax.Device = None)
¶
JIT (just-in-time) compile the simulator methods. Args: device (jax.Device, optional): Device to compile the methods on. Defaults to None, which uses the first available device.
Source code in src/squint/simulator/tn.py
verify(self)
¶
Performs a verification check on the circuit object to ensure it is valid prior to being compiled.
Source code in src/squint/simulator/tn.py
quantum_fisher_information_matrix(_forward_amplitudes: Callable, _grad_amplitudes: Callable, *params: PyTree)
¶
Performs the forward pass to compute quantum amplitudes and their gradients,
and then calculates the quantum Fisher information matrix.
Args:
_forward_amplitudes (Callable): Function to compute quantum amplitudes.
_grad_amplitudes (Callable): Function to compute gradients of quantum amplitudes.
*params (list[PyTree]): Parameters for the quantum circuit, partitioned via eqx.partition.
The argnum is already defined in the callables
Returns:
qfim (jnp.ndarray): Quantum Fisher information matrix.
Source code in src/squint/simulator/tn.py
classical_fisher_information_matrix(_forward_prob: Callable, _grad_prob: Callable, *params: PyTree)
¶
Performs the forward pass to compute classical probabilities and their gradients,
and then calculates the classical Fisher information matrix.
Args:
_forward_prob (Callable): Function to compute classical probabilities.
_grad_prob (Callable): Function to compute gradients of classical probabilities.
*params (list[PyTree]): Parameters for the quantum circuit, partitioned via eqx.partition.
The argnum is already defined in the callables
Returns:
cfim (jnp.ndarray): Classical Fisher information matrix.