Public API contract#

This page defines the supported PyFiberModes 1.0 surface. Only names imported from the package root and listed in PyFiberModes.__all__ are stable. Public signatures and important defaults are recorded in tests/api_snapshot.json and checked on every supported Python version.

Unit contract#

Import ureg and physical type hints from PyFiberModes.units. This unit module shares TypedUnit.ureg with PyMieSim. Physical inputs require explicit Pint quantities, including dimensionless refractive indices. Physical outputs are quantities; use .to(unit).magnitude at numerical or plotting boundaries. Bare physical inputs raise TypeError and incompatible dimensions raise pint.DimensionalityError. YAML geometry and private solvers use SI numbers.

Core models#

Stable models#

Object

Construction

Contract

Mode

Mode(family, nu, m)

Immutable identifier. family accepts a string or Family; nu >= 0 and m >= 1.

Fiber

Fiber(wavelength)

Mutable physical model; wavelength and radii require length quantities. Layer property assignments validate units and invalidate caches.

LayerSpec

LayerSpec(name, radius, refractive_index)

Immutable validated layer input; radius is metres and index is dimensionless.

SolverSettings

SolverSettings(...)

Immutable numerical settings. Tolerances must be positive.

CartesianCoordinates, CylindricalCoordinates

Coordinate arrays

Coordinate distances are metres and angular coordinates are radians.

Fiber construction and analysis#

Stable operations#

Operation

Result

Mutates input?

Failure

load_fiber()

Initialized Fiber

No

ValidationError, KeyError, or file-loading exception for invalid definitions

fiber.solve_effective_index(mode)

SolverResult[Quantity]; effective index is dimensionless

No

Failed numerical or unguided solve is represented by converged=False

fiber.get_effective_index(mode)

Effective index or NaN

No

NaN only for an unsuccessful numerical/unguided solve

fiber.get_mode_cutoff_v0(mode)

Dimensionless cutoff V-number or NaN

No

UnsupportedGeometryError when the geometry has no cutoff backend

fiber.get_mode_field(mode, limit=None, n_point=101)

Sampled Field

No

ValidationError for invalid input; ConvergenceError when the mode cannot be solved

find_modes()

Tuple of guided modes

No

Expected non-convergence is omitted; invalid input propagates

sweep_modes()

ModeSweepResult

No; copied fibers are varied

Expected per-point convergence failure becomes NaN; invalid input and unsupported operations propagate

optimize_fiber()

DesignResult

No; candidate fibers are copies

Invalid configuration raises ValueError or ValidationError

Failure model#

The exception hierarchy has stable meanings:

  • ValidationError means the request or physical input is invalid. It is also a ValueError.

  • UnsupportedGeometryError means the input is valid but that calculation has no backend for its geometry.

  • ConvergenceError means a supported numerical calculation failed to produce a finite result.

  • SolverError is the common base for supported solver failures.

SolverResult.unwrap() returns a converged value and otherwise raises ConvergenceError. Derivative-based scalar methods also raise ConvergenceError rather than returning an unexplained non-finite value. Convenience effective-index and cutoff methods retain NaN for an expected absence of a root so array workflows can represent mode cutoff naturally.

Fields, design, and propagation#

Field and coordinate objects expose sampled arrays and derived integrals; the sampling grid is immutable by convention, while internal arrays are normal NumPy arrays. DesignResult, PropagationResult, ModeSweepResult, and SolverResult are result containers. Coupled-mode propagation does not modify initial amplitudes, and overlap/coupling operations do not mutate their fields.

Compatibility names#

V_number, M_number, and get_S_parameter predate the current naming policy. They remain supported public Fiber members for the 1.x series. New APIs use descriptive snake-case names, but these three spellings are not scheduled for removal and do not emit deprecation warnings.