GithubHelp home page GithubHelp logo

Comments (3)

elijahbenizzy avatar elijahbenizzy commented on August 20, 2024

Reproducible example:

from burr.core import action, State, ApplicationBuilder, default


@action(reads=["val"], writes=["list", "val"])
def append(state: State) -> tuple[dict, State]:
    val = state["val"] + 1
    result = {"val": val}
    return result, state.append(list=result["val"]).update(val=val)


app = (
    ApplicationBuilder()
    .with_state(list=[], val=0)
    .with_actions(append=append)
    .with_entrypoint("append")
    .with_transitions(
        ("append", "append", default),
    )
    .build()
)

old_state = app.state
assert old_state["list"] == []
*_, new_state = app.step()
assert new_state["list"] == [1]
*_, new_state = app.step()
assert new_state["list"] == [1, 2]

from burr.

elijahbenizzy avatar elijahbenizzy commented on August 20, 2024

Problem is in FunctionBasedAction -- run takes in just the read state, but it does both a run and a update. So when we pass in the write state (which has the full list), it gets clobbered. Meanwhile, the default append is to create an empty list, so it keeps resetting it.

Trick here is to pass in the reads and writes from state to the run item in the action... This comes from the ugliness of doing both at the same time, but I think we can specify a combination one that does both? E.G. this does both so it wants reads and writes? And then the framework passes it in?

Ideas:

  1. Make it ask for both self._reads and self._writes in reads -- this is ugly because there wouldn't be defaults, and it'll have more than it needs...
  2. Make it specify that its a single-step process -- handle that differently.
  3. Move the logic for subsetting state into Action so this can handle it differently

My instinct says (2) as the logic feels like it should be outside (an action should say what it wants and not grab it). Will see how complicated it is.

from burr.

elijahbenizzy avatar elijahbenizzy commented on August 20, 2024

This is fixed -- see discussion/commits in 770c27f for design.

from burr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.