Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
20 changes: 10 additions & 10 deletions examples/plot_input_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions examples/test_Dudley.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions examples/test_raman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 2 additions & 1 deletion gnlse/dispersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"""
import numpy as np
import math
from scipy import interpolate

from gnlse.common import c
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gnlse/gnlse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
14 changes: 9 additions & 5 deletions gnlse/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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)],
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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,
)
18 changes: 18 additions & 0 deletions tools/run_examples.py
Original file line number Diff line number Diff line change
@@ -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")
55 changes: 17 additions & 38 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading