Git Product home page Git Product logo

pymmf's Introduction

pyMMF

Simple module to find numerically the propagation modes and their corresponding propagation constants of multimode fibers of arbitrary index profiles.

What is it?

pyMMF is a simple module that allows finding the propagating modes of multimode fibers with arbitrary index profiles and simulates the transmission matrix for a given length. The solver can also take into account the curvature of the fiber (experimental). This code is not designed to compete with commercially available software in term of accuracy of the mode profiles/propagation constants or speed, it aims at quickly simulating realistic transmission matrices of short sections of fiber.

Citing the code

If the code was helpful to your work, please consider citing it:

DOI

Online mode predictions

Test pyMMF on Replicate

Installation

Download the file and execute the following command.

python setup.py install

Contributions

This code is written and maintained by S. M. Popoff

I thank contributions from Pavel Gostev vongostev/pyMMF:

  1. Semianalytical solver has parallelized by joblib, thanks to which its performance has increased dramatically on thick fibers.
  2. Stability of fast radial solver increased, specifically on thick fibers and small wavelengths.

How does it work?

pyMMF proposes different solvers to find the propagation constants and mode profiles of multimode optical fibers. They solve the the transverse part of the scalar propagation equation.

Semi-analytical solver for step-index

Ideal step-index fibers allow anlytical dispersion relations and mode profile expressions. This solver numericaly solves this relation dispersion and compute the modes using the analytical formula of the modes. It is only valid for ideal step-index fibers.

Use solver.solve(mode = 'SI', ...)

Radial solver

Solver for fibers with an axisymmetric index profile defined by a radial function, e.g. graded index fibers. It solves the 1D problem using the finite difference recursive scheme for Riccati's equations. It allows finding accurately and quickly the mode profiles and propagation constants for fibers when the index profiles only depends on the radial coordinate.

More details here:

Use solver.solve(mode = 'radial', ...)

Eigenvalue solver

It finds the modes by numerically finding the eigenvalues of the transverse operator represented as a large but sparse matrix on a square mesh. The eigenvectors represent the mode profiles and the eigenvalues give the corresponding propagation constants. The solver needs to know how many modes you want to compute, if the number set is higher than the number of propagationg modes, it will only returns the propagating modes. This solver is slower and requires finer discretisations compared to the radial solver, but it allows using arbitrary, and in particular non-axisymmetric, index profiles. It also allows introducing bending to the fiber and finding the modes of the perturbed fiber.

More detailed explanations can be found is this two-part tutorial:

Use solver.solve(mode = 'eig', ...)

WKB solver

Find the propagation constants of parabolic GRIN multimode fibers under the WKB (Wentzel–Kramers–Brillouin) approximation [1]_. This approximation leads to inaccurate results for modes close to the cutoff, which can be a significant proportion of the modes for typical fibers. It is provided only for comparison.

Examples

Example 1: Finding the modes of a graded index fiber (GRIN)

Preambule

import pyMMF
import numpy as np
import matplotlib.pyplot as plt

Parameters

We first set the parameters of the fiber we want to simulate.

NA = 0.275
radius = 7 # in microns
areaSize = 2.5*radius # calculate the field on an area larger than the diameter of the fiber
npoints = 2**7 # resolution of the window
n1 = 1.45
wl = 0.6328 # wavelength in microns
curvature = None

Index profile

We first create the fiber object

profile = pyMMF.IndexProfile(npoints = npoints, areaSize = areaSize)

We use the helper function that generates a parabolic index profile:

profile.initParabolicGRIN(n1=n1, a=radius, NA=NA)

We then give the profile and the wavelength to the solver

solver = pyMMF.propagationModeSolver()
solver.setIndexProfile(profile)
solver.setWL(wl)

Run the solver

The solver needs to know how many modes you want to compute. We estimate the number of modes of a GRIN multimode fiber.

NmodesMax = pyMMF.estimateNumModesGRIN(wl,radius,NA)

To be safe, we ask for a bit more than the estimated number of modes previously calculated.

2d eigenvalue solver
modes = solver.solve(nmodesMax=NmodesMax+10,
boundary = 'close',
mode = 'eig',
curvature = curvature)
Radial solver
modes = solver.solve(mode = 'radial')

Results

Ask for the number of propagating modes found by the solver (other modes are discarded).

Nmodes = modes.number

Display the profile of a mode

m = 10
plt.figure()
plt.subplot(121)
plt.imshow(np.real(modes.profiles[m]).reshape([npoints]*2))
plt.subplot(122)
plt.imshow(np.imag(modes.profiles[m]).reshape([npoints]*2))

Other examples

Other examples are provided as notebooks in the example folder.

Release notes

0.6

