Zulip Chat Archive

Stream: mathlib4

Topic: Running Mathlib under `set_option debug.byAsSorry`


Kim Morrison (Jul 25 2024 at 10:39):

I've been trying to get Mathlib to run under set_option debug.byAsSorry, which turns all by blocks into sorry.

Kim Morrison (Jul 25 2024 at 10:40):

The purpose of this is to enable very fast benchmarking builds of subsets of Mathlib. (e.g. one might turn it on globally, and then turn it off for select files, and then rebuild while making changes to Lean itself)

Kim Morrison (Jul 25 2024 at 10:40):

This causes some problems! Sometimes implicit arguments in term mode aren't determined until we run a tactic block. Other times variables are not pulled in when the tactic block is omitted.

Kim Morrison (Jul 25 2024 at 10:40):

Nearly all the changes required, however, seem positive. I've made 5 PRs so far backporting changes. #14993 #15119 #15120 #15125 #15126

Kim Morrison (Jul 25 2024 at 10:40):

Moreover, some of these changes are independently going to be helpful as we change the variable inclusion mechanism (as requested at lean#2452 with work in flight at lean#4814).

Kim Morrison (Jul 25 2024 at 10:40):

If anyone would like to help out with this effort, here's how you can assist:

  • Checkout branch#byAsSorry
  • lake build
  • This will fail at a bunch of files, the current frontier of work.
  • Look at these files
    • if you can fix them via the types of changes in the PRs above, please do so!
    • if you can't fix them, just as set_option debug.byAsSorry false, either to individual declarations or the whole file
  • Commit any of the set_option changes direct to branch#byAsSorry
  • But for all the other changes, please don't commit them directly: instead git stash them, create a branch off master, and PR them, then merge that branch in byAsSorry.

Kim Morrison (Jul 25 2024 at 10:40):

It's probably a good idea to "claim" and "unclaim" branch#byAsSorry here, via comment or emoji, so we don't have any collisions. I'm done for the night.

Notification Bot (Jul 25 2024 at 10:50):

9 messages were moved from this topic to #Zulip meta > fixing the mathlib#n linkifier by Kim Morrison.

Michael Rothgang (Jul 25 2024 at 11:40):

Let me "claim" this branch for perhaps an hour (I'll write another message once I'm done)

Michael Rothgang (Jul 25 2024 at 11:41):

Follow-up request: can you disable the linter.unusedTactic linter on that branch? (I won't do that now, to not bust my cache locally. But it seems useful to avoid warning spew.)

Eric Wieser (Jul 25 2024 at 12:00):

Are the semantics of byAsSorry "don't run any by blocks" or "don't run any Prop-typed by blocks"?

Eric Wieser (Jul 25 2024 at 12:00):

If the former, this seems to be leaning towards "by should not be used for data" as a hard rule, rather than the general guideline it used to be

Sebastian Ullrich (Jul 25 2024 at 12:05):

the latter

Edward van de Meent (Jul 25 2024 at 12:44):

assuming this gets adapted, i suppose mathlib would need another CI step where mathlib gets built with this option, to enforce this kind of benchmarking is possible? or maybe this can be enforced with some kind of linter?

Edward van de Meent (Jul 25 2024 at 12:47):

Michael Rothgang said:

Follow-up request: can you disable the linter.unusedTactic linter on that branch? (I won't do that now, to not bust my cache locally. But it seems useful to avoid warning spew.)

maybe you could just hide warnings?

Edward van de Meent (Jul 25 2024 at 12:48):

i imagine there might be an option for that?

Michael Rothgang (Jul 25 2024 at 14:40):

Sure, I can disable these warnings locally. I'm asking to globally disable these warnings (on that branch only) because

  • with that option, "unreachable tactics" are bound to happen by design
  • right now, runninglake build or opening a new file means waiting for what feels a minute, for lake to replay all the warnings produced by previous files --- which are not useful

Michael Rothgang (Jul 25 2024 at 14:41):

I filed #15133 with the fixes I have so far (for a few other files, I couldn't find an easy find, but set_option debug.byAsSorry at the top of the file did not work either; I left these alone.

Edward van de Meent (Jul 25 2024 at 14:46):

is it just me or do the changes to the lakefile you made at branch#MR-debugAsSorry make lake build throw errors saying invalid -D parameter, unknown configuration option 'linter.unreachableTactic'?

Edward van de Meent (Jul 25 2024 at 14:48):

or are you still working on that?

Edward van de Meent (Jul 25 2024 at 15:04):

i'd like to claim the branch for a bit

Michael Rothgang (Jul 25 2024 at 15:29):

Edward van de Meent said:

is it just me or do the changes to the lakefile you made at branch#MR-debugAsSorry make lake build throw errors saying invalid -D parameter, unknown configuration option 'linter.unreachableTactic'?

No, both tactics are mathlib tactics, and that branch apparently doesn't have the Lean change allowing to set mathlib options in lakefile.lean.

Michael Rothgang (Jul 25 2024 at 15:29):

I'm not working on this branch.

Edward van de Meent (Jul 25 2024 at 15:30):

(deleted)

Edward van de Meent (Jul 25 2024 at 17:23):

i've created a pr, is it the intention that the entirety of (current master + your changes) gets merged into branch#byAsSorry ? or just (your changes)?

Edward van de Meent (Jul 25 2024 at 17:24):

(the pr is #15137 for those interested)

Edward van de Meent (Jul 25 2024 at 17:33):

i suppose i will do the first option.

Edward van de Meent (Jul 25 2024 at 17:34):

once CI completes, that is

Edward van de Meent (Jul 25 2024 at 18:10):

ok, i'm done

Kim Morrison (Jul 25 2024 at 22:49):

Michael Rothgang said:

I filed #15133 with the fixes I have so far (for a few other files, I couldn't find an easy find, but set_option debug.byAsSorry at the top of the file did not work either; I left these alone.

Made one change, and :merge:'d

Kim Morrison (Jul 25 2024 at 22:51):

Edward van de Meent said:

(the pr is #15137 for those interested)

Thank you! :merge:'d

Kim Morrison (Jul 25 2024 at 23:26):

Oh: I should have said earlier, a good technique for debugging when Lean can't synthesize an implicit argument to is locally set_option debug.byAsSorry false, and then use #print to inspect the proof term, and fill things in from that.

Kim Morrison (Jul 25 2024 at 23:57):

Another: robustifying for debug.byAsSorry (part 8) #15149

Kim Morrison (Jul 26 2024 at 00:46):

And: robustifying for debug.byAsSorry (part 9) #15150

Kim Morrison (Jul 26 2024 at 00:46):

I'll fix the errors in those two, but otherwise branch#byAsSorry is available if anyone would like to hack on this.

Kim Morrison (Jul 26 2024 at 00:49):

We are definitely "getting there" now. We have been adding set_option debug.byAsSorry false in places, and these will have to be revisited, but the current frontier is now:

- Mathlib.Algebra.Algebra.Subalgebra.Directed
- Mathlib.Algebra.Category.Grp.Kernels
- Mathlib.Algebra.Exact
- Mathlib.Algebra.Homology.CommSq
- Mathlib.Algebra.Homology.ShortComplex.Exact
- Mathlib.Algebra.Polynomial.Basic
- Mathlib.CategoryTheory.Abelian.Transfer
- Mathlib.CategoryTheory.Galois.Decomposition
- Mathlib.CategoryTheory.Limits.EpiMono
- Mathlib.CategoryTheory.Quotient.Linear
- Mathlib.CategoryTheory.Quotient.Preadditive
- Mathlib.CategoryTheory.Sites.CoverLifting
- Mathlib.CategoryTheory.Sites.Preserves
- Mathlib.Combinatorics.Young.YoungDiagram
- Mathlib.Data.DFinsupp.WellFounded
- Mathlib.Geometry.Manifold.LocalInvariantProperties
- Mathlib.GroupTheory.OrderOfElement
- Mathlib.LinearAlgebra.TensorProduct.Tower
- Mathlib.RingTheory.Ideal.Quotient
- Mathlib.RingTheory.Localization.Basic
- Mathlib.RingTheory.Valuation.Integers
- Mathlib.SetTheory.Ordinal.Arithmetic
- Mathlib.Topology.Algebra.Module.Star
- Mathlib.Topology.Algebra.OpenSubgroup
- Mathlib.Topology.Order.Basic
- Mathlib.Topology.Order.ScottTopology
- Mathlib.Topology.SeparatedMap
- Mathlib.Topology.StoneCech

Kim Morrison (Jul 26 2024 at 00:51):

I couldn't work out how to fix

- Mathlib.Combinatorics.Young.YoungDiagram
- Mathlib.LinearAlgebra.TensorProduct.Tower

nicely at all.

Perhaps on these it is better to wait for lean#4814 to be ready, and to use include.

Mario Carneiro (Jul 26 2024 at 00:54):

Can we get some kind of by! which says "don't stub me under debug.byAsSorry"?

Mario Carneiro (Jul 26 2024 at 00:55):

this will be useful in particular for defs defined using tactics

Mario Carneiro (Jul 26 2024 at 00:56):

in fact, I think it can be implemented in user space, as set_option debug.byAsSorry false in by

Mario Carneiro (Jul 26 2024 at 00:57):

it is a uniform solution to migrate code to work with this option enabled

Kim Morrison (Jul 26 2024 at 01:03):

I'd like to do a first pass without this, and see where we land. With the changes required for the new variables I think there might not be a huge amount remaining, and by! would be a fine solution.

Eric Wieser (Jul 26 2024 at 01:13):

Mario Carneiro said:

this will be useful in particular for defs defined using tactics

I thought @Sebastian Ullrich's comment above means that such by blocks are run anyway?

Mario Carneiro (Jul 26 2024 at 01:13):

yes, but part of the reason for that was that it was just infeasible because the breakage was too much

Mario Carneiro (Jul 26 2024 at 01:14):

having a low cost syntax for opting out would make it a lot more feasible

Edward van de Meent (Jul 26 2024 at 07:32):

i'm claiming the branch again

Michael Rothgang (Jul 26 2024 at 08:57):

Kim Morrison said:

Another: robustifying for debug.byAsSorry (part 8) #15149

Do we have a standard emoji for "maintainer merge"'d? Anyway, I just did so this PR and its sequel.

Edward van de Meent (Jul 26 2024 at 09:54):

i think it would be useful for this effort to have a linter checking if toggling the option changes the type of a statement. currently, the only way to see if that is the case is hoping and waiting for an error to occur somewhere down the line when tactic-mode isn't used, but that seems a bit short-sighted to me...

Damiano Testa (Jul 26 2024 at 10:44):

As far as I understand a linter would be able to check that each individual declaration that is parsed would parse with "by replaced by sorry" (filtering out non-Prop-valued ones and whatever else). However, to recreate the full sorry-bearing environment and checking that a new declaration compiles with the previous ones sorryed out would mean basically that the linter would have to re-parse a big chunk of each file.

Damiano Testa (Jul 26 2024 at 10:45):

This looks more like a CI step: CI build mathlib as is and also mathlib-as-sorry.

Edward van de Meent (Jul 26 2024 at 10:45):

doesn't it suffice to check locally?

Edward van de Meent (Jul 26 2024 at 10:45):

because assuming that somehow a statement compiles differently when replacing by with sorry, there is a first such statement where that is the case.

Damiano Testa (Jul 26 2024 at 10:46):

I am not sure that it suffices to check locally: something sorryed may parse, but may not have the "same" meaning as the un-sorryed one in subtle ways.

Damiano Testa (Jul 26 2024 at 10:46):

A simple way in which this can happen is because a variable is not pulled in, since it was used in the proof (but not in the statement), but there are certainly more ways in which this can happen.

Edward van de Meent (Jul 26 2024 at 10:47):

so you can't compare the type of two versions of the term?

Damiano Testa (Jul 26 2024 at 10:47):

I'm not saying that the linter would be useless, just that you would still need to depend on more resources.

Damiano Testa (Jul 26 2024 at 10:48):

Yes, that could be done, but making it work for auto-generated declarations would be hard.

Edward van de Meent (Jul 26 2024 at 10:51):

maybe i'm not explaining it well...
take this example:

variable {a b :Nat} (h:a = b)

lemma heq : a = b := by exact h

with set_option debug.byAsSorry false, the type of heq is heq {a b : Nat} (h : a = b) : a = b while with set_option debug.byAsSorry true, it is heq {a b : Nat} : a = b. can't a linter tell this difference?

Damiano Testa (Jul 26 2024 at 10:52):

Yes, I think that this you could detect.

Damiano Testa (Jul 26 2024 at 10:52):

Let me try to write a linter that does that and see how it performs.

Damiano Testa (Jul 26 2024 at 10:52):

I agree that it will be useful, but I am not sure that it would flag everything that it should.

Damiano Testa (Jul 26 2024 at 12:06):

#15162

This is very preliminary, but I am not sure that I will have more time to work on this soon.

Damiano Testa (Jul 26 2024 at 12:57):

As you can probably see, the PR has just two new files: Mathlib.Tactic.Linter.CheckAsSorry and a test file. If you copy over Mathlib.Tactic.Linter.CheckAsSorry to your "other" PR, adding

import Mathlib.Tactic.Linter.CheckAsSorry

at the beginning should make the linter parse the file. The tests that I ran are basically exactly the ones contained in the test file, so I expect a lot of issues, since this is quite delicate, but hopefully it is useful.

Damiano Testa (Jul 26 2024 at 12:57):

If you accumulate the problems that you come across with the linter, I can try to fix them, though that would in all likelyhood not happen before Monday.

Edward van de Meent (Jul 26 2024 at 12:58):

right, thanks!

Edward van de Meent (Jul 26 2024 at 14:19):

#15164 is part 9 part 10 in the series

Michael Rothgang (Jul 26 2024 at 14:29):

Edward van de Meent said:

#15164 is part 9 in the series

Part 9 already landed on master, so this is even part 10. :-)

Edward van de Meent (Jul 26 2024 at 14:30):

ah oops :upside_down:

Edward van de Meent (Jul 26 2024 at 14:30):

forgot how to count

Edward van de Meent (Jul 26 2024 at 16:26):

#15169 is part 11 in the series

Edward van de Meent (Jul 26 2024 at 20:59):

@Kim Morrison i've taken a look at Mathlib.LinearAlgebra.TensorProduct.Tower, and it seems to be the case that removing [Module B P] as well as [IsScalarTower R B P] [SMulCommClass A B P] at lines 303-304 fixes the errors... it seems to have something to do with AlgebraTensorModule.assoc pulling in more variables for some reason? i'm not really sure exactly how it works. I'll create a PR for my current changes minus this tensorproduct stuff, and then free the branch

Edward van de Meent (Jul 26 2024 at 21:14):

a quick look at the docs for the file using ctrl+f makes it seem like the assumption [Module B P] occurs in 0 of the declarations in the file? nvm, that's just my browser not handling searching for italics

Edward van de Meent (Jul 26 2024 at 21:21):

it's at the very least not used in section CommSemiring, where the variable is declared

Edward van de Meent (Jul 26 2024 at 21:34):

ok, #15178 is number 12! i'm done for today

Damiano Testa (Jul 26 2024 at 22:59):

In case anyone tries the linter, I forgot to specify what I intended it to do:

  • it only inspects lemmas and theorems whose proof begins with := (as opposed to |),
  • protected confuses the linter,
  • if it fails, it should produce a message saying what expressions the sorried version produced,
  • it does not replace any other proof by sorry, just the "main" one.

Edward van de Meent (Jul 27 2024 at 07:12):

it would seem that i accidentally merged a batteries bump into the branch, which causes some issues i don't know how to fix. (it complained that some declarations like List.pmap and List.attach were already present.) For now, i'll undo the bump

Kim Morrison (Jul 27 2024 at 07:46):

@Edward van de Meent, I've merged your PRs, except for a few minor comments on #15178, which I've delegated ( :peace_sign:)

Edward van de Meent (Jul 27 2024 at 08:48):

i'm working on it again

Edward van de Meent (Jul 27 2024 at 14:01):

#15197 is part 13

Edward van de Meent (Jul 27 2024 at 14:01):

i'll stop there for today

Damiano Testa (Jul 27 2024 at 14:03):

Out of curiosity, did you try the linter? Was it in any way useful? :smile:

Edward van de Meent (Jul 27 2024 at 14:04):

i forgot :melting_face:

Kim Morrison (Jul 29 2024 at 00:46):

One more for now at "robustifying for debug.byAsSorry (part 14) #15247"

Kim Morrison (Jul 29 2024 at 00:47):

I propose, however, that we now pause on getting branch#byAsSorry working, as we are more and more often running into problems that are better solved by first updating Mathlib for the new variables inclusion mechanism from lean#4814.

Kim Morrison (Jul 29 2024 at 00:47):

I will started a separate thread describing the work that needs to be done there. We'll definitely need some help to get it pushed through. As soon as that is done we can return to byAsSorry. (Although, if anyone would like to continue here nevertheless, I'm not going to stop them!)

Kim Morrison (Jul 31 2024 at 23:17):

#15247 still awaiting review

Shuhao Song (Aug 01 2024 at 05:09):

I implemented a similar option many years ago. I used notation S\mathcal{S} to wrap around a by-block, and when the option checking_mode is true, it will be a usual by-tactic, when false it is elaborated as sorry.

Mr Proof (Aug 02 2024 at 01:30):

Hi, this sounds really useful what you're doing here. Can I just add my use case which is to basically have a small Mathlib library with propositions only without proofs included, which can be used offline, using REPL. In this use case we are not really interested in having things proved from the basic axioms, but are fine to "trust" the propositions in Mathlib are correct.


Last updated: May 02 2025 at 03:31 UTC