chore: import cleanup (lake shake, redundant_imports, remove import Mathlib) - #1701
Conversation
|
Thank you for this pull-request (PR). If this is your first PR, welcome to the community! Below is what will happen next. Please read carefully if you are not familiar with the process. You may open other PRs while this one is being reviewed, and can stack PRs on top of each other, so don't let these steps slow you down.
Tip: The easiest way to get have a fast review is to submit a PR that is small and self-contained, and has clear documentation explaining why things are the way they are in your chages. If you have any problems or questions, please reach out to the community on the Zulip. |
15321cb to
0b3dc77
Compare
Apply `lake shake --add-public --keep-implied --keep-prefix --fix` to Physlib
and QuantumInfo, with the following corrections:
- Drop the imports shake adds only to keep `positivity`/`norm_num`/Aesop
extensions visible ("extra rev use"); replace them by the imports
`#min_imports` reports, plus the ones downstream files actually use.
- Keep imports shake cannot see being used: `example`s and `#synth` checks
(Units/Examples, Units/ParametricDimensionExamples,
HarmonicOscillator/OneDimension/Examples, HermitianMat/Inner),
`native_decide` meta imports (SU5 ChargeSpectrum/ZMod), and Capacity.
- Import `Mathlib.Tactic.DeriveFintype` in SU5/Potential, which derives
`Fintype`.
- Remove `open`s of namespaces nothing in the file uses and an unused
`variable` block in Tensors/Reindexing, which kept otherwise unneeded
imports alive.
Co-authored-by: Claude Opus 5.5 <no-reply+claude-opus-5-5@anthropic.com>
0b3dc77 to
5e54371
Compare
…orts` Remove the imports that `lake exe redundant_imports` reports as implied by another import of the same file. Kept the ones that are not actually re-exported under the module system (the checker ignores import visibility) and `import all` imports, which also expose private declarations. Co-authored-by: Claude Opus 5.5 <no-reply+claude-opus-5-5@anthropic.com>
`QuantumInfo/ForMathlib/{Filter,Majorization,ULift}` and
`PhyslibAlpha/ProbabilisticTheory/HilbertSpace/{State/Vector,Trace}` and
`PhyslibAlpha/QuantumMechanics/StinespringDilation` imported all of Mathlib,
which put the whole library in the import closure of every file depending
on them. Replace each by the imports `#min_imports` reports, and add to the
downstream files the imports they had been getting through `Mathlib`.
`lake shake` cannot fix these: every module registering a `positivity`,
`norm_num` or Aesop extension counts as used by a file that could see it,
and `--keep-prefix` then rolls these up into `Mathlib` again.
Co-authored-by: Claude Opus 5.5 <no-reply+claude-opus-5-5@anthropic.com>
…lib` A second `lake shake` pass, now that `import Mathlib` no longer hides them, finds five unused imports in `Channels/MatrixMap`, `Channels/Dual`, `ForMathlib/Unitary`, `ResourceTheory/FreeState` and `ResourceTheory/HypothesisTesting`. Co-authored-by: Claude Opus 5.5 <no-reply+claude-opus-5-5@anthropic.com>
Tried removing each import this branch adds, one at a time, and kept the removal when the file still builds: 48 were unnecessary. Most came from `lake shake` requiring the module of a lemma or extension that `simp` or `positivity` happened to use (e.g. `Real.ringHom_apply` from `Mathlib.Algebra.Order.Archimedean.Real.Hom` in `Dynamics/Hamiltonian` and `Vacuum/IsPlaneWave`), or from `#min_imports` suggesting an instance-providing module the file can also do without. `PauliMatrices/SelfAdjoint` now imports `Mathlib.Tactic.Positivity` itself, which it had been getting through `PauliMatrices/Basic`. Co-authored-by: Claude Opus 5.5 <no-reply+claude-opus-5-5@anthropic.com>
5e54371 to
fb6fffb
Compare
jstoobysmith
left a comment
There was a problem hiding this comment.
Approved. Many thanks feel free to merge when ready.
|
I think this PR has broken CI for open PRs. The checks were failing on #1702 and I did some searching with claude and it seems removing |
Cleans up imports across Physlib, QuantumInfo and PhyslibAlpha. No declarations are added, removed or changed.
Compared with master, no module's import closure grows. Total closure size drops by 47% in QuantumInfo, 5% in PhyslibAlpha and 2.9% in Physlib. The project now depends on 4,279 of Mathlib's 8,529 modules instead of all of them, and a full build is 5,522 jobs instead of 9,890.
Commits
chore: minimize imports with lake shake:lake shake --add-public --keep-implied --keep-prefix --fixon Physlib and QuantumInfo, with corrections:positivity/norm_num/Aesop extensions in scope (e.g.Matroid.Init,EReal.Operations), which nothing uses. They are replaced by what#min_importsreports.example/#synthuses,native_decidemeta imports (SU5ChargeSpectrum/ZMod), and aderiving Fintype(SU5Potential).chore: remove transitively implied imports reported by redundant_imports: 88 imports in 63 files. The 17 remaining reports are false positives: 11 imports are needed under the module system (the checker ignores import visibility), and 6 areimport all.chore: replace import Mathlib by the imports actually used: inQuantumInfo/ForMathlib/{Filter,Majorization,ULift},PhyslibAlpha/ProbabilisticTheory/HilbertSpace/{State/Vector,Trace}andPhyslibAlpha/QuantumMechanics/StinespringDilation. Downstream files get the imports they had been receiving throughMathlib. Shake can't fix these files: with--keep-prefixit always keepsimport Mathlib.chore(QuantumInfo): remove imports unused after dropping import Mathlib: 5 imports.chore: drop added imports that the files build without: each import added by the commits above was removed in turn and kept out when the file still builds; 48 go. Most were modules of a lemma or extension thatsimp/positivityhappened to use, which shake treats as required.PauliMatrices/SelfAdjointnow importsMathlib.Tactic.Positivityitself.Non-import changes (dead code that kept imports alive)
Relativity/Tensors/RealTensor/Vector/Pre/Basic,…/Matrix/Pre,Relativity/Fermions/Weyl/Contraction: removeopen CategoryTheory.MonoidalCategory, which nothing in these files uses.Units/Dimension: remove unusedopen NNReal.Relativity/Tensors/Reindexing: shrink the unusedvariableblock to{C : Type}.Reviewer map
import Mathlibfiles, then the downstream additions.Testing
lake buildpasses for Physlib, QuantumInfo and PhyslibAlpha.lake exe lint_allpasses; the Physlib Lean linter passes.runPhyslibAlphaLinters,noAlphaImports,alphaFileImportsand the style linters pass.🤖 Generated with Claude Code