Bug correction

  • solve issue with optimized (scipy bisect) radial solver (see PR #8)

Changes

  • switch radial solvers: radial corresponds now to the corrected optimized radial solver using scipy for bisect search, radial_legacy is the old one
  • Store radial and azimuthal functions of the modes in the radial solver in modes0.data[<ind_mode>]['radial_func'] and modes0.data[<ind_mode>]['azimuthal_func'], can be used to apply to your mesh, e.g.:
modes = solver.solve(mode='radial_test', ...)
X, Y = np.meshgrid(...)
TH = np.arctan2(Y, X)
R = np.sqrt(X**2 + Y**2)
ind_mode = 0
psi_r = modes.data[ind_mode]['radial_func'](R)
psi_theta = modes.data[ind_mode]['azimuthal_func'](TH)
plt.figure()
plt.imshow(np.real(R*TH))
  • in the radial solver, argument min_radius_bc is now in units of wavelength, defaults to 4.

0.5

Changes

  • Radial solver performance improvements (Pavel Gostev)
  • Semi-analytical solver performance improvements (Pavel Gostev)
  • Improved documentation
  • Add Jupyter notebook examples

0.4

Changes:

  • added Ricatti solver for axisymmetric index profiles

0.1

  • First public version

pymmf's People

Contributors

asteib avatar vongostev avatar wavefrontshaping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pymmf's Issues

joblib related TypeError

Hello!

After running this code on Ubuntu 20.04.4 machine:

import pyMMF
import numpy as np

NA = 0.14
radius = 4.15
areaSize = 3.5*radius
npoints = 2**8
n1 = 1.455
wl = 1.2

profile = pyMMF.IndexProfile(npoints = npoints, areaSize = areaSize)
profile.initStepIndex(n1=n1,a=radius,NA=NA)
solver = pyMMF.propagationModeSolver()
solver.setIndexProfile(profile)
solver.setWL(wl)

modes_semianalytical = solver.solve(mode = 'SI', curvature = None)

I'm getting TypeError, full log:

2022-03-22 17:17:45,210 - pyMMF.core [DEBUG  ]  Debug mode ON.
2022-03-22 17:17:45,210 - pyMMF.solv [INFO   ]  Finding the propagation constant of step index fiber by numerically solving the dispersion relation.
2022-03-22 17:17:45,291 - pyMMF.solv [INFO   ]  Found 6 modes in 0.08 seconds.
2022-03-22 17:17:45,291 - pyMMF.solv [INFO   ]  Finding analytical LP mode profiles associated to the propagation constants.
2022-03-22 17:17:46,489 - pyMMF.core [ERROR  ]  Uncaught exception
joblib.externals.loky.process_executor._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/joblib/externals/loky/process_executor.py", line 436, in _process_worker
    r = call_item()
  File "/usr/local/lib/python3.8/dist-packages/joblib/externals/loky/process_executor.py", line 288, in __call__
    return self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/dist-packages/joblib/_parallel_backends.py", line 595, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 262, in __call__
    return [func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 262, in <listcomp>
    return [func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pyMMF/solvers/SI.py", line 130, in calc_mode
    psi = np.pi/2 if m[idx] < 0 else 0
TypeError: 'int' object is not subscriptable
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./find_modes.py", line 36, in <module>
    modes_semianalytical = solver.solve(mode = 'SI', curvature = None)
  File "/usr/local/lib/python3.8/dist-packages/pyMMF/core.py", line 239, in solve
    modes = solve_SI(
  File "/usr/local/lib/python3.8/dist-packages/pyMMF/solvers/SI.py", line 21, in solve_SI
    modes = associateLPModeProfiles(modes,indexProfile,
  File "/usr/local/lib/python3.8/dist-packages/pyMMF/solvers/SI.py", line 170, in associateLPModeProfiles
    modes.profiles = Parallel(n_jobs=n_jobs)(
  File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 1056, in __call__
    self.retrieve()
  File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 935, in retrieve
    self._output.extend(job.get(timeout=self.timeout))
  File "/usr/local/lib/python3.8/dist-packages/joblib/_parallel_backends.py", line 542, in wrap_future_result
    return future.result(timeout=timeout)
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 444, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
TypeError: 'int' object is not subscriptable

I have:

python 3.8.10
numpy  1.21.5
scipy  1.8.0
numba  0.55.1
llvmlite  0.38.0
joblib  1.1.0

An example from README is incorrect

Dear Sébastien!

There are two bugs in radial solver that uprise in the example from README.

  1. N_BETA_COARSE_DEFAULT in solvers.radial is float, but must be int
  2. binary_search in solver.radial doesn't converge. It has output value -1.79..., but it's abs must be < 1e-6.

Also there are broken links in README.

P.S.: The example from an article works good.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.