for k, v in list(u.__dict__.items()):
    if isinstance(v, Expr) and v.has(u.Unit):
        subs[Symbol(k)] = v
print(sympify('yard*millimeter/ly').subs(subs))
How to parse and simplify a string like '3cm/µs² + 4e-4 sqmiles/km/h**2' treating physical units correctly?