-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help numerary help @beartype (help numerary) by porting CachingProtocolMeta to beartype #8
Comments
I love it! I have not experimented with an LRU cache because my focus was limited to to number types, which tends to translate to a small number of cached protocols. (I also assumed that one is not computing tensor densities¹ on Raspberry Pis.) That said, I could certainly tinker around with the idea and see if it resulted in any significant difference in performance. Either way, I would be honored to contribute to a beartype feature in this way. Let's do it! If you have a solid idea about the details, I can help be along for the ride. If you haven't gotten that far, I can tackle a (rant-free²) PR as a starting point. First discussion topic: Should these be available in Python 3.7?My recommendation is: Nope, >=3.8 only. (Read on for my reasoning.) The reason I ask is that I think there is a conditional dependency on If that's accurate, I think we have (at least) two options. Option 1 - lean on
|
When brilliance refracts itself through a prism that suspiciously resembles a little-known album cover from a little-known 70's band whose name possibly rhymes with Blink Boyd, the above galaxy brain-tier post from @posita is what humanity gets. "DropBox, I summon you to pay this man in all of your corporate assets immediately!" ...fingers crossed
This. So much this. Actually, I'm delighted to hack at this too – but currently preoccupied (to an unhealthy degree that our cats find disturbing yet compelling) with finalizing the upcoming beartype configuration API. If we leave this to me, we leave this in the hands of Fate. Having read Pratchett, I trust Fate less than I used to.
This. In theory, silently integrating Beartype: it cleans your table so you don't have to.
This. Beartype: it takes the load right off you and puts it right on itself, because that's what caring and sharing means. ❤️🔥
This. I'm fuming that The overriding constraint for
This. I briefly contemplated refactoring
This. So much this. You will be both pleased and horrified to learn that my wife insists (despite lingering doubts I share) that computing tensor densities on microcontrollers is now a thing that exists, because NumPy has been ported to MicroPython and CircuitPython as a thing called If She suspects I doubt, it will not go well with me tonight. I now go to gird my loins in preparation. |
😳 The wonders never cease. I accept Her representations without question. 😊 beartype/beartype#86 is now up, but should be considered a work in progress. |
[Moved from #7, since I think I finally understand the request(s).] Discussion topic: How should we allow a cache limit to be tuned?I know the subject of runtime configurability has come up before. This one's tricksy. The temptation is to invite and set any limit override at load time, not at any arbitrary point at runtime. (The first thing that comes to mind is an environment variable?) I suppose we could expose an interface to UPDATE: I'm guessing this [emphasis mine]…
… might be of assistance here? Discussion topic: Should the LRU mechanism be
|
Amazing discussion continues amazing. A Configuration API Arises from the Blackest Depths of MoriaFirstly, the public gala unveiling the beartype configuration API is happening now and you're the only one invited: squeeeee from beartype import beartype, BeartypeConf, BeartypeStrategy
# Configure @beartype to do all these things:
# * Type-check everything in O(n) linear time.
# This is currently ignored. So, we're still gonna
# type-check a single thing in O(1) constant time.
# This is the cost of personal sloth and pizza.
# * Print the signature and body of the
# type-checking wrapper function dynamically
# generated by @beartype here to stdout.
@beartype(conf=BeartypeConf(
strategy=BeartypeStrategy.On,
is_print_wrapper_code=True,
))
def public_service_announcement(with_guitars: list[str]) -> None:
print('These are your rights:\n' + '\n'.join(with_guitars)) @beartype: freedom may still not be free, but at least we can type-check it. Given But first... Safe Threads Make Safe SweatersSecondly, thread-safety. The 💡 realization I've had over the past several lifetimes as a poorly paid techbro is that thread safety only really matters when the consequences of violating thread-safety are both harmful and permanent – like collapsing into a snow drift five yards from our cabin's front door without double mittens on, which is not gonna end well. Thankfully, that's basically never the case for memoization, caching, or other optimizations. For caching, violating thread-safety usually just means that contesting threads repeatedly cache the same thing as they trip over each trying to get out of a snow drift five yards from our cabin's front door without double mittens on. That's usually fine. Is that fine here? I know nothing, but kinda suspect we're better off without lugging around a giant deadweight Less Work Means Less Migraines
Thirdly, my instinct is to keep following your instinct. Instinctual recursion: engage! We do as you say in all things. Lastly... How Much Space Are We Talkin' Here?Since...
...we may not even need to deep-dive into LRU caching here. I know, right? I'm squeeing again over here. Specifically:
My festering guts are insinuating that LRU caching might be overkill here. What say you before faceplanting into the nearest cushion with unspeakable exhaustion, Typing Overlord Posita? |
beartype/beartype#117 aside (which I hope I didn't cause), I think we can call this fixed by beartype/beartype#86 and beartype/beartype#103? |
Jolly good show, bear bro! I meant to close this out for you a few weeks ago, but then Russia repeatedly blew up Ukraine and all I ended up doing was wearing out my Thanks again for all that fast-actin' protocol cachin'. I'm currently hip-deep wading through the uncomposted manure that is Sphinx configuration. This is why I've been quiet on the @beartype and Please, please, please drop me a line at any time if |
Sphinx. Yes. Ugh. Your observations are apt. Getting Sphinx to work is like "implementing" SAP (which is one of those rare cases where I think "implement" is the right word to describe a software installation¹). I used to fight with it on all my projects, including well after the getting-it-up-and-running phase. RtD was cool, but finicky. (I hope that's changed.) Sphinx and rST is precisely the reason I now use MkDocs (with Material) and Markdown. (No more RtD integration. I now publish straight to GitHub pages for each release, although I haven't yet invested the time to automate this.) It hasn't been without issue, and I gave up a lot of shiny promises with Sphinx², but I didn't use those anyway, and I'm much happier. I would offer to assist, but I've long since forgotten (or willfully suppressed) any memory around my troubles with Sphinx. You're welcome to ask me for help at any time. I just can't guarantee I'll be useful. Heck, I can't guarantee I won't be involuntarily triggered into a weeping mess to be scooped up off the floor with a spatula. But I'm willing to give it a shot. ¹ Hint: if I need to "implement" your software in order to use it, you don't have not delivered a product. You have delivered a liability. But, hey, what do I know? ² I mean who hasn't dreamed of a single documenting system that supports multi-language cross-references? |
Oh! One thing that did occur to me is that caching protocols may have value orthogonal to beartype. This may make runtime beartype configuration (which is a subject I know you've given some thought) more useful. Consider, for example, the case where one wants to start retrofitting the |
Enterprise JavaBeans PTSD intensifies. It's best for both of us that we not relive those hateful memories.
Quoted for truth. Animated for feels.
Keep selling me on this. I'm an easy customer here, because my black heart is already filled with vengeance at the vendor I'm locked in with what feels suspiciously like a straightjacket.
Sold. Static site generators is my jam – or would be, if I webdeved. Which I totally could. You know. Like... any minute. Sadly, I'm reliving 90's flashbacks of "I'm a Teenage Dirtbag." So, not teenage but a dirtbag? Long Grecian tragedy story short (that could very well end with someone depravedly clawing out their own sensory apparatus): @beartype has so much content locked up in reStructuredText – including a literal dumpster's worth of embedded docstrings and a I value my sanity, so I wish that abandoning Sphinx was a starter. MkDocs + Material + GitHub Pages: take me now! The only winning move is not to play. We all remember hearing that somewhere. Now, we are living that moment.
Bwaha! Code or it didn't happen, so: from beartype import (
BeartypeConf, BeartypeStrategy, beartype)
beartype_conf = BeartypeConf(
strategy=(
BeartypeStrategy.O0 # <-- no-time is a thing
if MUH_BURNING_PRODUCTION_LINE else
BeartypeStrategy.O1 # <-- linear-time for justice
)
)
'''
Beartype configuration suitable for the current environment.
Specifically:
* On production, this configuration currently disables the
:func:`beartype.beartype` decorator entirely.
* On CI, this configuration enables the default ``O(1)``-time
:func:`beartype.beartype` decorator behaviour.
'''
@beartype(conf=beartype_conf)
def make_it_so_number_one() -> str:
return 'My beard despises you, Jean Luc.' Relatedly, German Megamind @amogorkon recently invented this phenomenal Python swag called import beartype, numpy, use
# Type-check the entire NumPy API with @beartype.
use.apply_aspect(numpy, beartype)
# Type-check @beartype itself with @beartype.
use.apply_aspect(beartype, beartype)
# Type-check your production line with @beartype
# using the aforementioned configuration. Hazzuh!
import burn_it_down
use.apply_aspect(burn_it_down, beartype(conf=beartype_conf)) Apparently, Rome was built in a day. 🏟️ |
Original proposal attributed to @leycyc. From #7 (comment):
Filing separately because #7 deals with a broader issue, and I got distracted by this shiny object.
The text was updated successfully, but these errors were encountered: