refactor(filters): one implementation of `exponential_filter` / `hyperviscosity` shared by Fourier, Chebyshev and spherical (currently seven copies with inconsistent validation)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- jupyter-notebook, python
- Domain
- backend-api-design, tooling
Research direction
Start by reading the existing filter implementations in fourier/filters.py, chebyshev/filters.py, and spherical/filters.py to understand the seven copies. Look at the test files for each basis to see how filters are currently tested. The goal is to create a shared module _src/_filters.py with the two multiplier functions, then refactor each filter class to use them. Verify the changes by running the existing filter tests and adding new tests for mean preservation and composition.
Written by the indexing model from the issue text.
Description
Part of #83.
Summary
The same two formulas are implemented seven times:
| File:line | Class |
|---|---|
fourier/filters.py:32, 66 |
SpectralFilter1D.exponential_filter, .hyperviscosity |
fourier/filters.py:111, 125 |
SpectralFilter2D |
fourier/filters.py:153, 167 |
SpectralFilter3D |
chebyshev/filters.py:63, 108 |
ChebyshevFilter1D |
chebyshev/filters.py:178, 224 |
ChebyshevFilter2D |
spherical/filters.py:52, 92 |
SphericalFilter1D |
spherical/filters.py:161, 195 |
SphericalFilter2D |
Only the Chebyshev and spherical copies validate alpha/power (with Python if, see #82); the Fourier 2D/3D copies have the corner-normalisation bug (#89); the spherical hyperviscosity docstring has the wrong sign (#100). Two different things share the name hyperviscosity: SpectralDerivative.hyperviscosity(u, nu, order) is a tendency −ν |k|^{2n} u, and SpectralFilter.hyperviscosity(u, nu, dt, power) is the integrating factor exp(−ν |k|^p dt).
Proposed fix
- One private module
_src/_filters.pywith pure functions on a "mode magnitude" array:exponential_multiplier(ratio, alpha, power)=exp(−α ratio^p), applied per axis (tensor product) for Fourier/Chebyshev and onl/lmaxfor spherical.hyperviscous_multiplier(eig, nu, dt, power)=exp(−ν eig^{p/2} dt).- Validation via
eqx.error_ifin one place.
- Each basis's filter class becomes: get the eigenvalue/mode-ratio arrays from the grid, call the shared multiplier, transform. The classes stay (they know their transforms) but hold no formulas.
- Rename the integrating-factor method to
hyperviscosity_integrating_factor(orhyperdiffuse), keepinghyperviscosityas a deprecated alias, so it no longer collides with the derivative-class tendency.
Acceptance criteria
- One implementation of each formula; a grep for
jnp.exp(-alphafinds exactly one site. - All existing filter tests pass; new tests: mean preservation,
F(F(u)) == F²(u),F(axis Nyquist) == exp(−α)for every basis. - Validation works under jit (traced
alpha) for every basis.
- Dominant language
- Python
- Stars
- 2
- Forks
- 0
- Avg merge
- 8h 13m
- Merged PRs (30d)
- 8
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jejjohnson/spectraldiffx
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
jejjohnson/spectraldiffx#172 ·
-
epic
Difficulty 1/5 Under an hour Newbie friendliness 62/100
jejjohnson/spectraldiffx#167 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
jejjohnson/spectraldiffx#113 ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jejjohnson/spectraldiffx#105 ·
-
dependencies
Difficulty 4/5 3-5 days Newbie friendliness 45/100
jejjohnson/spectraldiffx#181 ·
All issues in jejjohnson/spectraldiffx
Similar issues
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPossibly taken @jejjohnson claimed this today. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jejjohnson/integrix#144 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
finos/ai-governance-framework#459 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
freelawproject/litigant-portal#1307 ·
Maintainers usually reply within 2 days
-
type/bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
h2oai/h2o-llmstudio#1163 ·
Maintainers usually reply within 1 day