Skip to content

Commit

Permalink
fix: avoid using cumtrapz from scipy
Browse files Browse the repository at this point in the history
cumtrapz has been replaced with cumulative_trapezoid in the scipy version currently required by GNPy.

Change-Id: I6790f7aa8d8e8d171faa48db4b20e6a93141c471
  • Loading branch information
AndreaDAmico committed Nov 15, 2024
1 parent 39d3f0f commit 7b1354e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions gnpy/core/science_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

from numpy import interp, pi, zeros, cos, array, append, ones, exp, arange, sqrt, trapz, arcsinh, clip, abs, sum, \
concatenate, flip, outer, inner, transpose, max, format_float_scientific, diag, sort, unique, argsort, cumprod, \
polyfit, log, reshape, swapaxes, full, nan
polyfit, log, reshape, swapaxes, full, nan, cumsum
from logging import getLogger
from scipy.constants import k, h
from scipy.integrate import cumtrapz
from scipy.interpolate import interp1d
from math import isclose, factorial

Expand Down Expand Up @@ -227,6 +226,7 @@ def calculate_unidirectional_stimulated_raman_scattering(power_in, alpha, cr, z,
if last_position < z[-1]:
interval = z_indices[(z >= last_position) * (z <= z_lumped_loss) == 1]
z_interval = z[interval] - last_position
dz = z_interval[1:] - z_interval[:-1]
last_position = z[interval][-1]
p0 = power_in * lumped_loss
power_interval = outer(p0, ones(z_interval.size))
Expand All @@ -239,15 +239,22 @@ def calculate_unidirectional_stimulated_raman_scattering(power_in, alpha, cr, z,
gamma1 = sum(crpz * eff_length, 1)
exponent += gamma1
if sim_params.raman_params.order >= 2:
gamma2 = sum(crpz * cumtrapz(expz * gamma1, z_interval, axis=1, initial=0), 1)
z_integrand = expz * gamma1
z_integral = cumsum((z_integrand[:, :-1] + z_integrand[:, 1:]) / 2 * dz, 1)
gamma2 = zeros(gamma1.shape)
gamma2[:, 1:] = sum(crpz[:, :, 1:] * z_integral, 1)
exponent += gamma2
if sim_params.raman_params.order >= 3:
gamma3 = sum(crpz * cumtrapz(expz * (gamma2 + 1/2 * gamma1**2), z_interval,
axis=1, initial=0), 1)
z_integrand = expz * (gamma2 + 1/2 * gamma1**2)
z_integral = cumsum((z_integrand[:, :-1] + z_integrand[:, 1:]) / 2 * dz, 1)
gamma3 = zeros(gamma1.shape)
gamma3[:, 1:] = sum(crpz[:, :, 1:] * z_integral, 1)
exponent += gamma3
if sim_params.raman_params.order >= 4:
gamma4 = sum(crpz * cumtrapz(expz * (gamma3 + gamma1 * gamma2 + 1/factorial(3) * gamma1**3),
z_interval, axis=1, initial=0), 1)
z_integrand = expz * (gamma3 + gamma1 * gamma2 + 1/factorial(3) * gamma1**3)
z_integral = cumsum((z_integrand[:, :-1] + z_integrand[:, 1:]) / 2 * dz, 1)
gamma4 = zeros(gamma1.shape)
gamma4[:, 1:] = sum(crpz[:, :, 1:] * z_integral, 1)
exponent += gamma4
power_interval *= exp(exponent)
power[:, interval[1:]] = power_interval[:, 1:]
Expand Down

0 comments on commit 7b1354e

Please sign in to comment.