diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d3ae6d..9ba6112 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,17 +2,31 @@ name: CI on: [push, pull_request] +permissions: + contents: read + jobs: tests: + name: ${{ matrix.environment }} / Python 3.14 runs-on: ubuntu-latest - container: - image: python:3.9 + strategy: + fail-fast: false + matrix: + environment: [py314, docs, lint] + steps: - - name: Packages - run: pip install 'tox<4' - - name: Checkout - uses: actions/checkout@v3 - - name: Tox + - name: Checkout repository + uses: actions/checkout@v7 + + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: '3.14' + + - name: Install tox run: | - git config --global --add safe.directory "${GITHUB_WORKSPACE}" - tox -v + python -m pip install --upgrade pip + python -m pip install 'tox>=4,<5' + + - name: Run tests + run: python -m tox -e ${{ matrix.environment }} diff --git a/examples/plot_input_pulse.py b/examples/plot_input_pulse.py index a56f0a8..2db1688 100644 --- a/examples/plot_input_pulse.py +++ b/examples/plot_input_pulse.py @@ -18,9 +18,9 @@ # peak power [W] Pmax = 100 - # Amplitude envelope of gaussina pulse + # Amplitude envelope of gaussian pulse A1 = gnlse.GaussianEnvelope(Pmax, FWHM).A(T) - # Amplitude envelope of hiperbolic secans pulse + # Amplitude envelope of hyperbolic secant pulse A2 = gnlse.SechEnvelope(Pmax, FWHM).A(T) # Amplitude envelope of lorentzian pulse A3 = gnlse.LorentzianEnvelope(Pmax, FWHM).A(T) @@ -29,19 +29,19 @@ plt.figure(figsize=(12, 8)) plt.subplot(1, 2, 1) - plt.plot(T, A1, label='gauss') - plt.plot(T, A2, label='sech') - plt.plot(T, A3, label='lorentz') - plt.plot(T, A4, label='cw') + plt.plot(T, np.abs(A1), label='gauss') + plt.plot(T, np.abs(A2), label='sech') + plt.plot(T, np.abs(A3), label='lorentz') + plt.plot(T, np.abs(A4), label='cw') plt.xlabel("Time [ps]") plt.ylabel("Amplitude [sqrt(W)]") plt.legend() plt.subplot(1, 2, 2) - plt.plot(T, A1**2, label='gauss') - plt.plot(T, A2**2, label='sech') - plt.plot(T, A3**2, label='lorentz') - plt.plot(T, A4**2, label='cw') + plt.plot(T, np.abs(A1)**2, label='gauss') + plt.plot(T, np.abs(A2)**2, label='sech') + plt.plot(T, np.abs(A3)**2, label='lorentz') + plt.plot(T, np.abs(A4)**2, label='cw') plt.xlabel("Time [ps]") plt.ylabel("Power [W]") plt.legend() diff --git a/examples/test_Dudley.py b/examples/test_Dudley.py index fef21bc..4cac2cd 100644 --- a/examples/test_Dudley.py +++ b/examples/test_Dudley.py @@ -61,10 +61,12 @@ plt.subplot(2, count, i + 1) plt.title(pulse_model.name) - gnlse.plot_wavelength_vs_distance(solution, WL_range=[400, 1400]) + gnlse.plot_wavelength_vs_distance_logarithmic( + solution, WL_range=[400, 1400]) plt.subplot(2, count, i + 1 + count) - gnlse.plot_delay_vs_distance(solution, time_range=[-0.5, 5]) + gnlse.plot_delay_vs_distance_logarithmic( + solution, time_range=[-0.5, 5]) plt.tight_layout() plt.show() diff --git a/examples/test_raman.py b/examples/test_raman.py index 29a17d0..6043471 100644 --- a/examples/test_raman.py +++ b/examples/test_raman.py @@ -59,9 +59,11 @@ plt.subplot(2, count, i + 1) plt.title(name) - gnlse.plot_wavelength_vs_distance(solution, WL_range=[500, 1250]) + gnlse.plot_wavelength_vs_distance_logarithmic( + solution, WL_range=[500, 1250]) plt.subplot(2, count, i + 1 + count) - gnlse.plot_delay_vs_distance(solution, time_range=[-0.5, 4]) + gnlse.plot_delay_vs_distance_logarithmic( + solution, time_range=[-0.5, 4]) plt.tight_layout() plt.show() diff --git a/gnlse/dispersion.py b/gnlse/dispersion.py index 0e05922..b02c4eb 100644 --- a/gnlse/dispersion.py +++ b/gnlse/dispersion.py @@ -6,6 +6,7 @@ """ import numpy as np +import math from scipy import interpolate from gnlse.common import c @@ -67,7 +68,7 @@ def D(self, V): self.calc_loss() # Taylor series for subsequent derivatives # of constant propagation - B = sum(beta / np.math.factorial(i + 2) * V**(i + 2) + B = sum(beta / math.factorial(i + 2) * V**(i + 2) for i, beta in enumerate(self.betas)) L = 1j * B - self.alpha / 2 return L diff --git a/gnlse/gnlse.py b/gnlse/gnlse.py index 888064f..d2befac 100644 --- a/gnlse/gnlse.py +++ b/gnlse/gnlse.py @@ -225,7 +225,7 @@ def run(self): plan_forward = pyfftw.FFTW(x, X) plan_inverse = pyfftw.FFTW(X, x, direction="FFTW_BACKWARD") - progress_bar = tqdm.tqdm(total=self.fiber_length, unit='m') + progress_bar = tqdm.tqdm(total=round(self.fiber_length, 3), unit='m') def rhs(z, AW): """ diff --git a/gnlse/visualization.py b/gnlse/visualization.py index 56f3784..b6953fd 100644 --- a/gnlse/visualization.py +++ b/gnlse/visualization.py @@ -5,7 +5,8 @@ import numpy as np import matplotlib.pyplot as plt -from scipy.interpolate import interp2d +# scipy.interpolate.interp2d was removed in SciPy 1.14. +from scipy.interpolate import RegularGridInterpolator from gnlse.common import c @@ -582,9 +583,11 @@ def plot_wavelength_vs_distance(solver, WL_range=None, ax=None, WL_asc = WL_asc[iis] IW = IW[:, iis] - interpolator = interp2d(WL_asc, solver.Z, IW) + interpolator = RegularGridInterpolator((WL_asc, solver.Z), + IW.T, method='cubic') newWL = np.linspace(np.min(WL_asc), np.max(WL_asc), IW.shape[1]) - toshow = interpolator(newWL, solver.Z) + WL_new_grid, Z_new_grid = np.meshgrid(newWL, solver.Z, indexing='ij') + toshow = interpolator((WL_new_grid, Z_new_grid)).T ax.imshow(toshow, origin='lower', aspect='auto', cmap=cmap, extent=[np.min(WL_asc), np.max(WL_asc), 0, np.max(solver.Z)], @@ -637,9 +640,10 @@ def plot_wavelength_vs_distance_logarithmic(solver, WL_range=None, WL_asc = WL_asc[iis] lIW = lIW[:, iis] - interpolator = interp2d(WL_asc, solver.Z, lIW) + interpolator = RegularGridInterpolator((WL_asc, solver.Z), lIW.T) newWL = np.linspace(np.min(WL_asc), np.max(WL_asc), lIW.shape[1]) - toshow = interpolator(newWL, solver.Z) + WL_new_grid, Z_new_grid = np.meshgrid(newWL, solver.Z, indexing='ij') + toshow = interpolator((WL_new_grid, Z_new_grid)).T ax.imshow(toshow, origin='lower', aspect='auto', cmap=cmap, extent=[np.min(WL_asc), np.max(WL_asc), 0, np.max(solver.Z)], diff --git a/requirements.txt b/requirements.txt index 90e9a69..8030649 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -matplotlib>=2.2.2 -numpy>=1.14.3 -scipy>=1.1.0 +matplotlib>=3.0.0 +numpy>=2.0.0 +scipy>=1.10.0 pyfftw>=0.10.0 -hdf5storage>=0.1.15 +hdf5storage>=0.2.0 tqdm>=4.11.2 diff --git a/setup.py b/setup.py index 8286482..9fe9306 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,12 @@ -import pkg_resources - from setuptools import find_packages from setuptools import setup with open('requirements.txt', 'r') as fh: - reqs = [str(requirement) - for requirement in pkg_resources.parse_requirements(fh)] + reqs = [ + line.strip() + for line in fh + if line.strip() and not line.strip().startswith('#') + ] with open("README.md", "r") as fh: long_description = fh.read() @@ -23,9 +24,14 @@ packages=find_packages(), classifiers=[ 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: 3.14', 'Operating System :: OS Independent', ], + license='MIT', python_requires='>=3.7', install_requires=reqs, ) diff --git a/tools/run_examples.py b/tools/run_examples.py new file mode 100644 index 0000000..be6c8ec --- /dev/null +++ b/tools/run_examples.py @@ -0,0 +1,18 @@ +"""Run every example in a separate Python process (Windows and Linux).""" + +from pathlib import Path +import subprocess +import sys + + +ROOT = Path(__file__).resolve().parent.parent +EXAMPLES = sorted((ROOT / "examples").glob("*.py")) + +if not EXAMPLES: + raise SystemExit("No Python examples were found") + +for example in EXAMPLES: + print(f"Running {example.name}", flush=True) + subprocess.run([sys.executable, str(example)], cwd=ROOT, check=True) + +print(f"All {len(EXAMPLES)} examples completed successfully") diff --git a/tox.ini b/tox.ini index 85eb735..a93fbe3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,53 +1,32 @@ [tox] -minversion = 1.6 -skipsdist = True -envlist = docs,examples,doc8,pep8,autopep8 +requires = tox>=4 +env_list = py314, docs, lint [testenv] -basepython = python3 -usedevelop = True -install_command = pip install {opts} {packages} +package = editable -[testenv:autopep8] -description = Print autopep8 suggestions. -envdir = {toxworkdir}/linters -deps = -r test-requirements.txt -commands = autopep8 --recursive --aggressive --diff --exit-code . - -[testenv:doc8] -description = Style guide enforcement with doc8. -envdir = {toxworkdir}/linters -deps = -r test-requirements.txt -commands = doc8 {posargs} +[testenv:py314] +description = Run numerical examples on Python 3.14 +set_env = + MPLBACKEND = Agg +commands = + python tools/run_examples.py [testenv:docs] -description = Build project documentation. -envdir = {toxworkdir}/sphinx +description = Build Sphinx HTML documentation deps = -r docs/requirements.txt -allowlist_externals = rm commands = - rm -rf docs/_build - sphinx-build -W -b html docs docs/_build - -[testenv:examples] -description = Run all python scripts from examples directory - physics check. -envdir = {toxworkdir}/build -deps = -r requirements.txt -# Env variable MPLBACKEND=Agg prevents display of windows during tests -setenv = MPLBACKEND=Agg -allowlist_externals = bash -commands = bash -ex -c 'for FILE in examples/*.py; do python $FILE; done' + sphinx-build -E -W -b html docs docs/_build -[testenv:pep8] -description = Style guide enforcement with flake8. -envdir = {toxworkdir}/linters +[testenv:lint] +description = Check Python and documentation style +package = skip deps = -r test-requirements.txt -commands = flake8 {posargs} +commands = + flake8 + doc8 [doc8] -# D000 - invalid rst format -# D002 - no trailing whitespace -# D004 - no carriage returns (use unix newlines) ignore = D000,D002,D004 ignore-path = .git,.tox,.venv,docs/_build,*.egg-info