Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linters #85

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
doctests = True
ignore =
F403,
select =
C4,
E722,
F,
32 changes: 32 additions & 0 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ------------------------------------------------------------------ #
# #
# SymPy Benchmark CI script for Github Actions #
# #
# Runs each time a pull request is opened, pushed or merged #
# #
# ------------------------------------------------------------------ #

name: test
on: [push, pull_request]
jobs:

# -------------------- Code quality ------------------------------ #

code-quality:

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip

- run: pip install flake8 ruff

- name: Run flake8 on the sympy benchmark package
run: flake8 benchmarks slow_benchmarks

- name: Run Ruff on the sympy benchmark package
run: ruff check .
8 changes: 7 additions & 1 deletion benchmarks/cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from functools import reduce
from operator import add

from sympy import cse, exp, sin, symbols, tan, Matrix
import sympy as sym
from sympy import cse, exp, sin, symbols, tan, Matrix, ImmutableDenseMatrix, MatAdd, MatMul, Transpose, Inverse, \
MatrixSymbol
from sympy.core.singleton import SingletonRegistry


def _get_args_exprs(nexprs, nterms):
Expand Down Expand Up @@ -239,6 +242,9 @@ def time_combined_cse(self):
cse([self.y, self.G])


S = SingletonRegistry()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be imported from sympy



class KalmanFilterMatrixEquationCSE:
"""Kalman filter example from Matthew Rocklin's SciPy 2013 talk.

Expand Down
1 change: 0 additions & 1 deletion benchmarks/dsolve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import sympy
from sympy import symbols, dsolve, Eq, Function, exp

def _make_ode_01():
Expand Down
Empty file.
6 changes: 3 additions & 3 deletions benchmarks/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ class TimeMatrixPower:
[ 1/4 + 13*I/4, -825/64 - 147*I/32, 21/8 + I, -537/64 + 143*I/16, -5/8 - 39*I/16, 2473/256 + 137*I/64, -149/64 + 49*I/32, -177/128 - 1369*I/128]]'''))

def time_Case1(self):
m = self.Case1**4
_ = self.Case1**4

def time_Case2(self):
m = self.Case2**4
_ = self.Case2**4

def time_Case3(self):
m = self.Case3**4
_ = self.Case3**4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ = self.Case3**4
_ = self.Case3**4

2 changes: 1 addition & 1 deletion benchmarks/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def time_solve_lin_sys(self):

def time_verify_sol(self):
zeros = [eq.compose(self.sol) for eq in self.eqs]
if not all([zero == 0 for zero in zeros]):
if not all(zero == 0 for zero in zeros):
raise ValueError("All values in zero should be 0")

def time_to_expr_eqs(self):
Expand Down
1 change: 0 additions & 1 deletion benchmarks/solve_large_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from sympy.polys.rings import ring
from sympy.polys.fields import field
from sympy.polys.domains import ZZ, QQ
from sympy.polys.solvers import solve_lin_sys

# Expected times on 3.4 GHz i7:

Expand Down
1 change: 0 additions & 1 deletion benchmarks/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
The evalutation of symbolic sum via the doit method got slowed by the introdution of Piecewise. Simple profiling suggest that piecewise_fold is taking up to 97% of the time.
It worked much faster on 0.7.2(3) than on 1.0.
"""
import sympy
from sympy import symbols, Function, Sum, I, Symbol, KroneckerDelta

