Michael Kocher

122 posts

Michael Kocher banner
Michael Kocher

Michael Kocher

@ElevenPhonons

@PacBio R&D Alumni, Former core member of Materials Project (@persson_group) at @BerkeleyLab. Material Science Ph.D. Currently enjoying Scala and Python.

San Francisco, CA Katılım Haziran 2019
131 Takip Edilen41 Takipçiler
Michael Kocher
Michael Kocher@ElevenPhonons·
@karpathy Here's a list of other Python packages that are leveraging type hint/annotations to generate command line apps. Several of these projects support loading from config files formats (e.g., json,toml,yaml). #other-related-tools" target="_blank" rel="nofollow noopener">github.com/mpkocher/pydan…
English
0
0
0
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@karpathy I put a thin layer on Pydantic to generate a command line interface while also supporting JSON. It has a mix'n match model of loading config using JSON "presets" as complete/partial models and also enabling overriding these values as CLI options/flags. #loading-configuration-using-json" target="_blank" rel="nofollow noopener">github.com/mpkocher/pydan…
Michael Kocher tweet media
English
1
0
0
0
Andrej Karpathy
Andrej Karpathy@karpathy·
The software engineering aspect of deep learning repos I've been watching closely is how they store, catalogue, override, manage and plumb hyperparameter configs. Have come to dislike argparse, YAMLs (too inflexible), and fully enumerated kwargs on classes/defs. Any favorites?
English
179
161
1.8K
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@driscollis @realpython Alternatively, a range based solution could be used. I believe each `in` range call should be O(1) for non-large numbers. Also, it's probably better to use Tuple[int, ...] for breakpoint and avoid using a default mutable argument (e.g. list).
Michael Kocher tweet media
English
0
0
2
0
Mike Driscoll
Mike Driscoll@driscollis·
Have you tried the `bisect` module in #Python 🐍 ? #PythonStdLib 🔥 According to the docs, "this module provides support for maintaining a list in sorted order without having to sort the list after each insertion." Here's an example of using bisect to calculate letter grades:
Mike Driscoll tweet media
English
4
20
95
0
Trey Hunner
Trey Hunner@treyhunner·
I love Python's pathlib module. 💖🐍🗃 Whenever I need to ask a question about a file path in #Python, I default to using pathlib. Let's talk about some of my most common uses for pathlib and compare them to their non-pathlib alternatives. 🧵
English
15
120
743
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@raymondh The "returns" package explores this space and attempts to be typesafe. While these are interesting experiments, I believe there's too much friction trying to resolve the impedance mismatch of a Result return type with the standard raise model in Python. #result-container" target="_blank" rel="nofollow noopener">github.com/dry-python/ret…
English
0
0
2
0
Raymond Hettinger
Raymond Hettinger@raymondh·
My new favorite #Python helper function makes a call and puts the results in an (exception, result) pair: >>> exc_and_value('abcde'.index, 'd') (None, 3) >>> exc_and_value('abcde'.index, 'f') (<class 'ValueError'>, None) 1/
English
18
22
168
0
Ned Batchelder
Ned Batchelder@nedbat·
The two-argument form of #python's iter() repeatedly gets values from a function until it finds the specified sentinel value. #iter" target="_blank" rel="nofollow noopener">docs.python.org/3/library/func… /ht @SnickerDev
Ned Batchelder tweet media
English
3
17
170
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@driscollis If your unittest cases are heavily parameterized, it can be useful to write a util func and have a more declarative style. This can sometimes reduce the boilerplate/duplication and improve readability.
Michael Kocher tweet media
English
0
0
1
0
Mike Driscoll
Mike Driscoll@driscollis·
Let's talk about test-driven development (TDD) with #Python today. We will do that by going over a code kata example! 🧵🐍🔥👇
English
8
22
131
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@bernhardsson There's a ton of entropy in this space. Leaky abstractions, PBS/Slurm/SGE lack of standardization, never ending converting file format/standard X to Y, scrappy CLI tools, random grep/awk tasks, file chunking based on workflow specific data access patterns. It's a tricky space.
English
0
0
2
0
Erik Bernhardsson
Erik Bernhardsson@bernhardsson·
I get the impression that bioinformatics has its whole own ecosystem of workflow scheduling and scaling (stuff like Nextflow and SLURM) – why is that?
English
42
27
210
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@raymondh Using %paste might be a useful (temporary) workaround for some cases. Paste appears to go outside of the reformatting mechanism. Using %load will still be reformatted. It's a bit unclear why %paste and %load behave differently with respect to formatting.
Michael Kocher tweet media
English
0
0
1
0
Raymond Hettinger
Raymond Hettinger@raymondh·
Argh! Who thought Black should be automatically applied to lines in the IPython CLI? The makes it less useful for education purposes, less useful for interactive math, and annoying when it rewrites your input across multiple lines.
English
16
35
273
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@raymondh I believe EllipsisType has a similar friction point. In 3.10, types.EllipsisType and types.NoneType were added. #types.EllipsisType" target="_blank" rel="nofollow noopener">docs.python.org/3/library/type…
English
0
0
0
0
Raymond Hettinger
Raymond Hettinger@raymondh·
A little birdie told me that #Python typing Optional and Union are going away. It's all or-operators from here: def f(x: A | B, y = int | None = None) -> dict[tuple[str, str]]: ... I won't miss Union, but Optional was pleasantly readable. f(x: A | B, y: Optional[int] = None):
English
18
31
235
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@bbelderbos The state of the cache can be obtained using .cache_info() and the cache can be cleared using .cache_clear(). The source of lru_cache is also worth reading. It has tasteful use of closures and utilizes bound functions to help optimization the algo. #L524" target="_blank" rel="nofollow noopener">github.com/python/cpython…
Michael Kocher tweet media
English
1
0
3
0
Bob Belderbos
Bob Belderbos@bbelderbos·
For caching (memoization) in #Python, check out functools.lru_cache:
Bob Belderbos tweet media
English
2
17
91
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@treyhunner Also note that reduce has a simple type signature (at least relative to max/min).
Michael Kocher tweet media
English
0
0
0
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@treyhunner Reduce can be useful when you start to hit limitations of using key= mechanism in max/min when comparing two entities. Reduce can also be used to construct a compose function to capture the steps of a data processing pipeline. github.com/mpkocher/Funct…
Michael Kocher tweet mediaMichael Kocher tweet media
English
1
0
1
0
Trey Hunner
Trey Hunner@treyhunner·
I rarely use functools.reduce in #Python. Most of my reductions can be done with another tool: - adding (sum) - multiplying (math.​prod) - counting values (collections.Counter, list.count, etc) - checking conditions (any & all) What do you use (or not) functools.reduce for?
English
11
4
33
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@driscollis @realpython @pybites It can be useful to leverage a custom default factory when defining dataclasses. The post_init hook in your example might be better if you use the channels that were passed in to the constructor instead of hard coding these to an empty list.
Michael Kocher tweet mediaMichael Kocher tweet media
English
1
1
1
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@1st1 For simple cases, it can be useful to replace if/elif blocks with a dict to perform the dispatch handling.
Michael Kocher tweet media
English
0
0
13
0
Yury Selivanov
Yury Selivanov@1st1·
Recently I was staring at a series of long if..elif..elif chains in #python code and came up with a little abstraction to make the code look nicer. Please welcome value dispatch. It's just like the functools.singledispatch decorator but works on values, not types. 🐍
Yury Selivanov tweet media
English
9
40
266
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@anthonypjshaw Are there any optimizations in Pyjion at the JIT compiler level that leverage type annotations/hints?
English
0
0
0
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@bbelderbos It can be useful to be make sure Pydantic's core design principles are consistent with your app requirements prior to adoption. Pydantic has an opinionated approach to casting/conversion. This is often useful, but sometimes can yield surprising results. #data-conversion" target="_blank" rel="nofollow noopener">pydantic-docs.helpmanual.io/usage/models/#…
Michael Kocher tweet media
English
1
0
2
0
Michael Kocher
Michael Kocher@ElevenPhonons·
@noahsbwilliams For this use case, random.choice can be helpful. #random.choice" target="_blank" rel="nofollow noopener">docs.python.org/3/library/rand…
Michael Kocher tweet media
English
0
0
0
0