qpnn
The quotonic.qpnn module includes classes that contain different models of quantum photonic neural networks (QPNNs),
each designed to explore different capabilities in detail. QPNN serves as a template for these models and thus
includes attributes that are relevant to all. The other classes inherit QPNN and build from it, yet remain
organized similarly to each other in many ways, as will be discussed further below.
QPNNs are brain-inspired, nonlinear photonic circuits that have been predicted to near-deterministically (i.e. with near 100% success rates) generate, and process, quantum entanglement. Driven with light, these networks leverage the multiplexing, low latency, and ultra-low operational powers of mature photonic integrated circuits similarly to their classical counterparts. By adding optical nonlinearities to the processing toolkit, QPNNs feature components that not only induce the necessary photon-photon interactions for efficient processing, but also act analogous to the activation (i.e. learning) function of conventional neural networks, allowing QPNNs to be trained to perform specified input-output mappings between quantum photonic states. Building on this operating principle, QPNNs have been considered for conducting quantum simulation, accelerating quantum state tomography, and even speeding up more common machine learning tasks like image recognition or natural language processing.
As displayed in the exemplary four-mode, two-layer network shown below, each QPNN is constructed from \(m\) optical modes and \(L\) layers, where each layer is realized by a linear, rectangular \(m\times m\) Mach-Zehnder inteferometer (MZI) mesh. By selecting the two controllable phase shifters \((\phi, \theta)\) in each MZI, each layer can be programmed to perform any arbitrary linear unitary transformation \(\mathbf{U}\) on the optical modes of the photons (see clements for more details). Single-site few-photon optical nonlinearities \(\Sigma(\varphi)\), of effective nonlinear phase shift \(\varphi\) (ideally \(\pi\), see nl for more details), are placed between consecutive layers. These elements are key to network operation as they provide the learning capabilities to the neural network and allow it to realize near-deterministic entangling operations.
By simply piecing all the sections of the network together, a QPNN can be described by the transfer function,
where each \(\boldsymbol{\phi}_L, \boldsymbol{\theta}_L\) are vectors that contain all the \(\phi, \theta\) phase shifts in each MZI for the \(i^\text{th}\) layer. This transfer function will act on the \(k^\text{th}\) input state \(\left|\mathrm{in}\right\rangle_k\) to produce an output state \(\left|\mathrm{out}\right\rangle_k = \mathbf{ S}\left|\mathrm{in}\right\rangle_k\). Comparing the output with the target state \(\left|\mathrm{ targ}\right\rangle_k\), (i.e. according to a truth table), the unconditional fidelity (or equivalently the success rate) for the \(k^\text{th}\) input-target pair is given by
which describes the chance that the network produces the targeted output state for any given input state without conditions. To train the QPNN, an optimization algorithm maximizes the unconditional fidelity (or equivalently minimizes the cost/network error \(\mathcal{C}^{(\mathrm{unc})} = 1 - \mathcal{F}^{(\mathrm{unc})}\)) using the variational phase shift parameters from its \(L\) layers (see trainer for more details on training).
Alternatively, the success of a QPNN operation may be conditioned on the detection of a logical output, that is, one where the photons are detected in a combination of output modes that corresponds to the qubit encoding scheme. In the image above, dual-rail encoding for the photonic qubits is considered such that a logical output is one where a single photon is detected in one of the upper two modes while the other is detected in one of the bottom two modes. This measure is termed the conditional fidelity (or equivalently just fidelity) \(\mathcal{F}_k^{(\mathrm{con})}\), each \(k^\text{th}\) term of which can be multiplied by the corresponding probability that the network produces a logical output in the computational basis \(\mathcal{P}_k^{(\mathrm{cb})}\) (or equivalently logical rate),
to retrieve the \(k^\text{th}\) term of the unconditional fidelity.
With this background in mind, the structure of the classes for each QPNN model can be described more clearly. Upon
instantiation, each model prepares all pieces of the network architecture, from the linear layers to the nonlinear
sections, though the specific way that these components are prepared may differ slightly between models. Each class
has a property called training_set that can be used to set and retrieve a training set for an instantiated QPNN.
They also include a method called build to construct the system function \(\mathbf{S}\) in full. With the system
function and a training set, the aforementioned performance measures can be calculated, and these calculations tend
to make up the remainder of the class methods. All of these properties and methods differ slightly between models
which is why they are not written into the base class QPNN itself. If you decide to use quotonic to perform
research on QPNNs, feel free to develop your own model and a corresponding class to go with it. That is essentially
the best way to use this part of the package from a research standpoint. Also, we'd be happy to add it if it fits the
format appropriately, so please reach out!
QPNN
¶
Base class for a quantum photonic neural network (QPNN).
This is effectively a template that prepares the most fundamental attributes for any QPNN. Each QPNN is designed to operate on a certain number of photons, \(n\) with a certain number of optical modes \(m\), and features \(L\) layers.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
number of photons, \(n\) |
m |
int
|
number of optical modes, \(m\) |
L |
int
|
number of layers, \(L\) |
N |
int
|
dimension of the relevant Fock basis for \(n\) photons and \(m\) optical modes |
Source code in src/quotonic/qpnn.py
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 | |
__init__(n, m, L, basis_type='secq')
¶
Initialization of a QPNN instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
number of photons, \(n\) |
required |
m
|
int
|
number of optical modes, \(m\) |
required |
L
|
int
|
number of layers, \(L\) |
required |
basis_type
|
str
|
specifies whether the QPNN is resolved in the first or second-quantized basis |
'secq'
|
Source code in src/quotonic/qpnn.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
IdealQPNN
¶
Bases: QPNN
Class for an idealized QPNN based on single-site Kerr-like nonlinearities.
Here, the QPNN is modelled as it was originally proposed in G. R. Steinbrecher et al., “Quantum optical neural networks”, npj Quantum Inf 5, 60 (2019). Linear layers are spatial meshes of Mach-Zehnder interferometers, and the single-site nonlinearities are based on the optical Kerr effect. A provided truth table defines the training set.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
number of photons, \(n\) |
m |
int
|
number of optical modes, \(m\) |
L |
int
|
number of layers, \(L\) |
N |
int
|
dimension of the second quantization Fock basis for \(n\) photons and \(m\) optical modes |
mesh |
Mesh
|
object containing methods that allow linear layers (i.e. rectangular Mach-Zehnder interferometer meshes) to be encoded |
transformer |
SecqTransformer
|
object containing methods that compute multi-photon unitary transformations of the linear layers |
varphi |
float
|
effective nonlinear phase shift, \(\varphi\) |
kerr |
jnp_ndarray
|
\(N\times N\) array, the matrix representation of the set of single-site Kerr-like nonlinearities resolved in the second quantization Fock basis |
K |
int
|
number of input-target state pairs in the QPNN training set, defaults to 0 if none provided |
psi_in |
jnp_ndarray
|
\(K\times N\) array containing the \(K\) input states in the QPNN training set, resolved in the \(N\)-dimensional second quantization Fock basis, defaults to an empty array if none provided |
psi_targ |
jnp_ndarray
|
\(K\times N\) array containing the \(K\) target states in the QPNN training set, resolved in the \(N\)-dimensional second quantization Fock basis, defaults to an empty array if none provided |
Source code in src/quotonic/qpnn.py
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 | |
__init__(n, m, L, varphi=np.pi, training_set=None)
¶
Initialization of an Ideal QPNN instance.
Each piece of the QPNN architecture is instantiated and stored as an attribute alongside relevant parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
number of photons, \(n\) |
required |
m
|
int
|
number of optical modes, \(m\) |
required |
L
|
int
|
number of layers, \(L\) |
required |
varphi
|
float
|
effective nonlinear phase shift, \(\varphi\) |
pi
|
training_set
|
tuple | None
|
a tuple including two \(K\times N\) arrays, the first of which contains \(K\) input states resolved in the second quantization Fock basis, the second of which contains the corresponding target states |
None
|
Source code in src/quotonic/qpnn.py
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 | |
training_set
property
writable
¶
Training set of the QPNN.
Returns:
| Name | Type | Description |
|---|---|---|
psi_in |
np_ndarray
|
\(K\times N\) array containing the \(K\) input states resolved in the second quantization Fock basis |
psi_targ |
np_ndarray
|
\(K\times N\) array containing the \(K\) target states resolved in the second quantization Fock basis |
build(phi, theta, delta)
¶
Build a matrix representation of the QPNN from all its layers and components.
This method calculates the system function of the QPNN as introduced at the top of this module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
jnp_ndarray
|
\(N\times N\) array, the matrix representation of the QPNN resolved in the second quantization Fock basis |
Source code in src/quotonic/qpnn.py
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 | |
calc_fidelity(phi, theta, delta)
¶
Calculate the fidelity of the QPNN.
This method calculates the fidelity of the QPNN as introduced at the top of this module. In this idealized model, the logical rate is always unity. Therefore, the unconditional and conditional fidelities are equivalent. This method relies on a training set and will thus throw an error if one has not been provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
F |
DTypeLike
|
fidelity of the QPNN |
Source code in src/quotonic/qpnn.py
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 | |
ImperfectQPNN
¶
Bases: QPNN
Class for experimental modelling of QPNNs based on single-site Kerr-like nonlinearities.
Here, we add relevant experimental imperfections to the QPNN model including non-uniform photon loss and
imbalanced routing caused by non-ideal directional coupler splitting ratios. This model corresponds to that
presented in J. Ewaniuk et al., “Imperfect Quantum Photonic Neural Networks”, Adv Quantum Technol. 6,
2200125 (2023). As in IdealQPNN, a provided truth table defines the
training set.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
number of photons, \(n\) |
m |
int
|
number of optical modes, \(m\) |
L |
int
|
number of layers, \(L\) |
N |
int
|
dimension of the second quantization Fock basis for \(n\) photons and \(m\) optical modes |
meshes |
tuple
|
tuple of \(L\) objects containing methods that allow each linear layer (i.e. rectangular Mach-Zehnder interferometer meshes) to be encoded |
ell_mzi |
tuple
|
nominal loss for a Mach-Zehnder interferometer in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual interferometer is selected |
ell_ps |
tuple
|
nominal loss for a phase shifter in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual output phase shifter is selected |
t_dc |
tuple
|
directional coupler splitting ratios (T:R) as decimal values, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual nominally 50:50 coupler is selected |
transformer |
SecqTransformer
|
object containing methods that compute multi-photon unitary transformations of the linear layers |
varphi |
float
|
effective nonlinear phase shift, \(\varphi\) |
nl |
jnp_ndarray
|
\(N\times N\) array, the matrix representation of a set of single-site Kerr-like nonlinearities resolved in the second quantization Fock basis |
K |
int
|
number of input-target state pairs in the QPNN training set, defaults to 0 if none provided |
psi_in |
jnp_ndarray
|
\(K\times N\) array containing the \(K\) input states in the QPNN training set, resolved in the \(N\)-dimensional second quantization Fock basis, defaults to an empty array if none provided |
psi_targ |
jnp_ndarray
|
\(K\times N\) array containing the \(K\) target states in the QPNN training set, resolved in the \(N\)-dimensional second quantization Fock basis, defaults to an empty array if none provided |
comp_indices |
jnp_ndarray
|
\(2^n\)-length array whose elements are the indices of the second quantization Fock basis where dual-rail encoded computational basis states lie |
Source code in src/quotonic/qpnn.py
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 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 592 593 594 595 596 597 | |
__init__(n, m, L, varphi=np.pi, ell_mzi=(0.0, 0.0), ell_ps=(0.0, 0.0), t_dc=(0.5, 0.0), training_set=None)
¶
Initialization of an Imperfect QPNN instance.
Each piece of the QPNN architecture is instantiated and stored as an attribute alongside relevant parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
number of photons, \(n\) |
required |
m
|
int
|
number of optical modes, \(m\) |
required |
L
|
int
|
number of layers, \(L\) |
required |
varphi
|
float
|
effective nonlinear phase shift, \(\varphi\) |
pi
|
ell_mzi
|
tuple
|
nominal loss for a Mach-Zehnder interferometer in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual interferometer is selected |
(0.0, 0.0)
|
ell_ps
|
tuple
|
nominal loss for a phase shifter in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual output phase shifter is selected |
(0.0, 0.0)
|
t_dc
|
tuple
|
directional coupler splitting ratios (T:R) as decimal values, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual nominally 50:50 coupler is selected |
(0.5, 0.0)
|
training_set
|
tuple | None
|
a tuple including two \(K\times N\) arrays, the first of which contains \(K\) input states resolved in the second quantization Fock basis, the second of which contains the corresponding target states |
None
|
Source code in src/quotonic/qpnn.py
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 | |
training_set
property
writable
¶
Training set of the QPNN.
Returns:
| Name | Type | Description |
|---|---|---|
psi_in |
np_ndarray
|
\(K\times N\) array containing the \(K\) input states resolved in the second quantization Fock basis |
psi_targ |
np_ndarray
|
\(K\times N\) array containing the \(K\) target states resolved in the second quantization Fock basis |
imperfections
property
writable
¶
Component-level imperfection values for each interferometer mesh in the QPNN.
Realistic MZI meshes are modelled by allowing each individual interferometer to suffer unique imperfections,
resulting in unbalanced, photon-path-dependent errors. The transmittance of each directional coupler is
randomly selected from a normal distribution with a mean and a standard deviation as defined by attribute
t_dc. Similarly, the photon losses introduced by each MZI and each output phase shifter in each mesh are
selected from normal distributions as well, with means and standard deviations defined by attributes
ell_mzi and ell_ps, respectively. The transmittance attribute is a decimal value between 0 and 1 (e.g.
0.5 corresponds to 50% transmission). Conversely, the loss attributes are provided as a positive dB value,
and thus must be converted to a decimal value between 0 and 1 that defines the fraction of light lost. For
some positive-valued dB loss \(\ell_\mathrm{dB}\), this fraction is given by
From the standard deviation of the dB loss \(\sigma_\mathrm{dB}\), the standard deviation of the fractional loss is given by
When setting this property, you can provide a tuple with elements including arrays of the MZI losses,
phase shifter losses, and directional coupler transmissivities, respectively (all as decimal values).
Alternatively, you can pass quotonic.qpnn.DEFAULT = None to instruct the function to sample imperfection
values from the distributions defined by the internal attributes.
Returns:
| Name | Type | Description |
|---|---|---|
ells_mzi |
np_ndarray
|
\(L\times m\times m\) array containing the fractinal loss per arm of each of the \(L\) interferometer meshes, for each column of MZIs respectively |
ells_ps |
np_ndarray
|
\(L\times m\) array containing the fractional loss for each of the output phase shifters in each of the \(L\) interferometer meshes |
ts_dc |
np_ndarray
|
\(L\times 2\times m(m-1)/2\) array containing the splitting ratio (T:R) of each directional coupler in each of the \(L\) interferometer meshes, organized such that each column corresponds to one MZI, the top row being the first directional coupler and the bottom being the second, where the MZIs are ordered from top to bottom followed by left to right across each mesh |
build(phi, theta, delta)
¶
Build a matrix representation of the QPNN from all its layers and components.
This method calculates the system function of the QPNN as introduced at the top of this module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
jnp_ndarray
|
\(N\times N\) array, the matrix representation of the QPNN resolved in the second quantization Fock basis |
Source code in src/quotonic/qpnn.py
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 | |
calc_unc_fidelity(phi, theta, delta)
¶
Calculate the unconditional fidelity of the QPNN.
This method calculates the unconditional fidelity of the QPNN as introduced at the top of this module. It relies on a training set and will thus throw an error if one has not been provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Func |
DTypeLike
|
unconditional fidelity of the QPNN |
Source code in src/quotonic/qpnn.py
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 | |
calc_performance_measures(phi, theta, delta)
¶
Calculate the unconditional fidelity, conditional fidelity, and logical rate of the QPNN.
This method calculates the unconditional fidelity, conditional fidelity, and logical rate of the QPNN as introduced at the top of this module. It relies on a training set and will thus throw an error if one has not been provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Func |
DTypeLike
|
unconditional fidelity $\mathcal{F}^{(\mathrm{unc})} of the QPNN |
Fcon |
DTypeLike
|
conditinal fidelity $\mathcal{F}^{(\mathrm{con})} of the QPNN |
Pcb |
DTypeLike
|
logical rate $\mathcal{P}^{(\mathrm{cb})} of the QPNN |
Source code in src/quotonic/qpnn.py
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 592 593 594 595 596 597 | |
TreeQPNN
¶
Bases: QPNN
Class for experimental modelling of QPNNs based on three-level system photon subtraction/addition nonlinearities that power a tree-type photonic cluster state generation protocol.
Here, we extend upon the QPNN model further, now incorporating both imperfections as well as the cavity-assisted
three-level system scattering nonlinearity introduced in J. R. Basani et al., "Universal logical quantum
photonic neural network processor via cavity-assisted interactions", npj Quantum Inf 11, 142 (2025). Additionally, this model is specifically designed for compatibility
with the tree-type photonic cluster state generation protocol outlined in J. Ewaniuk et al., "Large-Scale
Tree-Type Photonic Cluster State Generation with Recurrent Quantum Photonic Neural Networks", arXiv:2505.14628
[quant-ph]. As in IdealQPNN, a provided truth table defines the
training set, however, this set is more involved than the previous models. When generating trees, the QPNN must
perform photon-number-dependent operations, responding only to the input photons without active adjustment. As a
result, there are multiple training subsets for different numbers of photons, and more specifically different
tree unit cells that must be formed.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
number of photons, \(n\) |
m |
int
|
number of optical modes, \(m\) |
L |
int
|
number of layers, \(L\) |
b |
int
|
maximum number of branches in the tree, \(b\equiv\max\{\vec{b}\}\) |
N |
int
|
dimension of the second quantization Fock basis for \(n\) photons and \(m\) optical modes |
Ns |
tuple
|
tuple of \(b + 1\) dimensions of the second quantization Fock bases for \(n\) photons and \(m\) optical modes for all \(1 \leq n \leq b + 1\) |
meshes |
tuple
|
tuple of \(L\) objects containing methods that allow each linear layer (i.e. rectangular Mach-Zehnder interferometer meshes) to be encoded |
ell_mzi |
tuple
|
nominal loss for a Mach-Zehnder interferometer in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual interferometer is selected |
ell_ps |
tuple
|
nominal loss for a phase shifter in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual output phase shifter is selected |
t_dc |
tuple
|
directional coupler splitting ratios (T:R) as decimal values, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual nominally 50:50 coupler is selected |
transformers |
tuple
|
tuple of \(b + 1\) objects containing methods that compute multi-photon unitary transformations of the linear layers for all \(1 \leq n \leq b + 1\) |
varphi |
tuple
|
tuple of the phase shifts applied to the subtracted photon, followed by that applied to the remaining photons, for the 3LS photon \(\mp\) nonlinearity, in \(\text{rad}\), \((\varphi_1, \varphi2)\) |
nls |
tuple
|
tuple of \(b + 1\) \(N\times N\) arrays, the \(b + 1\) matrix representations of a set of single-site 3LS photon \(\mp\) nonlinearities resolved in the Fock bases for all \(1 \leq n \leq b + 1\) |
K |
tuple
|
arrays containing the numbers of input-target state pairs in the QPNN training set for each \(1 \leq n \leq b + 1\), per unit cell operation, defaults to a tuple of zeros if none provided |
psi_in |
tuple
|
arrays containing the input states of the QPNN training set, resolved in the \(2^n\)-dimensional computational bases, for each \(1 \leq n \leq b + 1\), defaults to a tuple of empty arrays if none provided |
psi_targ |
tuple
|
arrays containing the target states of the QPNN training set, resolved in the \(2^n\)-dimensional computational bases, for each \(1 \leq n \leq b + 1\), defaults to a tuple of empty arrays if none provided |
comp_indices |
tuple
|
arrays containing the indices of each second quantization Fock basis, for each \(1 \leq n \leq b + 1\), that correspond to each possible unit cell operation, defaults to a tuple of empty arrays if none provided |
Source code in src/quotonic/qpnn.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 | |
__init__(b, L, varphi=(0.0, np.pi), ell_mzi=(0.0, 0.0), ell_ps=(0.0, 0.0), t_dc=(0.5, 0.0), training_set=None)
¶
Initialization of a Tree QPNN instance.
Each piece of the QPNN architecture is instantiated and stored as an attribute alongside relevant parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
int
|
number of branches in the tree, \(b\) |
required |
L
|
int
|
number of layers, \(L\) |
required |
varphi
|
tuple
|
tuple of the phase shifts applied to the subtracted photon, followed by that applied to the remaining photons, for the 3LS photon \(\mp\) nonlinearity, in \(\text{rad}\), \((\varphi_1, \varphi2)\) |
(0.0, pi)
|
ell_mzi
|
tuple
|
nominal loss for a Mach-Zehnder interferometer in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual interferometer is selected |
(0.0, 0.0)
|
ell_ps
|
tuple
|
nominal loss for a phase shifter in dB, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual output phase shifter is selected |
(0.0, 0.0)
|
t_dc
|
tuple
|
directional coupler splitting ratios (T:R) as decimal values, where the first (second) element is the mean (standard deviation) of a normal distribution from which those for each individual nominally 50:50 coupler is selected |
(0.5, 0.0)
|
training_set
|
tuple | None
|
tuple of three tuples, the first two of which are the input and target states resolved in the computational basis for each \(1 \leq n \leq b + 1\), the last of which contains the computational basis indices for each unit cell operation that exists for each \(n\) |
None
|
Source code in src/quotonic/qpnn.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
training_set
property
writable
¶
Training set for the unit cell generation functionality of the QPNN.
Returns:
| Name | Type | Description |
|---|---|---|
psi_in |
tuple
|
tuple of the input states resolved in the computational basis for each \(1 \leq n \leq b + 1\) |
psi_targ |
tuple
|
tuple of the target states resolved in the computational basis for each \(1 \leq n \leq b + 1\) |
comp_indices |
tuple
|
computational basis indices for each unit cell operation that exists for each \(n\) |
imperfections
property
writable
¶
Component-level imperfection values for each interferometer mesh in the QPNN.
See ImperfectQPNN.imperfections for more details.
Returns:
| Name | Type | Description |
|---|---|---|
ells_mzi |
tuple
|
\(L\times m\times m\) array containing the fractinal loss per arm of each of the \(L\) interferometer meshes, for each column of MZIs respectively |
ells_ps |
tuple
|
\(L\times m\) array containing the fractional loss for each of the output phase shifters in each of the \(L\) interferometer meshes |
ts_dc |
tuple
|
\(L\times 2\times m(m-1)/2\) array containing the splitting ratio (T:R) of each directional coupler in each of the \(L\) interferometer meshes, organized such that each column corresponds to one MZI, the top row being the first directional coupler and the bottom being the second, where the MZIs are ordered from top to bottom followed by left to right across each mesh |
build(phi, theta, delta)
¶
Build matrix representations of the QPNN from all its layers and components, for operation on \(1 \leq n \leq b + 1\) photons.
This method calculates the system function of the QPNN as introduced at the top of this module, yet does so for each potential number of input photons, \(1 \leq n \leq b + 1\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
tuple
|
a tuple of \(b + 1\) \(N\times N\) arrays, the matrix representations of the QPNN resolved in the \(N\)-dimensional second quantization Fock bases for all \(1 \leq n \leq b + 1\) |
Source code in src/quotonic/qpnn.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
calc_cost(phi, theta, delta)
¶
Calculate the cost function for the QPNN.
This method calculates the cost function of the QPNN as introduced at the top of this module. It relies on a training set and will thus throw an error if one has not been provided. Specifically, it includes all input-target pairs for all unit cell operations for all numbers of photons \(1 \leq n \leq b + 1\), before averaging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
C |
DTypeLike
|
cost (i.e. network error) of the QPNN |
Source code in src/quotonic/qpnn.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | |
calc_overall_performance_measures(phi, theta, delta)
¶
Calculate the overall fidelity, success rate and logical rate of the QPNN.
This method calculates the fidelity, success rate, and logical rate of the QPNN as introduced at the top of this module. It relies on a training set and will thus throw an error if one has not been provided. Specifically, it includes all input-target pairs for all unit cell operations for all numbers of photons \(1 \leq n \leq b + 1\), before averaging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fid |
DTypeLike
|
overall fidelity of the QPNN |
succ_rate |
DTypeLike
|
overall success rate of the QPNN |
logi_rate |
DTypeLike
|
overall logical rate of the QPNN |
Source code in src/quotonic/qpnn.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 | |
calc_unit_cell_performance_measures(phi, theta, delta)
¶
Calculate the fidelities, success rates and logical rates of the QPNN for each individual unit cell operation required for tree formation.
This method calculates the fidelity, success rate, and logical rate of the QPNN as introduced at the top of this module. It relies on a training set and will thus throw an error if one has not been provided. Specifically, each returned value includes only the input-target pairs for a specific unit cell operation. For each measure, a tuple is returned. The elements of this tuple are arrays, each for a specific number of photons in increasing order for all \(1 \leq n \leq b + 1\). There may be multiple unit cell operations required for a given \(n\), so these arrays may contain multiple values. The specific dimensions depend in a complicated way on \(b\), which is why they are not provided here in general.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\phi\), where the ith row contains those for each MZI in the ith layer |
required |
theta
|
jnp_ndarray
|
\(L\times m(m-1)/2\) phase shifts, \(\theta\), where the ith row contains those for each MZI in the ith layer |
required |
delta
|
jnp_ndarray
|
\(L\times m\) phase shifts, \(\delta\), where the ith row contains those for each mode at the output of the mesh in the ith layer |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fids |
tuple
|
tuple containing the fidelities of the QPNN for each unit cell operation and each \(n\) |
succ_rates |
tuple
|
tuple containing the success rates of the QPNN for each unit cell operation and each \(n\) |
logi_rates |
tuple
|
tuple containing the logical rates of the QPNN for each unit cell operation and each \(n\) |
Source code in src/quotonic/qpnn.py
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 | |