nikhil
February 19, 2018, 6:32pm
1
How would I go about making a global experiment counter that updates when any of a set of other cells change?
My use case is that I want the page to allow running of several experiments whose parameters are controlled via UI elements (e.g. a slider).
Each time any of the UI elements changes, I want to be able to
increment the global experiment counter by one
run an experiment with new parameters
record it in some state object keyed by the experiment ID
clean up WebGL memory from all older experiments.
Eventually it’d also be nice if an “experiment” was changing the code of a cell.
There may be something I’m missing here, but would love some guidance! Thanks!
nikhil
February 19, 2018, 8:14pm
2
Just found this, which solves my cleanup memory from the previous run of a cell problem:
To free up resources when a cell is re-evaluated, such as cancelling timers or disposing WebGL contexts, use the invalidation promise from the standard library. This promise resolves when the current cell is re-evaluated: when the cell’s code...
Glad you thought of this in November, Mike
Hi Nikhil,
We’ve just released the mutable
keyword, which should give you an easier way to orchestrate the state of your experiments across cell boundaries. For the basics, check out the introductory notebook:
https://beta.observablehq.com/@jashkenas/introduction-to-mutable-state
Specifically, I would imagine that you could:
Have a mutable experimentNo = 1
counter that you increment whenever an experiment is re-evaluated.
Have a mutable experimentRecords = {}
object that you mutate and replace every time an experiment has finished and its results are finalized.
Have other cells that observe and react to either of those things.
Let me know if that doesn’t help you…
nikhil
February 21, 2018, 12:35am
4
Awesome, that sounds like exactly what I want (I saw the “code stinks” notebook and stayed away from simply mutating an object of my own).
Thank you