Skip to content

Phasefinder codebase cleanup#3

Merged
cairn-6ee5b843[bot] merged 20 commits intomainfrom
agent/PHASF-2-builder-1
Feb 22, 2026
Merged

Phasefinder codebase cleanup#3
cairn-6ee5b843[bot] merged 20 commits intomainfrom
agent/PHASF-2-builder-1

Conversation

@bleugreen
Copy link
Owner

Summary

Comprehensive cleanup of the phasefinder codebase: bug fixes, deduplication, type hints, packaging fixes, and CI/CD setup.

Changes

New files

  • phasefinder/constants.py — Shared constants (SAMPLE_RATE, N_FFT, HOP, FRAME_RATE, BEAT_ONSET_THRESHOLD, CLICK_SAMPLE_RATE)
  • tests/test_weight_loading.py — Proper pytest tests for weight loading and constants
  • .github/workflows/ci.yml — CI pipeline with lint and test jobs

Bug fixes (predictor.py)

  • Removed redundant device assignment block (lines 21-24 were overwritten by 29-32)
  • Fixed if not beats:if beats is None: (numpy arrays raise ValueError on truthiness)
  • Removed dead line audio_with_clicks = np.array(...) (immediately overwritten)
  • Fixed return type inconsistency: predict() now always returns np.ndarray (added .numpy() for unclean path)

Bug fixes (train.py)

  • Fixed broken import from datasetfrom phasefinder.dataset
  • Replaced hardcoded .cuda() with .to(device) using get_device()
  • Fixed running_loss bug: tracked total_loss separately from logging window
  • Removed debug print(args.use_attention)

Bug fixes (dataset.py)

  • Fixed broken import from utils.one_hotsfrom phasefinder.utils.one_hots
  • Changed default device='cuda'device=None with auto-detection

Deduplication

  • Extracted extract_beat_times() into phasefinder/postproc/__init__.py — replaces copy-pasted HMM → onset detection → cleaning pipeline from predictor.py and val.py
  • Added _report_scores() helper in val.py for repeated averaging/printing block
  • Removed duplicate frame_rate = 22050. / 512 line in val.py

Minor fixes

  • decoder.py: Renamed self.reluself.activation (it's nn.ELU())
  • cleaner.py: Removed debug print and commented-out old thresholds, removed unused nudge() function
  • hmm.py: abs()torch.abs() for consistency
  • infer.py: Removed dead audio_with_clicks = np.array(...) line

Type hints

Added type annotations to all public function signatures across: predictor.py, val.py, dataset.py, postproc/__init__.py, postproc/hmm.py, postproc/cleaner.py, utils/get_device.py, utils/get_weights.py, audio/log_filter.py

Test & import fixes

  • Fixed bare imports in test_model.py, test_postproc.py, postproc_gridsearch.py to use phasefinder. prefix
  • Added pytest config to pyproject.toml with testpaths = ["tests"]

Packaging

  • Removed duplicate librosa from requirements.txt and pyproject.toml
  • Fixed inconsistent indentation in pyproject.toml
  • Added [project.optional-dependencies] dev = ["pytest", "ruff"]

CI/CD

  • Lint job: ruff check + ruff format
  • Test job: CPU-only PyTorch, cached model weights, pytest
  • Ruff config: line-length = 120, select = ["E", "F", "W", "I"]

Code style

  • Applied ruff auto-fixes and formatting across all .py files
  • Used explicit re-export syntax in __init__.py files

Verification

  • pytest tests/ -v — 1 passed, 1 skipped (weight loading skipped without model files)
  • ruff check . — all checks passed
  • ruff format --check . — all files formatted
  • Constants import verified: FRAME_RATE=43.066...
  • extract_beat_times importable and functional

@cairn-6ee5b843 cairn-6ee5b843 bot merged commit 6794f0f into main Feb 22, 2026
2 checks passed
@cairn-6ee5b843 cairn-6ee5b843 bot deleted the agent/PHASF-2-builder-1 branch February 22, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant