neurophox.components package¶
neurophox.components.mzi module¶
-
class
neurophox.components.mzi.
BlochMZI
(theta, phi, hadamard, epsilon=0.0, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.mzi.MZI
Mach-Zehnder Interferometer (Bloch basis, named after the Bloch sphere qubit formula)
Class simulating an ideal phase-shifting Mach-Zehnder interferometer. As usual in our simulation environment, we have \(\theta \in [0, \pi]\) and \(\phi \in [0, 2\pi)\).
In Hadamard convention, the corresponding transfer matrix is:
\[\begin{split}U_2(\theta, \phi) = H D(\theta) H L(\phi) = \begin{bmatrix} e^{i \phi}\cos \frac{\theta}{2} & i\sin \frac{\theta}{2} \\ ie^{i \phi}\sin \frac{\theta}{2} & \cos \frac{\theta}{2} \end{bmatrix}\end{split}\]In beamsplitter convention, the corresponding transfer matrix is:
\[\begin{split}U_2(\theta, \phi) = B D(\theta) B L(\phi) = i \begin{bmatrix} e^{i \phi}\sin \frac{\theta}{2} & \cos \frac{\theta}{2} \\ e^{i \phi}\cos \frac{\theta}{2} & -\sin \frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters
theta (
float
) – Amplitude-modulating phase shiftphi (
float
) – External phase shift,hadamard (
bool
) – Whether to use Hadamard conventionepsilon (
Union
[float
,Tuple
[float
,float
]]) – Beamsplitter errordtype – Type-casting to use for the matrix elements
-
class
neurophox.components.mzi.
MZI
(internal_upper, internal_lower, external_upper, external_lower, hadamard, epsilon=0.0, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.transfermatrix.PairwiseUnitary
Mach-Zehnder Interferometer
Class simulating the scattering matrix formulation of an ideal phase-shifting Mach-Zehnder interferometer. This can implement any \(2 \times 2\) unitary operator \(U_2 \in \mathrm{U}(2)\).
The internal phase shifts, \(\theta_1, \theta_2\), and the external phase shifts \(\phi_1, \phi_2\), are used to define the final unitary operator as follows (where we define \(\theta := \theta_1- \theta_2\) for convenience):
In Hadamard convention, the corresponding transfer matrix is:
\[\begin{split}U_2(\theta, \phi) = H L(\theta_1) R(\theta_2) H L(\phi_1) R(\phi_2) = e^{i\frac{\theta_1 + \theta_2}{2}} \begin{bmatrix} e^{i \phi_1}\cos \frac{\theta}{2} & ie^{i \phi_2}\sin \frac{\theta}{2} \\ ie^{i \phi_1}\sin \frac{\theta}{2} & e^{i \phi_2}\cos \frac{\theta}{2} \end{bmatrix}\end{split}\]In beamsplitter convention, the corresponding transfer matrix is:
\[\begin{split}U_2(\theta, \phi) = B L(\theta_1) R(\theta_2) B L(\phi_1) R(\phi_2) = i e^{i\frac{\theta_1 + \theta_2}{2}} \begin{bmatrix} e^{i \phi_1}\sin \frac{\theta}{2} & e^{i \phi_2}\cos \frac{\theta}{2} \\ e^{i \phi_1}\cos \frac{\theta}{2} & -e^{i \phi_2}\sin \frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters
internal_upper (
float
) – Upper internal phase shiftinternal_lower (
float
) – Lower internal phase shiftexternal_upper (
float
) – Upper external phase shiftexternal_lower (
float
) – Lower external phase shifthadamard (
bool
) – Whether to use Hadamard conventionepsilon (
Union
[float
,Tuple
[float
,float
]]) – Beamsplitter errordtype – Type-casting to use for the matrix elements
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
-
property
reflectivity
¶ Returns: Reflectivity, \(r\), for the matrix \(U\)
-
property
transmissivity
¶ Returns: Transmissivity, \(t\), for the matrix \(U\)
-
class
neurophox.components.mzi.
SMMZI
(theta, phi, hadamard, lower_theta=False, lower_phi=False, epsilon=0.0, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.mzi.MZI
Mach-Zehnder Interferometer (single-mode basis)
Class simulating an ideal phase-shifting Mach-Zehnder interferometer. As usual in our simulation environment, we have \(\theta \in [0, \pi]\) and \(\phi \in [0, 2\pi)\).
In Hadamard convention, the corresponding transfer matrix is:
\[\begin{split}U_2(\theta, \phi) = H L(\theta) H L(\phi) = e^{-i \theta / 2} \begin{bmatrix} e^{i \phi}\cos \frac{\theta}{2} & i\sin \frac{\theta}{2} \\ ie^{i \phi}\sin \frac{\theta}{2} & \cos \frac{\theta}{2} \end{bmatrix}\end{split}\]In beamsplitter convention, the corresponding transfer matrix is:
\[\begin{split}U_2(\theta, \phi) = B L(\theta) B L(\phi) = ie^{-i \theta / 2} \begin{bmatrix} e^{i \phi}\sin \frac{\theta}{2} & \cos \frac{\theta}{2} \\ e^{i \phi}\cos \frac{\theta}{2} & -\sin \frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters
theta (
float
) – Amplitude-modulating phase shiftphi (
float
) – External phase shift,hadamard (
bool
) – Whether to use Hadamard conventionepsilon (
Union
[float
,Tuple
[float
,float
]]) – Beamsplitter errordtype – Type-casting to use for the matrix elements
-
neurophox.components.mzi.
get_mzi_transfer_matrix
(internal_upper, internal_lower, external_upper, external_lower, hadamard, epsilon, dtype)[source]¶ Mach-Zehnder interferometer
- Parameters
internal_upper (
float
) – Upper internal phase shiftinternal_lower (
float
) – Lower internal phase shiftexternal_upper (
float
) – Upper external phase shiftexternal_lower (
float
) – Lower external phase shifthadamard (
float
) – Whether to use Hadamard conventionepsilon (
Tuple
[float
,float
]) – Beamsplitter errordtype – Type-casting to use for the matrix elements
- Return type
ndarray
- Returns
MZI transfer matrix
-
neurophox.components.mzi.
get_tdc_transfer_matrix
(kappa, delta, external_upper, external_lower, dtype)[source]¶ Tunable directional coupler
- Parameters
kappa (
float
) – Phase-matched phase shift (from coupled mode theory)delta (
float
) – Phase-mismatched phase shift (from coupled-mode theory)external_upper (
float
) – Upper external phase shiftexternal_lower (
float
) – Lower external phase shiftdtype – Type-casting to use for the matrix elements
- Return type
ndarray
- Returns
MZI transfer matrix
neurophox.components.transfermatrix module¶
-
class
neurophox.components.transfermatrix.
Beamsplitter
(hadamard, epsilon=0, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.transfermatrix.PairwiseUnitary
Ideal 50/50 beamsplitter
Implements the Hadamard or beamsplitter operator.
Hadamard transformation, \(H\):
\[\begin{split}H = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1\\ 1 & -1 \end{bmatrix}\end{split}\]Beamsplitter transformation \(B\):
\[\begin{split}B = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & i\\ i & 1 \end{bmatrix}\end{split}\]Hadamard transformation, \(H_\epsilon\) (with error \(\epsilon\)):
\[\begin{split}H_\epsilon = \frac{1}{\sqrt{2}}\begin{bmatrix} \sqrt{1 + \epsilon} & \sqrt{1 - \epsilon}\\ \sqrt{1 - \epsilon} & -\sqrt{1 + \epsilon} \end{bmatrix}\end{split}\]Beamsplitter transformation \(B_\epsilon\) (with error \(\epsilon\)):
\[\begin{split}B_\epsilon = \frac{1}{\sqrt{2}}\begin{bmatrix} \sqrt{1 + \epsilon} & i\sqrt{1 - \epsilon}\\ i\sqrt{1 - \epsilon} & \sqrt{1 + \epsilon} \end{bmatrix}\end{split}\]- Parameters
hadamard (
bool
) – Amplitude-modulating phase shiftepsilon (
float
) – Errors for beamsplitter operatordtype – Cast values as
dtype
for this pairwise unitary operator
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
- Return type
ndarray
-
property
reflectivity
¶ Returns: Reflectivity, \(r\), for the matrix \(U\)
- Return type
float
-
property
transmissivity
¶ Returns: Transmissivity, \(t\), for the matrix \(U\)
- Return type
float
-
class
neurophox.components.transfermatrix.
PairwiseUnitary
(dtype=<class 'numpy.complex128'>)[source]¶ Bases:
object
Pairwise unitary
This can be considered also a two-port unitary linear optical component (e.g. unitary scattering matrix for waveguide modal interaction).
This unitary matrix \(U_2\) has the following form:
\[\begin{split}U_2 = \begin{bmatrix} U_{11} & U_{12} \\ U_{21} & U_{22} \end{bmatrix},\end{split}\]where we define the reflectivity \(r = |U_{11}|^2 = |U_{22}|^2\) and transmissivity \(t = |U_{12}|^2 = |U_{21}|^2\). We also require that the determinant \(|\det U| = 1\), from which we ultimately get the property \(U_2^\dagger U_2 = I_2\), where \(I_2\) is the \(2 \times 2\) identity matrix. All children of this class have this property.
- Parameters
dtype – Cast values as
dtype
for this pairwise unitary operator
-
givens_rotation
(units, m, n=None)[source]¶ Givens rotation matrix \(T_{m, n}\) which rotates any vector about axes \(m, n\).
- Parameters
units (
int
) – Input dimension to rotatem (
int
) – Lower index to rotaten (
Optional
[int
]) – Upper index to rotate, requires \(n > m\) (defaults to None, which implies \(n = m + 1\))
- Return type
ndarray
- Returns
The Givens rotation matrix
-
property
inverse_matrix
¶ - Return type
ndarray
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
- Return type
ndarray
-
property
reflectivity
¶ Returns: Reflectivity, \(r\), for the matrix \(U\)
- Return type
float
-
property
transmissivity
¶ Returns: Transmissivity, \(t\), for the matrix \(U\)
- Return type
float
-
class
neurophox.components.transfermatrix.
PhaseShiftCommonMode
(phase_shift, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.transfermatrix.PairwiseUnitary
Common mode phase shift operator
Implements the common-mode phase shift operator \(C(\theta)\) given phase \(\theta\):
\[\begin{split}C(\theta) = \begin{bmatrix} e^{i\theta} & 0\\ 0 & e^{i\theta} \end{bmatrix}\end{split}\]- Parameters
phase_shift (
float
) – Phase shift \(\theta\)dtype – Cast values as
dtype
for this pairwise unitary operator
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
- Return type
ndarray
-
class
neurophox.components.transfermatrix.
PhaseShiftDifferentialMode
(phase_shift, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.transfermatrix.PairwiseUnitary
Differential phase shift operator
Implements the differential-mode phase shift operator \(D(\theta)\) given phase \(\theta\):
\[\begin{split}D(\theta) = \begin{bmatrix} e^{i\theta / 2} & 0\\ 0 & e^{-i\theta/2} \end{bmatrix}\end{split}\]- Parameters
phase_shift (
float
) – Phase shift \(\theta\)dtype – Cast values as
dtype
for this pairwise unitary operator
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
- Return type
ndarray
-
class
neurophox.components.transfermatrix.
PhaseShiftLower
(phase_shift, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.transfermatrix.PairwiseUnitary
Lower phase shift operator
Implements the lower phase shift operator \(R(\theta)\) given phase \(\theta\):
\[\begin{split}R(\theta) = \begin{bmatrix} 1 & 0\\ 0 & e^{i\theta} \end{bmatrix}\end{split}\]- Parameters
phase_shift (
float
) – Phase shift \(\theta\)dtype – Cast values as
dtype
for this pairwise unitary operator
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
- Return type
ndarray
-
class
neurophox.components.transfermatrix.
PhaseShiftUpper
(phase_shift, dtype=<class 'numpy.complex128'>)[source]¶ Bases:
neurophox.components.transfermatrix.PairwiseUnitary
Upper phase shift operator
Implements the upper phase shift operator \(L(\theta)\) given phase \(\theta\):
\[\begin{split}L(\theta) = \begin{bmatrix} e^{i\theta} & 0\\ 0 & 1 \end{bmatrix}\end{split}\]- Parameters
phase_shift (
float
) – Phase shift \(\theta\)dtype – Cast values as
dtype
for this pairwise unitary operator
-
property
matrix
¶ Returns: \(U_2\), a \(2 \times 2\) unitary matrix implemented by this component
- Return type
ndarray