int12Sigma, int22Sigma, exgg12SU2L, intgg11SU2L, intgg11SU2L, ext12Sigma, ext11Sigma, ext11Sigma, exgg22SU2L, intgg11SU2L, intgg11SU2L, ext22Sigma, ext31Sigma, ext31Sigma, exgg32SU2L, intgg21SU2L, intgg21SU2L, ext32Sigma, ext21Sigma, ext21Sigma, exgg42SU2L, intgg21SU2L, intgg21SU2L, ext42Sigma, ext41Sigma, ext41Sigma, int32ASU2L, int42ASU2L, int52ASU2L, int62ASU2L, ext12Pi, ext11Pi, ext11Pi, exgg22SU2L, intgg11SU2L, intg11SU2L, ext22Pi, ext41Pi, int12Pi, int22Pi, ext32Pi, int62ASU2L, ext42Pi, exgg12SU2L, exgg32SU2L, intgg21SU2L, ext31Pi, exgg42SU2L, intgg21SU2L, intgg21SU2L, ext42Pi, ext21Pi, ext21Pi = symbols('int12Sigma int22Sigma exgg12SU2L intgg11SU2L intgg11SU2L ext12Sigma ext11Sigma ext11Sigma exgg22SU2L intgg11SU2L intgg11SU2L ext22Sigma ext31Sigma ext31Sigma exgg32SU2L intgg21SU2L intgg21SU2L ext32Sigma ext21Sigma ext21Sigma exgg42SU2L intgg21SU2L intgg21SU2L ext42Sigma ext41Sigma ext41Sigma int32ASU2L int42ASU2L int52ASU2L int62ASU2L ext12Pi ext11Pi ext11Pi exgg22SU2L intgg11SU2L intg11SU2L ext22Pi ext41Pi int12Pi int22Pi ext32Pi int62ASU2L ext42Pi exgg12SU2L exgg32SU2L intgg21SU2L ext31Pi exgg42SU2L intgg21SU2L intgg21SU2L ext42Pi ext21Pi ext21Pi')
Expand Down
44 changes: 44 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[tool.ruff]
# Enable Pyflakes `E` and `F` codes by default.
select = [
"C40",
"E",
"F",
"PIE802",
"PIE810",
"SIM101",
]

# Ignore rules that currently fail on the SymPy codebase
ignore = [
"E401", # Multiple imports on one line
"E402", # Module level import not at top of file
"E501", # Line too long (<LENGTH> > 88 characters)
"E701", # Multiple statements on one line (colon)
"E702", # Multiple statements on one line (semicolon)
"E703", # Statement ends with an unnecessary semicolon
"E711", # Comparison to `None` should be `cond is not None`
"E712", # Comparison to `<BOOL>` should be `cond is <BOOL>`
"E713", # Test for membership should be `not in`
"E714", # Test for object identity should be `is not`
"E721", # Do not compare types, use `isinstance()`
"E722", # Do not use bare `except`
"E731", # Do not assign a `lambda` expression, use a `def`
"E741", # Ambiguous variable name: `<VARIABLE>`
"E743", # Ambiguous function name: `<FUNCTION>`
"F401", # `<TYPE>` imported but unused
"F403", # `from <MODULE> import *` used; unable to detect undefined names
"F405", # `<TYPE>` may be undefined, or defined from star imports: `<MODULE>`
"F523", # `.format` call has unused arguments at position(s): <INDEX>
"F601", # Dictionary key literal `'<KEY>'` repeated
"F811", # Redefinition of unused `<VARIABLE>` from line <LINE>
"F821", # Undefined name `VARIABLE`
"F823", # Local variable `VARIABLE` referenced before assignment
"F841", # Local variable `VARIABLE` is assigned to but never used
]

# Black default, although irrelevant with E501 ignored
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
4 changes: 2 additions & 2 deletions slow_benchmarks/matrices.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sympy import Symbol, Matrix, symbols, SparseMatrix, Abs
from sympy import I, S, simplify
from sympy import Matrix, symbols, SparseMatrix
from sympy import S
from sympy.simplify.simplify import simplify

_TEST_SIMPLIFY = False # test simplify after operation?
Expand Down
2 changes: 0 additions & 2 deletions slow_benchmarks/solve.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

import sympy

class TimeMatrixOperations:
# first param is the size of the matrix, second is the number of symbols in it
params = ((6,10), (0, 2, 5))
Expand Down
2 changes: 1 addition & 1 deletion slow_benchmarks/tests/test_refine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

import sympy
from sympy import dsolve, Eq, exp, refine
from sympy import Eq, exp, refine

from slow_benchmarks.refine import _mk_piecewise_01

Expand Down