Skip to content

Kind inference doesn't work when right-hand sides exclude function calls

Kind inference fails for the following:

def bw_euler():
    # Set up variables
    y = var("<state>y")
    t = var("<t>")
    dt = var("<dt>")

    with CodeBuilder("main") as cb:
        cb(y, y * 1/(1 + 10 * dt))
        cb(t, t + dt)
        cb.yield_state(y, "y", t, "t")

    return DAGCode.from_phases_list([cb.as_execution_phase("main")], "main")

This code could be a legitimate method. It's the backward Euler method for the right-hand side y' = -10 y.

The error is

Left-over statements in kind inference:
[main] <state>y <- <state>y / (1 + 10*<dt>)
  -> nothing known about '<state>y'
Traceback (most recent call last):
  File "bw_euler.py", line 54, in <module>
    main()
  File "bw_euler.py", line 50, in main
    infer_kinds(bw_euler())
  File "/Users/matt/src/dagrt/dagrt/data.py", line 634, in infer_kinds
    return kind_finder(names, phases)
  File "/Users/matt/src/dagrt/dagrt/data.py", line 529, in __call__
    raise RuntimeError("failed to infer kinds")
RuntimeError: failed to infer kinds

(infer_kinds is a new function I'm adding as part of #34 (closed).)

It's not clear to me how to repair this. Maybe this demonstrates that not all programs have an unambiguous type, so hints are sometimes needed?

Edited by Matt Wala
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information