neurophox package¶
Subpackages¶
neurophox.helpers module¶
-
neurophox.helpers.fix_phase_torch(fixed, mask, device=device(type='cpu'), dtype=torch.complex64)[source]¶
-
neurophox.helpers.get_alpha_checkerboard(units, num_layers, include_off_mesh=False, flipud=False)[source]¶
-
neurophox.helpers.get_efficient_coarse_grain_block_sizes(units, tunable_layers_per_block=2, use_cg_sequence=True)[source]¶
-
neurophox.helpers.prm_permutation(units, tunable_block_sizes, sampling_frequencies, butterfly=False)[source]¶
-
neurophox.helpers.random_gaussian_batch(batch_size, units, covariance_matrix=None, seed=None)[source]¶ - Return type
ndarray
-
neurophox.helpers.to_stripe_array(nparray, units)[source]¶ Convert a numpy array of phase shifts of size (num_layers, units) or (batch_size, num_layers, units) into striped array for use in general feedforward mesh architectures.
- Parameters
nparray (
ndarray) – phase shift values for all columnsunits (
int) – dimension the stripe array acts on (depends on parity)
- Returns
A general mesh stripe array arrangement that is of size (units, num_layers) or (batch_size, units, num_layers)
neurophox.initializers module¶
-
class
neurophox.initializers.HaarRandomPhaseInitializer(units, num_layers=None, hadamard=False, tri=False)[source]¶ Bases:
neurophox.initializers.MeshPhaseInitializerHaar-random initialization of rectangular and triangular mesh architectures.
- Parameters
units (
int) – Input dimension, \(N\)num_layers (
Optional[int]) – Number of layers, \(L\)hadamard (
bool) – Whether to use Hadamard conventiontri (
bool) – Initializer for the triangular mesh architecture
-
class
neurophox.initializers.PRMPhaseInitializer(units, hadamard, tunable_layers_per_block=None)[source]¶
-
class
neurophox.initializers.PhaseInitializer(phase, units)[source]¶ Bases:
neurophox.initializers.MeshPhaseInitializerUser-specified initialization of rectangular and triangular mesh architectures.
- Parameters
phase (
ndarray) – Phase to initializeunits (
int) – Input dimension, \(N\)
-
class
neurophox.initializers.UniformRandomPhaseInitializer(units, num_layers, max_phase, min_phase=0)[source]¶
-
neurophox.initializers.get_haar_theta(units, num_layers, hadamard, tri=False)[source]¶ - Return type
Union[Tuple[ndarray,ndarray],Tuple[Variable,Variable],Variable]
neurophox.meshmodel module¶
-
class
neurophox.meshmodel.ButterflyMeshModel(num_layers, hadamard=False, bs_error=0.0, basis='bloch', theta_init='random_theta', phi_init='random_phi', gamma_init='random_gamma')[source]¶ Bases:
neurophox.meshmodel.MeshModelButterfly mesh
The butterfly mesh contains \(L\) layers and \(N = 2^L\) inputs/outputs to implement \(U \in \mathrm{U}(N)\). Unlike the triangular and full (\(L = N\)) rectangular mesh, the butterfly mesh is not universal. However, it has attractive properties for efficient machine learning and compact photonic implementations of unitary mesh models.
- Parameters
num_layers (
int) – Number of layers, \(L\)hadamard (
bool) – Hadamard conventionbs_error (
float) – Beamsplitter layertheta_init (
Union[str,tuple,ndarray]) – Initializer fortheta(\(\boldsymbol{\theta}\) or \(\theta_{n\ell}\)), seeMeshModel.phi_init (
Union[str,tuple,ndarray]) – Initializer forphi(\(\boldsymbol{\phi}\) or \(\phi_{n\ell}\)), seeMeshModel.gamma_init (
Union[str,tuple,ndarray]) – Initializer forgamma(\(\boldsymbol{\gamma}\) or \(\gamma_{n}\)), seeMeshModel.
-
class
neurophox.meshmodel.MeshModel(perm_idx, hadamard=False, num_tunable=None, bs_error=0.0, testing=False, use_different_errors=False, theta_init='random_theta', phi_init='random_phi', gamma_init='random_gamma', basis='bloch')[source]¶ Bases:
objectAny feedforward mesh model of \(N\) inputs/outputs and \(L\) layers.
- Parameters
perm_idx (
ndarray) – A numpy array of \(N \times L\) permutation indices for all layers of the meshhadamard (
bool) – Whether to use Hadamard conventionnum_tunable (
Optional[ndarray]) – A numpy array of \(L\) integers, where for layer \(\ell\), \(M_\ell \leq \lfloor N / 2\rfloor\), used to defined the phase shift mask.bs_error (
float) – Beamsplitter error (ignore for pure machine learning applications)testing (
bool) – Use a seed for randomizing error (ignore for pure machine learning applications)use_different_errors (
bool) – Use different errors for the left and right beamsplitter errorstheta_init (
Union[str,tuple,ndarray]) – Initializer fortheta(\(\boldsymbol{\theta}\) or \(\theta_{n\ell}\)) astr,ndarray, or tuple of the form(theta_init, theta_fn).phi_init (
Union[str,tuple,ndarray]) – Initializer forphi(\(\boldsymbol{\phi}\) or \(\phi_{n\ell}\)): astr,ndarray, or tuple of the form(phi_init, phi_fn).gamma_init (
Union[str,ndarray]) – Initializer forgamma(\(\boldsymbol{\gamma}\) or \(\gamma_{n}\)): astr,ndarray, or tuple of the form(gamma_init, gamma_fn).basis (
str) – Phase basis to use for controlling each pairwise unitary (simulated interferometer) in the mesh
-
property
init¶ Returns: Initializers for \(\boldsymbol{\theta}, \boldsymbol{\phi}, \gamma_n\).
- Return type
Tuple[MeshPhaseInitializer,MeshPhaseInitializer,MeshPhaseInitializer]
-
property
mzi_error_matrices¶ Returns: Error numpy arrays for Numpy
MeshNumpyLayer- Return type
Tuple[ndarray,ndarray]
-
property
mzi_error_tensors¶
-
class
neurophox.meshmodel.PermutingRectangularMeshModel(units, tunable_layers_per_block=None, num_tunable_layers_list=None, sampling_frequencies=None, bs_error=0.0, hadamard=False, theta_init='haar_prm', phi_init='random_phi', gamma_init='random_gamma')[source]¶ Bases:
neurophox.meshmodel.MeshModelPermuting rectangular mesh model
- Parameters
units (
int) – Input dimension, \(N\)tunable_layers_per_block (
Optional[int]) – The number of tunable layers per block (overrides num_tunable_layers_list, sampling_frequencies)num_tunable_layers_list (
Optional[List[int]]) – Number of tunable layers in each block in order from left to rightsampling_frequencies (
Optional[List[int]]) – Frequencies of sampling frequencies between the tunable layersbs_error (
float) – Photonic error in the beamsplitterhadamard (
bool) – Whether to use hadamard convention (otherwise use beamsplitter convention)theta_init (
Union[str,tuple,ndarray]) – Initializer fortheta(\(\boldsymbol{\theta}\) or \(\theta_{n\ell}\)), seeMeshModel.phi_init (
Union[str,tuple,ndarray]) – Initializer forphi(\(\boldsymbol{\phi}\) or \(\phi_{n\ell}\)), seeMeshModel.gamma_init (
Union[str,tuple,ndarray]) – Initializer forgamma(\(\boldsymbol{\gamma}\) or \(\gamma_{n}\)), seeMeshModel.
-
class
neurophox.meshmodel.RectangularMeshModel(units, num_layers=None, hadamard=False, bs_error=0.0, basis='bloch', theta_init='haar_rect', phi_init='random_phi', gamma_init='random_gamma')[source]¶ Bases:
neurophox.meshmodel.MeshModelRectangular mesh
The rectangular mesh contains \(N\) inputs/outputs and \(L\) layers in rectangular grid arrangement of pairwise unitary operators to implement \(U \in \mathrm{U}(N)\).
- Parameters
units (
int) – Input dimension, \(N\)num_layers (
Optional[int]) – Number of layers, \(L\)hadamard (
bool) – Hadamard conventionbs_error (
float) – Beamsplitter layerbasis (
str) – Phase basis to use for controlling each pairwise unitary (simulated interferometer) in the meshtheta_init (
Union[str,tuple,ndarray]) – Initializer fortheta(\(\boldsymbol{\theta}\) or \(\theta_{n\ell}\)), seeMeshModel.phi_init (
Union[str,tuple,ndarray]) – Initializer forphi(\(\boldsymbol{\phi}\) or \(\phi_{n\ell}\)), seeMeshModel.gamma_init (
Union[str,tuple,ndarray]) – Initializer forgamma(\(\boldsymbol{\gamma}\) or \(\gamma_{n}\)), seeMeshModel.
-
class
neurophox.meshmodel.TriangularMeshModel(units, hadamard=False, bs_error=0.0, basis='bloch', theta_init='haar_tri', phi_init='random_phi', gamma_init='random_gamma')[source]¶ Bases:
neurophox.meshmodel.MeshModelTriangular mesh
The triangular mesh contains \(N\) inputs/outputs and \(L = 2N - 3\) layers in triangular grid arrangement of pairwise unitary operators to implement any \(U \in \mathrm{U}(N)\).
- Parameters
units (
int) – Input dimension, \(N\)hadamard (
bool) – Hadamard conventionbs_error (
float) – Beamsplitter layerbasis (
str) – Phase basis to use for controlling each pairwise unitary (simulated interferometer) in the meshtheta_init (
Union[str,tuple,ndarray]) – Initializer fortheta(\(\boldsymbol{\theta}\) or \(\theta_{n\ell}\)), seeMeshModel.phi_init (
Union[str,tuple,ndarray]) – Initializer forphi(\(\boldsymbol{\phi}\) or \(\phi_{n\ell}\)), seeMeshModel.gamma_init (
Union[str,tuple,ndarray]) – Initializer forgamma(\(\boldsymbol{\gamma}\) or \(\gamma_{n}\)), seeMeshModel.