Spaces:
Running

pydraw / pydraw3d /compile /coverage.py
linoyts's picture
linoyts HF Staff
wave 12: pixel-art craft, mood words, characters, writing on things, physics and growth simulation, combination fixes - pydraw d9e8909
1fe03ed verified
Raw History Blame Contribute Delete
2.55 kB
"""Dev tool: trace every hand model + a sample of family taxa, report which parts fall back and why.
PYTHONPATH=. python -m pydraw3d.compile.coverage [n_taxa]
"""
import collections, random, sys, time
import numpy as np
import pydraw3d # noqa: F401 (loads models + families)
from pydraw3d.models import MODELS
from pydraw3d.families import FAMILIES, TAXA, build, P
from pydraw3d.compile import trace_part
def corpus(n_taxa=300, seed=0):
out = []
for name, (fn, asp) in sorted(MODELS.items()):
try:
out.append(("model:" + name, fn(None, None)))
except Exception as e:
pass
for fam, (fn, asp, defaults) in sorted(FAMILIES.items()):
try:
out.append(("family:" + fam, fn(P(defaults), None, None)))
except Exception:
pass
keys = sorted(k for k, v in TAXA.items() if v.get("family") in FAMILIES)
random.Random(seed).shuffle(keys)
for k in keys[:n_taxa]:
try:
out.append(("taxon:" + k, build(TAXA[k]["family"], dict(TAXA[k], _word=k), None)))
except Exception:
pass
return out
def main():
n = int(sys.argv[1]) if len(sys.argv) > 1 else 300
t0 = time.time()
items = corpus(n)
reasons = collections.Counter()
bad_models = []
nparts = nfail = nspec = 0
nodes = []
for name, parts in items:
fails = []
for j, pt in enumerate(parts):
body, err, nn, sp = trace_part(pt.fn)
nparts += 1
nspec += bool(sp)
if body is None:
nfail += 1
fails.append((j, err))
reasons[err.split(" ")[0] if err.startswith("numpy function") is False else err] += 1
else:
nodes.append(nn)
if fails:
bad_models.append((name, fails))
print("models: %d, parts: %d, traced: %d (%.1f%%), speculative any(): %d, nodes median %d max %d, %.1fs"
% (len(items), nparts, nparts - nfail, 100 * (nparts - nfail) / max(1, nparts), nspec, np.median(nodes), max(nodes), time.time() - t0))
print("models with a fallback part: %d / %d" % (len(bad_models), len(items)))
full = collections.Counter()
for name, fails in bad_models:
for j, e in fails:
full[e[:110]] += 1
for e, c in full.most_common(40):
print("%5d %s" % (c, e))
for name, fails in bad_models[:60]:
print(" %s: %s" % (name, "; ".join("p%d %s" % (j, e[:70]) for j, e in fails[:3])))
if __name__ == "__main__":
main()