Skip to content

Remove dead Rust compute_synthetic_weights (follow-up to PR #344)#345

Merged
igerber merged 2 commits intomainfrom
fix/rust-cleanup-synthetic-weights
Apr 20, 2026
Merged

Remove dead Rust compute_synthetic_weights (follow-up to PR #344)#345
igerber merged 2 commits intomainfrom
fix/rust-cleanup-synthetic-weights

Conversation

@igerber
Copy link
Copy Markdown
Owner

@igerber igerber commented Apr 20, 2026

Summary

Methodology references (required if estimator / math changes)

Validation

  • Tests added/updated: None (the deleted Rust symbol was only tested by one cargo test case — test_compute_weights_sum_to_one — deleted alongside the function it exercised; Python-side coverage of the replacement path is already in tests/test_prep.py::TestRankControlUnits).
  • maturin develop --release --features accelerate: clean rebuild, no warnings.
  • pytest tests/test_rust_backend.py tests/test_prep.py::TestRankControlUnits: 85 passed.
  • Direct import verification: project_simplex / compute_sdid_unit_weights / compute_time_weights / sc_weight_fw still importable; compute_synthetic_weights correctly raises ImportError.
  • cargo test --release on macOS hits the known PyO3 Python3.framework rpath issue unrelated to this change. cargo check is clean.

Security / privacy

  • Confirm no secrets/PII in this PR: Yes.

Diff size: +1 / −126 across rust/src/weights.rs, rust/src/lib.rs, TODO.md.

…nding #22)

Closes the Rust-side loop on finding #22 from the silent-failures audit.
The Python-side wrapper and its sole caller were removed in PR #344; this
PR deletes the now-orphaned PyO3 binding, its internal PGD implementation,
and the obsolete constants that only serviced it.

Deleted
- rust/src/weights.rs: compute_synthetic_weights pyfunction + compute_synthetic_weights_internal
- rust/src/weights.rs: MAX_ITER, DEFAULT_TOL, DEFAULT_STEP_SIZE (only used by the deleted PGD path)
- rust/src/weights.rs: test_compute_weights_sum_to_one (cargo test for the deleted internal helper)
- rust/src/lib.rs: m.add_function(wrap_pyfunction!(weights::compute_synthetic_weights, m)?)

Retained (still used from Python)
- weights::project_simplex — consumed by _rust_project_simplex in utils.py (project_simplex tests in test_rust_backend.py)
- weights::compute_sdid_unit_weights, compute_time_weights, sc_weight_fw, compute_noise_level (SDID canonical path)
- weights::sum_normalize_internal, sparsify_internal (helpers for SDID)

Verification
- maturin develop --release --features accelerate: clean rebuild, no warnings
- cargo check --lib: clean (cargo test --release hits a known macOS PyO3 Python3.framework rpath issue unrelated to this change)
- pytest tests/test_rust_backend.py tests/test_prep.py::TestRankControlUnits: 85 passed
- Direct import test: project_simplex / compute_sdid_unit_weights / compute_time_weights / sc_weight_fw still importable; compute_synthetic_weights correctly raises ImportError

TODO.md row 86 removed. docs/audits/silent-failures-findings.md row #22 updated to FULLY RESOLVED.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Overall Assessment

✅ Looks good

Executive Summary

  • No supported estimator, weighting, or variance path changes are introduced. The registry-backed SDID implementation remains the Frank-Wolfe / two-pass synthdid match in docs/methodology/REGISTRY.md:L1438-L1566, and the retained Rust exports in rust/src/lib.rs:L31-L38 still align with that documented surface.
  • The deletion is contained. The Python backend import layer already excludes compute_synthetic_weights in diff_diff/_backend.py:L18-L39, and remaining mentions are historical comments in diff_diff/utils.py:L1133-L1140 and diff_diff/prep.py:L1014-L1027.
  • I do not see new empty-set, NaN/inference, control-group, parameter-propagation, or methodology-adherence risks in the changed code; this PR removes dead code rather than changing an active path.
  • P3 informational: tests/test_rust_backend.py:L107-L110 still says the dead binding is tracked in TODO, which becomes stale once this PR lands.
  • P3 informational: there is still no automated regression asserting that direct import of the removed private binding now fails.

Methodology

Code Quality

  • No findings. The cleanup is self-contained, and I did not find live Python callers or backend imports of the removed symbol beyond historical comments; see diff_diff/_backend.py:L18-L39.

Performance

  • No findings. This is dead-code removal and is neutral-to-positive for binary size and maintenance cost.

Maintainability

  • P3: tests/test_rust_backend.py:L107-L110 says the dead binding is still “tracked as a low-priority Rust cleanup TODO.” Impact: future readers will look for a tracker that this PR removes. Concrete fix: update or delete that comment so it says the cleanup is complete.

Tech Debt

  • No findings. Removing the resolved TODO.md entry is appropriate and reduces tracked debt.

Security

  • No findings. The PR only removes an orphaned private backend symbol and related constants/tests.

Documentation/Tests

  • P3: There is no automated regression in tests/test_rust_backend.py:L103-L116 for the new intended behavior that from diff_diff._rust_backend import compute_synthetic_weights fails. Impact: a future accidental re-export would rely on manual validation to catch it. Concrete fix: add a negative import test asserting ImportError for that symbol.

…gression guard

- tests/test_rust_backend.py: updated the stale "tracked as a low-priority
  Rust cleanup TODO" comment to reflect that the Rust-side removal is now
  done alongside the Python-side removal.
- tests/test_rust_backend.py: new test_compute_synthetic_weights_is_removed
  as a regression guard against accidental re-export of the deleted PyO3
  binding. Asserts both `from diff_diff._rust_backend import
  compute_synthetic_weights` raises ImportError and the attribute is
  absent on the module object.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@igerber
Copy link
Copy Markdown
Owner Author

igerber commented Apr 20, 2026

/ai-review

@github-actions
Copy link
Copy Markdown

🔁 AI review rerun (requested by @igerber)

Head SHA: ea381c83ea59659cd62735b704b6fa15bd4ea9f4


Overall Assessment

✅ Looks good

Re-review result: the prior informational issues are resolved, and I did not identify any new unmitigated P0/P1 findings in the changed code.

Executive Summary

Methodology

Code Quality

Performance

  • Severity: None. Impact: Dead-code removal is neutral-to-positive for compile/binary surface and does not touch any active hot path or numerical kernel used by supported estimators. Concrete fix: None.

Maintainability

  • Severity: None. Impact: The prior stale-comment concern is resolved; the test commentary now accurately reflects that the Rust symbol was removed from both implementation and registration in tests/test_rust_backend.py:L107-L110. Concrete fix: None.

Tech Debt

  • Severity: None. Impact: Removing the resolved compute_synthetic_weights cleanup item from TODO.md is appropriate; I do not see a remaining untracked follow-up created by this PR. Concrete fix: None.

Security

  • Severity: None. Impact: The PR only removes a private extension binding and associated dead code, plus adds a regression test; no new secret exposure, unsafe input handling, or attack surface is introduced. Concrete fix: None.

Documentation/Tests

  • Severity: None. Impact: The previous missing-regression-test concern is resolved by tests/test_rust_backend.py:L112-L128, which checks both from diff_diff._rust_backend import compute_synthetic_weights raising ImportError and hasattr(..., "compute_synthetic_weights") == False. Concrete fix: None.

Static-review note: I did not rerun pytest or cargo in this sandbox.

@igerber igerber added the ready-for-ci Triggers CI test workflows label Apr 20, 2026
@igerber igerber merged commit 6b24c42 into main Apr 20, 2026
21 of 22 checks passed
@igerber igerber deleted the fix/rust-cleanup-synthetic-weights branch April 20, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ci Triggers CI test workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant