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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
version: "latest"
Copy link
Member

Choose a reason for hiding this comment

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

According to https://github.com/astral-sh/ruff-action , latest is the default. This directive might not be necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

Without that there, we'd get an unwanted annotation on every CI run that it's using the latest version, that might not be what we want, and we should specify a version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @llimeht stated, in spite of it being the default, this proved to be an issue in the SasView repo, see SasView/sasview#3605 and SasView/sasview#3608

args: "check --fix-only --exit-non-zero-on-fix"
- uses: pre-commit-ci/lite-action@v1.1.0
if: always()
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ __pycache__
# are part of the repo and required by some models.
/sasmodels/models/lib/gauss*.c
sasmodels/_version.py

# Local pre-commit hooks
.pre-commit-config.yaml
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
default_install_hook_types: [pre-commit, pre-push]

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.9
hooks:
# Run the linter, applying any available fixes
- id: ruff-check
stages: [ pre-commit, pre-push ]
args: [ --fix-only ]
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we just report the issue, rather than try fixing them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The --fix-only flag restricts ruff to checking only for linting errors where it has an automatic fix available. If any are found, they are applied, and the commit is stopped. The developer can then check what has been changed by those automatic fixes, and then proceed with the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that these fixes will be applied in the CI if they are not done locally.

Copy link
Member

Choose a reason for hiding this comment

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

If we ARE fixing then maybe it makes sense to add formatting as well?

- id: ruff-format
  stages: [ pre-commit, pre-push ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given the current state of the code, adding formatting would result in a large number of changes, substantially increasing the burden for developers and PR reviewers. I am keen to introduce formatting at a later stage but this will require work done to go through the codebase, and applying formatting to what is there already.

1 change: 1 addition & 0 deletions build_tools/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre-commit
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ files = [ "build_tools/requirements.txt" ]

[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
test = [ "build_tools/requirements-test.txt" ]
dev = [ "build_tools/requirements-dev.txt" ]
server = [ "build_tools/requirements-server.txt" ]
OpenCL = [ "build_tools/requirements-opencl.txt" ]
CUDA = [ "build_tools/requirements-cuda.txt" ]
Expand Down Expand Up @@ -169,6 +170,7 @@ select = ["E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle warnings
"SIM118", # Use `key in dict` instead of `key in dict.keys()`
"SIM300"] # Yoda condition detected

Expand Down
4 changes: 2 additions & 2 deletions sasmodels/TwoYukawa/CalTYSk.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
from numpy import pi, mean
from numpy import mean, pi

from .Ecoefficient import TYCoeff
from .CalcRealRoot import CalRealRoot
from .Ecoefficient import TYCoeff
from .TInvFourier import TInvFourier

# Supplied Q vector must go out to at least this value to calculate g(r).
Expand Down
1 change: 1 addition & 0 deletions sasmodels/TwoYukawa/CalcRealRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .Ecoefficient import TYCoeff
from .Epoly import make_poly


def CalRealRoot(coeff: TYCoeff):

Ecoefficient = coeff.Ecoefficient
Expand Down
14 changes: 7 additions & 7 deletions sasmodels/TwoYukawa/Ecoefficient.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Callable, Tuple

import numpy as np
from numpy import exp, pi, cos, sin, cosh
from numpy import cos, cosh, exp, pi, sin
from numpy.typing import NDArray

# CalCoeff.m
Expand Down Expand Up @@ -194,17 +194,17 @@ def ABC12(d1, d2):
Ccd2_22*Cdd1_12*d1*d2**2 -
Ccd1_21*Cdd2_22*d1*d2**2 -
Ccd2_22*d2*k1 + Ccd1_21*d1*k2)))/
((d1*((
(d1*(
(-Ccd1_21)*Ccd2_12*d2 +
Ccd1_11*Ccd2_22*d2)))))
Ccd1_11*Ccd2_22*d2)))
C2 = ((-((Ccd2_12*d2*
(((-Cd1_1)*d1 - Cdd1_11*d1**2 -
Cdd1_12*d1*d2 + k1)) -
Ccd1_11*d1*
(((-Cd2_2)*d2 - Cdd2_12*d1*d2 -
Cdd2_22*d2**2 + k2))))) /
(((-Ccd1_21)*Ccd2_12*d1*d2 +
Ccd1_11*Ccd2_22*d1*d2)))
((-Ccd1_21)*Ccd2_12*d1*d2 +
Ccd1_11*Ccd2_22*d1*d2))
return A, B, C1, C2
self.ABC12 = ABC12

Expand Down Expand Up @@ -370,10 +370,10 @@ def tau_d21(s):

E1d02 = 12*c1F01*phi*sigma_d01(z1) - 12*c1F01*exp(-z1)*phi*tau_d01(z1)

E1d11 = (((12*c1F10*phi*sigma_d01(z1) + \
E1d11 = (12*c1F10*phi*sigma_d01(z1) + \
12*c1F01*phi*sigma_d10(z1) - \
12*c1F10*exp(-z1)*phi*tau_d01(z1) - \
12*c1F01*exp(-z1)*phi*tau_d10(z1))))
12*c1F01*exp(-z1)*phi*tau_d10(z1))
E1d12 = (-c1F01 + 12*c1F11*phi*sigma_d01(z1) +
12*c1F01*phi*sigma_d11(z1) -
12*c1F11*exp(-z1)*phi*tau_d01(z1) -
Expand Down
277 changes: 139 additions & 138 deletions sasmodels/TwoYukawa/Epoly.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions sasmodels/TwoYukawa/TFourier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from numpy import exp, pi, arange, linspace, abs, ceil, log2, interp
from numpy import abs, arange, ceil, exp, interp, linspace, log2, pi
from numpy.fft import fft


def TFourier(x, y, deltaX):
"""
Compute the Fourier transform of a function y(x) with sampling interval deltaX.
Expand Down Expand Up @@ -40,4 +41,4 @@ def TFourier(x, y, deltaX):
w = w_min + R_w * arange(N) / N
# Yw(k) = sum_1^N x(j)* exp(-2*pi*i*(j-1)(k-1)/N)

return w, Yw
return w, Yw
5 changes: 3 additions & 2 deletions sasmodels/TwoYukawa/TInvFourier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from numpy import exp, ceil, log2, pi, arange, interp
from numpy import arange, ceil, exp, interp, log2, pi
from numpy.fft import fft


def TInvFourier(x, y, deltaX):
"""
Inverse Fourier transform implementation
Expand Down Expand Up @@ -43,4 +44,4 @@ def TInvFourier(x, y, deltaX):
# t = np.flip(t)
# Yw(k) = sum_1^N x(j)* exp(-2*pi*i*(j-1)(k-1)/N)

return t, Yt
return t, Yt
6 changes: 3 additions & 3 deletions sasmodels/models/two_yukawa.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
from numpy import inf

# TODO: pep8 says packages and modules should not use camel case
from sasmodels.TwoYukawa.CalTYSk import CalTYSk, K_MIN, Z_MIN, Z_MIN_DIFF
from sasmodels.TwoYukawa.CalTYSk import K_MIN, Z_MIN, Z_MIN_DIFF, CalTYSk

# If you want a customized version of two_yukawa as a plugin (for example,
# because you want to use the high precision polynomial root solver from mpmath)
Expand All @@ -104,9 +104,9 @@
# https://github.com/SasView/sasmodels/tree/master/sasmodels/models/two_yukawa.py
# https://github.com/SasView/sasmodels/tree/master/sasmodels/TwoYukawa
if 0:
import importlib.util
import sys
from pathlib import Path
import importlib.util

# Remove existing TwoYukawa from sys.modules to force a reload
remove = [modname for modname in sys.modules if modname.startswith('TwoYukawa.') or modname == 'TwoYukawa']
Expand All @@ -121,7 +121,7 @@
sys.modules['TwoYukawa'] = module

# Override sasmodels library symbols with the local symbols.
from TwoYukawa.CalTYSk import CalTYSk, K_MIN, Z_MIN, Z_MIN_DIFF
from TwoYukawa.CalTYSk import K_MIN, Z_MIN, Z_MIN_DIFF, CalTYSk

name = "two_yukawa"
title = "User model for two Yukawa structure factor (S(q))"
Expand Down