Mutating objects affect reproducibility #1385
Replies: 3 comments 9 replies
-
That's correct, and a good point. We try our best, without resorting to magic (ie, no runtime tracing, which is a losing battle), and are currently happy with being substantially more computationally reproducible than vanilla IPyKernel. Our prescription to our users is: don't mutate variables across multiple cells. If you do, bets on "computational reproducibility" are off, unless you carefully manage the DAG yourself. You can find such language in our docs and tutorials. In this way we are similar to Happy to continue chatting. I will convert this to a Discussion because it's not bug, rather a design choice we're committed to. EDIT: Rereading the FAQ -- I can make the claim more clear. |
Beta Was this translation helpful? Give feedback.
-
This all sounds good, and I didn't see the best practices 🙏🏻 The only thing I'll add here is that I think there is still a bug... When I re-run the first cell (Cell A) and then Cell B (after running Cell C), shouldn't the printed value be reset back to |
Beta Was this translation helpful? Give feedback.
-
@benjreinhart PR #1580 addresses this to a larger extent. You really have to go out of your way to mutate things- but of course, it is limited by Python itself. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
In FAQ, Marimo states:
I see that variables are tracked and reassignment is not allowed. However, since Python is not an immutable language, this guarantee doesn't seem possible because cells can mutate objects and that seems impossible to prevent. Consider the following example:
Cell A:
Cell B:
Cell C:
Now, if I run them in order, you get what you'd expect the first time around. The problem is if I go back to Cell B and run that cell again. I now get a different value than I did the first time (see screen shot).
The bug part of this is issue that if I re-run Cell A and then Cell B, I'm still seeing "value 2" printed.
But the larger point of this issue is that, unless I'm missing something, it can't be the case that marimo notebooks truly guarantee consistency and reproducibility in all cases? Even if we tracked some types of modification, you could never catch them all. Code can call into other libraries that mutate (pandas, tensorflow, etc), code can dynamically eval strings as code, etc. I'd love to be wrong here because this would be awesome if we could reach the same level of guarantees that e.g. Livebook does, but I don't see how that's possible without using an immutable language.
Environment
https://marimo.app (the online wasm version)
Code to reproduce
No response
Beta Was this translation helpful? Give feedback.
All reactions