Skip to content

Commit

Permalink
Fix all flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
noc0lour committed May 17, 2023
1 parent 7682e40 commit 8c47685
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 66 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 88
extend-ignore = E203
#max-complexity = 10
33 changes: 17 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ license = {file = "COPYING"}
authors = [
{name = "Andrej Rode", email = "rode@kit.edu"},
{name = "Shrinivas Chimmalgi", email="shrinivas.chimmalgi@kit.edu"},
{name = "Benedikt Geiger", email="benedikt.geiger@kit.edu"}
{name = "Benedikt Geiger", email="benedikt.geiger@kit.edu"},
{name = "Laurent Schmalen"}
]

dependencies = [
Expand Down Expand Up @@ -43,7 +44,6 @@ dev = [
"pytest",
"black",
"flake8",
"pyproject-flake8",
"pylint",
"python-lsp-server[all]",
"pyls-flake8",
Expand All @@ -55,11 +55,6 @@ remotelog = [
"wandb",
]

[tool.flake8]
max-line-length = 88
extend-ignore = "E203,"
max-complexity = 10

[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
Expand Down Expand Up @@ -103,8 +98,9 @@ legacy_tox_ini = """
[tox]
description = list of environments against which tox runs the tests
envlist =
reformat
check
flake8
black
pydocstyle
py3-fast
py37
py38
Expand All @@ -121,7 +117,7 @@ python =
3.7: py37
3.8: py38
3.9: py39
3.10: reformat, check, py310
3.10: flake8, black, pydocstyle, py310
[testenv]
# install pytest in the virtualenv where commands will be executed
Expand All @@ -139,20 +135,25 @@ usedevelop = False
commands =
pytest {env:PYTEST_MARKERS:} {env:PYTEST_EXTRA_ARGS:} {posargs:-vv}
[testenv:check]
[testenv:flake8]
description = this environments checks for flake8 and black
deps =
black==22.3.0
pyproject-flake8
flake8
build
skip_install = true
commands =
pflake8 src tests
black --check --diff src tests
python -m build
flake8 src tests
[testenv:pydocstyle]
description = this environments checks formatting with pydocstyle
deps =
pydocstyle
skip_install = true
commands =
pydocstyle --count src/
[testenv:reformat]
[testenv:black]
description = reformats the code using black
deps =
black==22.3.0
Expand Down
22 changes: 14 additions & 8 deletions src/mokka/channels/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def nonlinear_operator(u):

return (h_dz, h_dz_2, nonlinear_operator)

def forward(self, u):
def forward(self, u): # noqa: C901
"""
:param u0: input signal (array)
:returns: array signal at the end of the fiber
Expand Down Expand Up @@ -636,7 +636,8 @@ def forward(self, u):
z = z + 2 * dz
if iter >= self.maxiter:
logger.info(
"WARNING: Failed to converge to goal local error of %s in %s iterations",
"WARNING: Failed to converge to goal local error \
of %s in %s iterations",
self.delta_G,
self.maxiter,
)
Expand All @@ -663,9 +664,10 @@ class SSFMPropagationDualPol(torch.nn.Module):
This class is adapted from Code written by Dominik Rimpf published under the MIT
license [https://gitlab.com/domrim/bachelorarbeit-code]
This class solves the coupled nonlinear Schrodinger equation for pulse propagation in an
optical fiber using the split-step Fourier method.
The implementation and name are based on https://photonics.umd.edu/software/ssprop/vector-version/
This class solves the coupled nonlinear Schrodinger equation for pulse propagation
in an optical fiber using the split-step Fourier method.
The implementation and name are based on
https://photonics.umd.edu/software/ssprop/vector-version/
:param dt: time step between samples (sample time)
:param dz: propagation stepsize (delta z) of SSFM (segment length)
Expand All @@ -679,8 +681,11 @@ class SSFMPropagationDualPol(torch.nn.Module):
length
:param delta_G: Goal local error (optional) (default 1e-3)
:param maxiter: Number of step-size iterations (optional) (default 4)
:param psp: Principal eigenstate of the fiber specified as a 2-vector containing the angles Psi and Chi (optional) (default [0,0])
:param solution_method: String that specifies which method to use when performing the split-step calculations. Supported methods elliptical and circular (optional) (default elliptical)
:param psp: Principal eigenstate of the fiber specified as a 2-vector containing
the angles Psi and Chi (optional) (default [0,0])
:param solution_method: String that specifies which method to use when performing
the split-step calculations. Supported methods elliptical
and circular (optional) (default elliptical)
"""

Expand Down Expand Up @@ -939,7 +944,8 @@ def forward(self, ux, uy):

if iter >= self.maxiter:
logger.info(
"WARNING: Failed to converge to goal local error of %s in %s iterations",
"WARNING: Failed to converge to goal local error \
of %s in %s iterations",
self.delta_G,
self.maxiter,
)
Expand Down
1 change: 0 additions & 1 deletion src/mokka/inft/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def BMI(m, N, b_ij, L_ij, p=None):
return BMI



def MI(M, PX, N, symbol_idx, Q_YX):
"""
Calculate the mutual information.
Expand Down
17 changes: 10 additions & 7 deletions src/mokka/mapping/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ class ClassicalDemapper(torch.nn.Module):
"""
Classical Bitwise Soft Demapper with Gaussian Noise assumption.
It takes the noise_sigma and constellation sorted from [0,2**m -1] and constructs
an more or less efficient demapper which outputs LLRS for all m bits for each received symbol
an more or less efficient demapper which outputs LLRS for all m bits for
each received symbol
"""

def __init__(self, noise_sigma, constellation, optimize=False):
Expand Down Expand Up @@ -550,8 +551,9 @@ def symbolwise(self, y, *args):
class GaussianDemapper(torch.nn.Module):
"""
Classical Bitwise Soft Demapper with Gaussian Noise assumption.
Learns bias and covariance matrix of noise for constellation sorted from [0,2**m -1] and constructs
an more or less efficient demapper which outputs LLRS for all m bits for each received symbol
Learns bias and covariance matrix of noise for constellation sorted from [0,2**m -1]
and constructs a more or less efficient demapper which outputs LLRS for all m bits
for each received symbol
"""

def __init__(self, constellation):
Expand Down Expand Up @@ -637,7 +639,6 @@ def warm_start(self, sym_idx, y, learning_fraction=0.3, single_circular=False):
]
rx_sym = y[idx].squeeze()
if y.dtype == torch.complex64:
dim = 2
rx_sym = torch.stack(
(torch.real(rx_sym), torch.imag(rx_sym))
).squeeze()
Expand Down Expand Up @@ -750,9 +751,10 @@ def forward(self, y, *args):

class SeparatedSimpleDemapper(torch.nn.Module):
"""
Simplified Demapper which shall approximates output LLRS of bits separated in real and imag
Simplified Demapper which shall approximates output LLRS of bits separated in real
and imaginary parts
Do simple function approximation with in -> Linear -> ReLU -> Linear -> out operation
Do simple function approximation with in -> Linear -> ReLU -> Linear -> out
This should be easy to replicate in hardware with LUT
"""

Expand Down Expand Up @@ -888,7 +890,8 @@ def p_symbols(self, *args):

class MBPCSSampler(torch.nn.Module):
"""
This class is supposed to use NNs to find a lambda [0,1] for each given parameter (if given parameters) and then return p_symbols for further simulation
This class is supposed to use NNs to find a lambda [0,1] for each given parameter
(if given parameters) and then return p_symbols for further simulation
"""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions src/mokka/normalization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import torch
from . import torch # noqa

from .torch import energy, centered_energy
from .torch import energy, centered_energy # noqa
2 changes: 1 addition & 1 deletion src/mokka/pulseshaping/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import torch
from . import torch # noqa
38 changes: 19 additions & 19 deletions src/mokka/pulseshaping/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@attr.define
class PulseShaping(torch.nn.Module):
"""
PulseShaping filter class which provides several classical shapes, a filter function and a
matched filter function.
PulseShaping filter class which provides several classical shapes, a filter function
and a matched filter function.
"""

_impulse_response: torch.tensor
Expand Down Expand Up @@ -80,15 +80,15 @@ def get_rc_ir(cls, syms, r, n_up, learnable=False):
with torch.no_grad():
# initialize output length and sample time
T_symbol = 1.0
T_sample = (
1.0 / n_up
) # length of one sample is the symbol-duration divided by the oversampling factor (=1/sampling rate)
T_ir = (
2 * syms * T_symbol
) # Duration of the impulse response is positive and negative normed symbols added multplied by Symbol Duration
ir = torch.zeros(
int(T_ir / T_sample) + 1
) # samples of impulse response is definied by duration of the ir divided by the sample time plus one for the 0th sample
T_sample = 1.0 / n_up
# length of one sample is the symbol-duration divided
# by the oversampling factor (=1/sampling rate)
T_ir = 2 * syms * T_symbol
# Duration of the impulse response is positive and negative
# normed symbols added multplied by Symbol Duration
ir = torch.zeros(int(T_ir / T_sample) + 1)
# samples of impulse response is definied by duration
# of the ir divided by the sample time plus one for the 0th sample

# time indices and sampled time
k_steps = torch.arange(
Expand Down Expand Up @@ -121,8 +121,8 @@ def get_rc_ir(cls, syms, r, n_up, learnable=False):
def get_rrc_ir(cls, syms, r, n_up, learnable=False):
"""Determines normed coefficients of an RRC filter
This function is adapted from Sourcecode written by Dominik Rimpf and was published under the
MIT license [https://gitlab.com/domrim/bachelorarbeit-code]
This function is adapted from Sourcecode written by Dominik Rimpf and was
published under the MIT license [https://gitlab.com/domrim/bachelorarbeit-code]
Formula out of: K.-D. Kammeyer, Nachrichtenübertragung
At poles, l'Hospital was used
Expand All @@ -138,12 +138,12 @@ def get_rrc_ir(cls, syms, r, n_up, learnable=False):
# initialize output length and sample time
T_symbol = 1.0
T_sample = 1 / n_up
T_ir = (
2 * syms * T_symbol
) # Duration of the impulse response is positive and negative normed symbols added multplied by Symbol Duration
ir = torch.zeros(
int(T_ir / T_sample) + 1
) # samples of impulse response is definied by duration of the ir divided by the sample time plus one for the 0th sample
T_ir = 2 * syms * T_symbol
# Duration of the impulse response is positive and negative
# normed symbols added multplied by Symbol Duration
ir = torch.zeros(int(T_ir / T_sample) + 1)
# samples of impulse response is definied by duration of
# the ir divided by the sample time plus one for the 0th sample

# time indices and sampled time
k_steps = torch.arange(
Expand Down
4 changes: 2 additions & 2 deletions src/mokka/utils/generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from . import numpy
from . import numpy # noqa

try:
from . import torch
from . import torch # noqa
except ImportError:
pass
2 changes: 1 addition & 1 deletion src/mokka/utils/generators/torch.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import torch
import torch # noqa
9 changes: 4 additions & 5 deletions tests/mokka/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def test_residualphasenoise():


def test_opticalnoise():
wavelength_bw = 0.1 # nm
optical_snr = 25 # dB
channel = channels.OpticalNoise(dt, wavelength, wavelength_bw , optical_snr)
wavelength_bw = 0.1 # nm
optical_snr = 25 # dB
channel = channels.OpticalNoise(dt, wavelength, wavelength_bw, optical_snr)
x = torch.zeros(num_samples, dtype=torch.complex64)
y = channel(x)
assert len(y) == num_samples
Expand Down Expand Up @@ -103,9 +103,8 @@ def test_SSFM_singlepol():
assert len(y) == num_samples



def test_SSFM_dualpol():
amp = channels.EDFAAmpDualPol(
amp = channels.EDFAAmpDualPol( # noqa
span_length,
amp_gain,
alphaa_db,
Expand Down
2 changes: 1 addition & 1 deletion tests/mokka/test_e2e.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import mokka.e2e.torch as e2e
import mokka.e2e.torch as e2e # noqa
2 changes: 1 addition & 1 deletion tests/mokka/test_equalizers.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import mokka.equalizers.torch as equalizers
import mokka.equalizers.torch as equalizers # noqa
2 changes: 1 addition & 1 deletion tests/mokka/test_pulseshaping.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import mokka.pulseshaping.torch as pulseshape
import mokka.pulseshaping.torch as pulseshape # noqa
2 changes: 1 addition & 1 deletion tests/mokka/test_synchronizers.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import mokka.synchronizers.phase.torch as phase
import mokka.synchronizers.phase.torch as phase # noqa

0 comments on commit 8c47685

Please sign in to comment.