Analysis, design, and propagation#
Mode discovery and parameter-sweep utilities.
- class ModeSweepResult(parameter_name, parameters, modes, values)[source]#
Bases:
objectStore modal quantities evaluated over a parameter sweep.
Rows correspond to
parametersand columns tomodes. Missing or unguided solutions are represented by NaN.- Parameters:
parameter_name (str) – Name of the swept parameter.
parameters (numpy.ndarray) – One-dimensional parameter values.
modes (tuple of Mode) – Modes represented by the columns of every value array.
values (dict of str to numpy.ndarray) – Modal metrics shaped
(n_parameters, n_modes).
- parameter_name: str#
- parameters: ndarray | Quantity#
- values: dict[str, ndarray | Quantity]#
- candidate_modes(families=('LP',), max_nu=6, max_m=6)[source]#
Generate a deterministic bounded set of mode candidates.
- Parameters:
families (sequence of str, optional) – Mode families to enumerate.
max_nu (int, optional) – Largest azimuthal order to include.
max_m (int, optional) – Largest radial order to include.
- Returns:
Candidates ordered by family, azimuthal order, and radial order.
- Return type:
tuple of Mode
- find_modes(fiber, families=('LP',), max_nu=6, max_m=6)[source]#
Find guided modes supported by a fiber.
- Parameters:
fiber (Fiber) – Fiber on which effective indices are evaluated.
families (sequence of str, optional) – Mode families to search.
max_nu (int, optional) – Largest azimuthal order to test.
max_m (int, optional) – Largest radial order to test.
- Returns:
Candidates with finite effective indices between the cladding and maximum material indices.
- Return type:
tuple of Mode
- sweep_modes(fiber, parameters, *, modes=None, parameter_name='wavelength', setter=None, metrics=('effective_index', 'propagation_constant'), families=('LP',), max_nu=6, max_m=6)[source]#
Evaluate modal metrics over wavelength or another scalar parameter.
- Parameters:
fiber (Fiber) – Fiber used as the immutable sweep template.
parameters (pint.Quantity or iterable of pint.Quantity) – Ordered parameter values with explicit units for public fibers.
modes (sequence of Mode, optional) – Modes to evaluate. When omitted, modes are discovered automatically.
parameter_name (str, optional) – Name recorded in the returned result.
setter (callable, optional) – Function accepting
(fiber, value)for non-wavelength sweeps.metrics (sequence of str, optional) – Suffixes of
Fiber.get_<metric>methods to evaluate.families (sequence of str, optional) – Families used during automatic discovery.
max_nu (int, optional) – Maximum discovered azimuthal order.
max_m (int, optional) – Maximum discovered radial order.
- Returns:
Dense arrays for each requested metric.
- Return type:
- Raises:
ValueError – If
parametersis empty or not one-dimensional, or when a custom parameter is requested without a setter.
Constrained inverse design for layered fibers.
- class DesignParameter(name, bounds, setter)[source]#
Bases:
objectDescribe one bounded scalar fiber design variable.
- Parameters:
name (str) – Stable name used in optimization results.
bounds (tuple of float) – Inclusive lower and upper bounds.
setter (callable) – Function accepting
(fiber, value)and mutating a candidate fiber.
- name: str#
- bounds: tuple[float | Quantity, float | Quantity]#
- setter: Callable[[object, float], None]#
- classmethod layer_radius(layer, bounds)[source]#
Create a parameter controlling a layer interface radius.
- Parameters:
layer (int) – Inner layer index whose outer radius is varied.
bounds (tuple of float) – Lower and upper radius bounds as length quantities.
- Returns:
Radius design variable that keeps adjacent interfaces continuous.
- Return type:
- class DesignResult(fiber, parameters, objective, success, message, evaluations)[source]#
Bases:
objectStore the outcome of a fiber optimization.
- Parameters:
fiber (Fiber) – Optimized copy of the input fiber.
parameters (dict of str to float) – Best value for each named design parameter.
objective (float) – Final penalized objective value.
success (bool) – Whether the numerical optimizer reported convergence.
message (str) – Optimizer termination message.
evaluations (int) – Number of objective evaluations.
- fiber: object#
- parameters: dict[str, float | Quantity]#
- objective: float#
- success: bool#
- message: str#
- evaluations: int#
- optimize_fiber(fiber, parameters, objective, *, constraints=(), method='differential_evolution', penalty=1000000000000.0, options=None)[source]#
Minimize an arbitrary fiber objective with inequality constraints.
- Parameters:
fiber (Fiber) – Fiber used as an immutable design template.
parameters (sequence of DesignParameter) – Variables exposed to the optimizer.
objective (callable) – Scalar function evaluated on each candidate fiber.
constraints (sequence of callable, optional) – Inequality functions that are non-negative when satisfied.
method (str, optional) –
"differential_evolution"or a method accepted byscipy.optimize.minimize().penalty (float, optional) – Quadratic penalty multiplier for constraint violations.
options (dict, optional) – Options forwarded to the selected SciPy optimizer.
- Returns:
Optimized fiber and numerical termination information.
- Return type:
- Raises:
ValueError – If no design parameters are supplied.
Notes
The input fiber is never modified.
Mode overlaps and coupled-mode longitudinal propagation.
- overlap(field_a, field_b, *, normalized=True)[source]#
Calculate the electric-field overlap on a shared Cartesian grid.
- Parameters:
- Returns:
Complex overlap integral or normalized overlap coefficient.
- Return type:
complex
- Raises:
ValueError – If the two field grids have different shapes.
- coupling_matrix(fields, perturbation=None)[source]#
Build a Hermitian coupling matrix from sampled mode fields.
- Parameters:
fields (sequence of Field) – Mode fields defined on a common Cartesian grid.
perturbation (scalar or numpy.ndarray, optional) – Spatial weighting applied to each overlap integrand.
- Returns:
Complex Hermitian matrix with a zero diagonal.
- Return type:
numpy.ndarray
- class PropagationResult(z, amplitudes)[source]#
Bases:
objectStore longitudinal coupled-mode propagation results.
- Parameters:
z (numpy.ndarray) – Longitudinal sample positions.
amplitudes (numpy.ndarray) – Complex modal amplitudes shaped
(n_positions, n_modes).
- z: ndarray#
- amplitudes: ndarray#
- property powers#
Return modal powers at every longitudinal position.
- Returns:
Squared amplitude magnitudes with the same shape as
amplitudes.- Return type:
numpy.ndarray
- class CoupledModeSystem(betas, coupling)[source]#
Bases:
objectRepresent a longitudinal coupled-mode system.
- Parameters:
betas (array-like) – Propagation constants for each mode.
coupling (array-like or callable) – Constant coupling matrix or function
coupling(z).
Notes
Amplitudes satisfy \(dA/dz = -i(\beta + \kappa)A\).
- propagate(initial, z, **solve_options)[source]#
Propagate initial modal amplitudes over longitudinal positions.
- Parameters:
initial (array-like) – Complex modal amplitudes at
z[0].z (array-like) – Ordered longitudinal evaluation positions.
**solve_options – Additional options forwarded to
scipy.integrate.solve_ivp().
- Returns:
Positions and propagated modal amplitudes.
- Return type:
- Raises:
ValueError – If initial amplitudes and propagation constants differ in length.
RuntimeError – If numerical integration fails.
Focused orchestration services used by the Fiber façade.
- class ModalAnalysis(fiber, settings=None)[source]#
Bases:
objectSolve and cache modal properties for one fiber.
- Parameters:
fiber (Fiber) – Fiber model owned by this service.
settings (SolverSettings, optional) – Numerical settings shared by solves.
- effective_index_result(mode)[source]#
Return a diagnostic effective-index result for a mode.
- Parameters:
mode (Mode) – Mode to solve.
- Returns:
Cached value and convergence status.
- Return type:
SolverResult[float]
- effective_index(mode)[source]#
Return an effective index through the scalar convenience API.
- Return type:
float
- cutoff_result(mode)[source]#
Return a cached normalized-cutoff result.
- Parameters:
mode (Mode) – Mode whose cutoff is requested.
- Returns:
Normalized cutoff and explicit status.
- Return type:
SolverResult[float]
- property cache_size: int#
Return the number of cached modal quantities.
- class FieldAnalysis(fiber)[source]#
Bases:
objectConstruct sampled and radial fields for one fiber.
- Parameters:
fiber (Fiber) – Fiber model owned by this service.
Structured numerical results returned by solver service APIs.
- class SolverResult(value, converged, residual=None, iterations=None, bracket=None, message='', metadata=<factory>)[source]#
Bases:
Generic[T]Describe a numerical solver outcome without ambiguous sentinel values.
- Parameters:
value (T or None) – Computed value, or
Nonewhen unsuccessful.converged (bool) – Whether a valid solution was obtained.
residual (float or None, optional) – Residual of the characteristic equation when available.
iterations (int or None, optional) – Number of iterations when reported by the backend.
bracket (tuple of float or None, optional) – Root bracket used by the backend.
message (str, optional) – Human-readable status information.
metadata (dict, optional) – Additional backend-specific diagnostics.
- value: T | None#
- converged: bool#
- residual: float | None#
- iterations: int | None#
- bracket: tuple[float, float] | None#
- message: str#
- metadata: dict[str, object]#
- unwrap()[source]#
Return the value or raise when the solve failed.
- Returns:
Successfully computed value.
- Return type:
T
- Raises:
ConvergenceError – If
convergedis false or no value is available.
Structural interfaces implemented by modal solver backends.
- class EffectiveIndexSolver(*args, **kwargs)[source]#
Bases:
ProtocolProtocol for effective-index solver implementations.
- class DiagnosticEffectiveIndexSolver(*args, **kwargs)[source]#
Bases:
EffectiveIndexSolver,ProtocolEffective-index backend that exposes structured diagnostics.
- solve_result(mode, delta_neff)[source]#
Solve
modeand retain convergence diagnostics.- Parameters:
mode (Mode)
delta_neff (float)
- Return type:
SolverResult[float]
- class CutoffSolver(*args, **kwargs)[source]#
Bases:
ProtocolProtocol for normalized-cutoff solver implementations.
- class RadialFieldSolver(*args, **kwargs)[source]#
Bases:
ProtocolProtocol for cylindrical radial-field solver implementations.
Two-layer step-index fiber solvers.
- class CutoffSolver(fiber, wavelength)[source]#
Bases:
BaseSolverSolve normalized modal cutoffs for a two-layer step-index fiber.
- Parameters:
fiber (Fiber) – Standard step-index fiber.
wavelength (float) – Reference vacuum wavelength in meters.
Notes
The fiber must contain exactly one circular core and one homogeneous exterior cladding. LP cutoffs use the weak-guidance approximation.
- logger = <Logger PyFiberModes.solver.two_layer.cutoff (WARNING)>#
- solve(mode)[source]#
Calculate the normalized cutoff frequency of a mode.
- Parameters:
mode (Mode) – Mode whose cutoff is requested.
- Returns:
Cutoff V-number.
- Return type:
float
- class EffectiveIndexSolver(fiber, wavelength)[source]#
Bases:
BaseSolverSolve effective indices and fields for a two-layer fiber.
- Parameters:
fiber (Fiber) – Standard step-index fiber.
wavelength (float) – Vacuum wavelength in meters.
Notes
The solver requires exactly two concentric, homogeneous, isotropic layers with a higher-index inner core. Characteristic functions are dimensionless; their roots give the dimensionless effective index.
- get_mode_with_lower_neff(mode)[source]#
Select a neighboring mode used as a lower solution boundary.
- get_clad_index_from_V0(V0)[source]#
Gets a clad index value associated to a certain V0 parameter for the same exact fiber.
- Parameters:
V0 (float) – The V number
- Returns:
The clad index
- Return type:
float
- get_low_neff_boundary(mode)[source]#
Gets the lower neff boundary using a lower neff mode.
- Parameters:
mode (Mode) – The current mode
- Returns:
The low neff boundary.
- Return type:
float
- get_characteristic_equation(mode)[source]#
Gets the adequat phase matching mode equation function.
- Parameters:
mode (Mode) – The mode
- Returns:
The characteristic-equation function.
- Return type:
object
- get_ceq_function(mode)#
Gets the adequat phase matching mode equation function.
- Parameters:
mode (Mode) – The mode
- Returns:
The characteristic-equation function.
- Return type:
object
- solve(mode, delta_neff, max_iteration=100, epsilon=1e-14)[source]#
Solve and return the effective index (neff) for a given mode.
- Parameters:
mode (Mode) – The mode
delta_neff (float) – The delta neff
max_iteration (int) – The maximum iteration, compute time heavily depend on it.
epsilon (float) – The epsilon
- Returns:
The effective index of the mode
- Return type:
float
- solve_result(mode, delta_neff, max_iteration=100, epsilon=1e-14)[source]#
Solve an effective index and return complete diagnostics.
- Parameters:
mode (Mode) – Mode to solve.
delta_neff (float) – Retained scalar-API search-step setting.
max_iteration (int, optional) – Maximum Brent iterations.
epsilon (float, optional) – Offset applied to physical search boundaries.
- Returns:
Effective index and explicit convergence information.
- Return type:
SolverResult[float]
- get_LP_field(nu, neff, radius)[source]#
Gets the LP field in the form of a tuple containing two numpy arrays. Tuple structure is [\(E_{x}\), 0, 0], [0, \(H_{y}\), 0].
The field are computed with as:
In the core:
\[\begin{split}E_x &= j_0\left( U * r \ r_{core} \right) / j_0(U) \\[10pt] H_y &= n_{eff} * \sqrt{\epsilon_0 / \mu_0} * E_x \\[10pt]\end{split}\]In the clad:
\[\begin{split}E_x &= k_0\left( W * r \ r_{core} \right) / k_0(W) \\[10pt] H_y &= n_{eff} * \sqrt{\epsilon_0 / \mu_0} * E_x \\[10pt]\end{split}\]- Parameters:
nu (int) – The nu parameter of the mode
neff (float) – The effective index
radius (float) – The radius
- Returns:
The lp field.
- Return type:
tuple
- get_TE_field(nu, neff, radius)[source]#
Gets the TE field in the form of a tuple containing two numpy arrays. Tuple structure is [0, \(E_{\phi}\), 0], [\(H_{r}\), 0, \(H_{z}\)]
The field are computed within the core and radius:
In the core
\[\begin{split}H_z &= \frac{\sqrt{\epsilon_0 / \mu_0} * U}{k_0 r_{core}} * \frac{j_0(U * r/r_{core})}{j_1(U)} \\[10pt] E_\phi &= -j_1(U * r/r_{core}) / j_1(U) \\[10pt] H_r &= n_{eff} * \sqrt{\epsilon_0 / \mu_0} * E_\phi \\[10pt]\end{split}\]In the clad
\[\begin{split}H_z &= \frac{\sqrt{\epsilon_0 / \mu_0} * W}{k_0 r_{core}} * \frac{k_0(W * r/r_{core})}{k_1(U)} \\[10pt] E_\phi &= -k_1(W * r/r_{core}) / k_1(W) \\[10pt] H_r &= n_{eff} * \sqrt{\epsilon_0 / \mu_0} * E_\phi \\[10pt]\end{split}\]- Parameters:
nu (int) – The nu parameter of the mode
neff (float) – The effective index
radius (float) – The radius
- Returns:
The TE field.
- Return type:
tuple
- get_TM_field(nu, neff, radius)[source]#
Gets the TM field in the form of a tuple containing two numpy arrays. Tuple structure is [\(E_{r}\), 0, \(E_{z}\)], [0, \(H_{\phi}\), 0]
The field are computed within the core and radius:
In the core
\[\begin{split}E_z &= \frac{-U}{k_0 * n_{eff} * r_{core}} * \frac{j_0(U * r / r_{core})}{j_1(U)} \\[10pt] E_r &= j_1(U * r/r_{core}) / j_1(U) \\[10pt] H_\phi &= \sqrt{\epsilon_0 / \mu_0} * n_{core} / n_{eff} * E_r \\[10pt]\end{split}\]In the clad
\[\begin{split}E_z &= \frac{n_{core}}{n_{clad}} \frac{W}{k_0 * n_{eff} * r_{core}} * \frac{k_0(W * r / r_{core})}{k_1(W)} \\[10pt] E_r &= \frac{n_{core}}{n_{clad}} k_1(W * r/r_{core}) / k_1(W)\\[10pt] H_\phi &= \sqrt{\epsilon_0 / \mu_0} * \frac{n_{core}}{n_{clad}} * k_1(W * r/r_{core}) / k_1(W) \\[10pt]\end{split}\]- Parameters:
nu (int) – The nu parameter of the mode
neff (float) – The effective index
radius (float) – The radius
- Returns:
The LP field.
- Return type:
tuple
- get_HE_field(nu, neff, radius)[source]#
Gets the HE field in the form of a tuple containing two numpy arrays. Tuple structure is [\(E_{r}\), \(E_{\phi}\), \(E_{z}\)], [\(H_{r}\), \(H_{\phi}\), \(H_{z}\)]
- Parameters:
nu (int) – The nu parameter of the mode
neff (float) – The effective index
radius (float) – The radius
- Returns:
The HE field.
- Return type:
tuple
- get_EH_field(*args, **kwargs)[source]#
Gets the EH field in the form of a tuple containing two numpy arrays. Tuple structure is [\(E_{r}\), \(E_{\phi}\), \(E_{z}\)], [\(H_{r}\), \(H_{\phi}\), \(H_{z}\)]
- Parameters:
*args – Positional arguments forwarded to
get_HE_field().**kwargs – Keyword arguments forwarded to
get_HE_field().
- Returns:
The LP field.
- Return type:
tuple
- get_U_W_V_parameter(neff)[source]#
Gets the U, W parameter of the fiber. Those are computed as:
- Parameters:
neff (float) – The effective index
- Returns:
The U and W parameter.
- Return type:
tuple
- get_LP_equation(neff, nu)[source]#
Return the LP-mode characteristic equation residual.
\[U J_{\nu-1}(U) K_{\nu}(W) + W J_{\nu}(U) K_{\nu-1}(W)\]- Parameters:
neff (float) – The effective index
nu (int) – The nu parameter of the mode
- Returns:
Characteristic-equation residual; a mode solution occurs at a root.
- Return type:
float
- get_TE_equation(neff, nu)[source]#
Return the TE characteristic-equation residual.
\[U J_0(U) K_1(W) + W J_1(U) K_0(W)\]- Parameters:
neff (float) – The effective index
nu (int) – The nu parameter of the mode
- Returns:
Dimensionless boundary-condition residual. A guided TE solution occurs at a root.
- Return type:
float
- get_TM_equation(neff, nu)[source]#
Return the TM characteristic-equation residual.
\[U J_0(U) K_1(W)n_\mathrm{clad}^2 + W J_1(U) K_0(W)n_\mathrm{core}^2\]- Parameters:
neff (float) – The effective index
nu (int) – The nu parameter of the mode
- Returns:
Dimensionless boundary-condition residual. A guided TM solution occurs at a root.
- Return type:
float
- get_HE_EH_terms(neff, nu)[source]#
Return the common and splitting terms of the hybrid equations.
- Parameters:
neff (float) – The effective index
nu (int) – The nu parameter of the mode
- Returns:
Dimensionless common boundary term and non-negative hybrid splitting term. Their sum and difference form the HE and EH characteristic residuals, respectively.
- Return type:
tuple of float
Three-layer step-index fiber solvers.
- class CutoffSolver(fiber, wavelength)[source]#
Bases:
BaseSolverSolve normalized cutoffs for a three-layer step-index fiber.
- Parameters:
fiber (Fiber) – Three-layer fiber to solve.
wavelength (float) – Reference vacuum wavelength in meters.
Notes
Only cutoff calculations are provided by this backend. Effective indices and fields for the same geometry are handled by the multilayer solver.
Multilayer step-index fiber solvers.
- class EffectiveIndexSolver(fiber, wavelength)[source]#
Bases:
BaseSolverSolve effective indices for arbitrary multilayer step-index fibers.
- Parameters:
fiber (Fiber) – Multilayer fiber to solve.
wavelength (float) – Vacuum wavelength in meters.
Notes
LP, TE, TM, HE, and EH families are supported. The solver does not model anisotropy, material loss, stress birefringence, non-circular interfaces, or longitudinal tapering within a solve.
- get_neff_lower_boundary(mode, delta_neff=1e-06)[source]#
Gets the lower boundary for neff value.
- Parameters:
mode (Mode) – The mode to evaluate
delta_neff (float) – The delta neff
- Returns:
The neff lower boundary.
- Return type:
float
- solve(mode, delta_neff)[source]#
Find an effective-index root for a mode.
- Parameters:
mode (Mode) – Mode whose effective index is requested.
delta_neff (float) – Maximum effective-index search step.
- Returns:
Effective index, or
numpy.nanwhen no valid interval exists.- Return type:
float
- solve_result(mode, delta_neff)[source]#
Solve an effective index and retain failure diagnostics.
- Parameters:
mode (Mode) – Mode whose effective index is requested.
delta_neff (float) – Maximum effective-index search step.
- Returns:
Root value, residual, search bracket, and status explanation.
- Return type:
SolverResult[float]
- get_LP_field(nu, neff, radius)[source]#
Gets the \(LP_{ u, m}\) mode field.
- Parameters:
nu (int) – The nu parameter of the LP mode
neff (float) – The effective index
radius (float) – The radius for evaluation
- Returns:
The LP electric and magnetic field in a tuple.
- Return type:
tuple[float, float]
- get_LP_field_from_parameters(eval_layer, radius, neff, nu, C)[source]#
Gets the LP field evaluation from parameters.
- Parameters:
eval_layer (object) – The layer at which the field is evaluated
radius (float) – The radius for evaluation
neff (float) – The effective index
nu (int) – The nu parameter of the LP mode
C (tuple) – Constants
- Returns:
The LP field.
- Return type:
tuple[float, float]
- get_TE_field(nu, neff, radius)[source]#
Gets the transverse electric TE field.
- Parameters:
nu (int) – The radial parameter of the mode
neff (float) – The effective index of the mode
radius (float) – The radius at which field is evaluated
- Returns:
The TE field.
- Return type:
tuple[float, float]
- get_TM_field(nu, neff, radius)[source]#
Gets the transverse magnetic TM field.
- Parameters:
nu (int) – The radial parameter of the mode
neff (float) – The effective index of the mode
radius (float) – The radius at which field is evaluated
- Returns:
The TM field.
- Return type:
tuple[float, float]
- get_EH_field(nu, neff, radius)[source]#
Gets the hybrid EH field.
- Parameters:
nu (int) – The radial parameter of the mode
neff (float) – The effective index of the mode
radius (float) – The radius at which field is evaluated
- Returns:
The EH field.
- Return type:
tuple[float, float]
- get_HE_field(nu, neff, radius)[source]#
Gets the hybrid HE field.
- Parameters:
nu (int) – The radial parameter of the mode
neff (float) – The effective index of the mode
radius (float) – The radius at which field is evaluated
- Returns:
The HE field.
- Return type:
tuple[float, float]
- get_LP_equation(neff, nu)[source]#
Evaluate the multilayer LP characteristic equation.
- Parameters:
neff (float) – Trial effective index.
nu (int) – Azimuthal order.
- Returns:
Characteristic-equation residual.
- Return type:
float
- get_TE_equation(neff, nu)[source]#
Evaluate the multilayer TE characteristic equation.
- Parameters:
neff (float) – Trial effective index.
nu (int) – Azimuthal order.
- Returns:
Characteristic-equation residual.
- Return type:
float
- get_TM_equation(neff, nu)[source]#
Evaluate the multilayer TM characteristic equation.
- Parameters:
neff (float) – Trial effective index.
nu (int) – Azimuthal order.
- Returns:
Characteristic-equation residual.
- Return type:
float